@@ -2,6 +2,7 @@ local assertions = require("@assertions")
22
33local assert_eq = assertions .assert_eq
44local assert_ne = assertions .assert_ne
5+ local assert_match = assertions .assert_match
56local assert_same = assertions .assert_same
67
78testing :test (" assert_eq" , function ()
@@ -52,6 +53,23 @@ testing:test("assert_ne", function()
5253 assert (err :match (" right: nil" ))
5354end )
5455
56+ testing :test (" assert_match" , function ()
57+ assert_match (" hello world" , " hello" )
58+ assert_match (" 12345" , " %d+" )
59+
60+ local ok , err = pcall (assert_match , " hello world" , " bye" )
61+ assert (not ok )
62+ assert (err :match (" assertion `obj:match%(pattern%)` failed!" ))
63+ assert (err :match (" pattern: bye" ))
64+ assert (err :match (" obj: hello world" ))
65+
66+ ok , err = pcall (assert_match , " foo" , " bar" , " custom message" )
67+ assert (not ok )
68+ assert (err :match (" assertion `obj:match%(pattern%)` failed: custom message" ))
69+ assert (err :match (" pattern: bar" ))
70+ assert (err :match (" obj: foo" ))
71+ end )
72+
5573testing :test (" assert_same" , function ()
5674 assert_same (1 , 1 )
5775 assert_same (nil , nil )
0 commit comments