From 25d83c74738e837c178fa40079966cae18b21a48 Mon Sep 17 00:00:00 2001
From: "Dmitry E. Oboukhov" <unera@debian.org>
Date: Mon, 27 Oct 2014 17:11:26 +0300
Subject: [PATCH] Add tap:like method, rename tap:isdeeply to tap:is_deeply.

---
 src/lua/tap.lua                  | 20 ++++++++++++++++++--
 test/app/lua/serializer_test.lua |  2 +-
 test/app/msgpack.test.lua        |  4 ++--
 test/app/msgpackffi.test.lua     |  4 ++--
 test/app/tap.result              | 12 +++++++++---
 test/app/tap.test.lua            | 23 +++++++++++++++--------
 6 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/src/lua/tap.lua b/src/lua/tap.lua
index 34c4f3fe60..67cb4026cf 100644
--- a/src/lua/tap.lua
+++ b/src/lua/tap.lua
@@ -126,6 +126,20 @@ local function cmpdeeply(got, expected, extra)
     return true
 end
 
+local function like(test, got, pattern, message, extra)
+    extra = extra or {}
+    extra.got = got
+    extra.expected = pattern
+    return ok(test, string.match(tostring(got), pattern) ~= nil, message, extra)
+end
+
+local function unlike(test, got, pattern, message, extra)
+    extra = extra or {}
+    extra.got = got
+    extra.expected = pattern
+    return ok(test, string.match(tostring(got), pattern) == nil, message, extra)
+end
+
 local function is(test, got, expected, message, extra)
     extra = extra or {}
     extra.got = got
@@ -141,7 +155,7 @@ local function isnt(test, got, unexpected, message, extra)
 end
 
 
-local function isdeeply(test, got, expected, message, extra)
+local function is_deeply(test, got, expected, message, extra)
     extra = extra or {}
     extra.got = got
     extra.expected = expected
@@ -268,7 +282,9 @@ test_mt = {
         isboolean = isboolean;
         isudata   = isudata;
         iscdata   = iscdata;
-        isdeeply  = isdeeply;
+        is_deeply = is_deeply;
+        like      = like;
+        unlike    = unlike;
     }
 }
 
diff --git a/test/app/lua/serializer_test.lua b/test/app/lua/serializer_test.lua
index 22f7b028b2..3adb18518d 100644
--- a/test/app/lua/serializer_test.lua
+++ b/test/app/lua/serializer_test.lua
@@ -18,7 +18,7 @@ local function rt(test, s, x)
     else
         xstr = tostring(x)
     end
-    test:isdeeply(x, x1, "encode/decode for "..xstr)
+    test:is_deeply(x, x1, "encode/decode for "..xstr)
 end
 
 local function test_unsigned(test, s)
diff --git a/test/app/msgpack.test.lua b/test/app/msgpack.test.lua
index b101b361bf..8fd8b15d8e 100755
--- a/test/app/msgpack.test.lua
+++ b/test/app/msgpack.test.lua
@@ -25,11 +25,11 @@ local function test_offsets(test, s)
     local a
     local offset = 1
     a, offset = s.decode(dump, offset)
-    test:isdeeply(a, arr1, "decoded part1")
+    test:is_deeply(a, arr1, "decoded part1")
     test:is(offset, 5, "offset of part2")
 
     a, offset = s.decode(dump, offset)
-    test:isdeeply(a, arr2, "decoded part2")
+    test:is_deeply(a, arr2, "decoded part2")
     test:is(offset, 9, "offset of end")
 
     test:ok(not pcall(s.decode, dump, offset), "invalid offset")
diff --git a/test/app/msgpackffi.test.lua b/test/app/msgpackffi.test.lua
index 3a9e2fc764..a3fdf7504b 100755
--- a/test/app/msgpackffi.test.lua
+++ b/test/app/msgpackffi.test.lua
@@ -25,11 +25,11 @@ local function test_offsets(test, s)
     local a
     local offset = 1
     a, offset = s.decode(dump, offset)
-    test:isdeeply(a, arr1, "decoded part1")
+    test:is_deeply(a, arr1, "decoded part1")
     test:is(offset, 5, "offset of part2")
 
     a, offset = s.decode(dump, offset)
-    test:isdeeply(a, arr2, "decoded part2")
+    test:is_deeply(a, arr2, "decoded part2")
     test:is(offset, 9, "offset of end")
 
     test:ok(not pcall(s.decode, dump, offset), "invalid offset")
diff --git a/test/app/tap.result b/test/app/tap.result
index a26757e5bf..3e78823315 100644
--- a/test/app/tap.result
+++ b/test/app/tap.result
@@ -1,5 +1,5 @@
 TAP version 13
-1..31
+1..32
 ok - true
 ok - extra information is not printed on success
 not ok - extra printed using yaml only on failure
@@ -118,7 +118,7 @@ not ok - failed subtests
   planned: 1
   failed: 1
   ...
-    # isdeeply
+    # is_deeply
     1..6
     ok - 1 and 1
     ok - abc and abc
@@ -136,10 +136,16 @@ not ok - failed subtests
       expected: 5
       got: 4
       ...
-    # isdeeply: end
+    # is_deeply: end
 not ok - failed subtests
   ---
   planned: 6
   failed: 2
   ...
+    # like
+    1..2
+    ok - like(abcde, cd)
+    ok - unlike(abcde, acd)
+    # like: end
+ok - like
 # failed subtest: 15
diff --git a/test/app/tap.test.lua b/test/app/tap.test.lua
index cc2d9bf382..a823faaa9c 100755
--- a/test/app/tap.test.lua
+++ b/test/app/tap.test.lua
@@ -20,7 +20,7 @@ test.trace = false
 -- ok, fail and skip predicates
 --
 
-test:plan(31) -- plan to run 3 test
+test:plan(32) -- plan to run 3 test
 test:ok(true, 'true') -- basic function
 local extra = { state = 'some userful information to debug on failure',
         details = 'a table argument formatted using yaml.encode()' }
@@ -117,18 +117,25 @@ end)
 
 
 
-test:test('isdeeply', function(t)
+test:test('is_deeply', function(t)
     t:plan(6)
 
-    t:isdeeply(1, 1, '1 and 1')
-    t:isdeeply('abc', 'abc', 'abc and abc')
-    t:isdeeply({}, {}, 'empty tables')
-    t:isdeeply({1}, {1}, '{1} and {1}')
-    t:isdeeply({1}, {2}, '{1} and {2}')
-    t:isdeeply({1, 2, { 3, 4 }}, {1, 2, { 3, 5 }}, '{1,2,{3,4}} and {1,2,{3,5}}')
+    t:is_deeply(1, 1, '1 and 1')
+    t:is_deeply('abc', 'abc', 'abc and abc')
+    t:is_deeply({}, {}, 'empty tables')
+    t:is_deeply({1}, {1}, '{1} and {1}')
+    t:is_deeply({1}, {2}, '{1} and {2}')
+    t:is_deeply({1, 2, { 3, 4 }}, {1, 2, { 3, 5 }}, '{1,2,{3,4}} and {1,2,{3,5}}')
 
 end)
 
+
+test:test('like', function(t)
+    t:plan(2)
+    t:like('abcde', 'cd', 'like(abcde, cd)')
+    t:unlike('abcde', 'acd', 'unlike(abcde, acd)')
+end)
+
 --
 -- Finish root test. Since we used non-callback variant, we have to
 -- call check explicitly.
-- 
GitLab