Merge remote-tracking branch 'myk002/myk_expect_find' into develop

develop
lethosor 2021-08-25 00:40:51 -04:00
commit a2911c5d95
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 25 additions and 0 deletions

@ -47,6 +47,14 @@ function expect.ge(a, b, comment)
return a >= b, comment, ('%s < %s'):format(a, b)
end
function expect.str_find(pattern, str_to_match, comment)
if type(str_to_match) ~= 'string' then
return false, comment, 'expected string, got ' .. type(str_to_match)
end
return str_to_match:find(pattern), comment,
('pattern "%s" not matched in "%s"'):format(pattern, str_to_match)
end
local function table_eq_recurse(a, b, keys, known_eq)
if a == b then return true end
local checked = {}

@ -1,5 +1,22 @@
local expect_raw = require('test_util.expect')
function test.str_find()
expect.true_(expect_raw.str_find('a ', 'a str', 'a comment'))
local ok, comment, msg = expect_raw.str_find('ab', 'a str', 'a comment')
expect.false_(ok)
expect.eq('a comment', comment)
expect.eq('pattern "ab" not matched in "a str"', msg)
ok, _, msg = expect_raw.str_find('pattern', nil)
expect.false_(ok)
expect.eq('expected string, got nil', msg)
ok, _, msg = expect_raw.str_find('pattern', {})
expect.false_(ok)
expect.eq('expected string, got table', msg)
end
function test.table_eq()
expect.true_(expect_raw.table_eq({}, {}))
expect.true_(expect_raw.table_eq({'a'}, {'a'}))