]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Fix unit tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 23 Apr 2016 14:27:03 +0000 (15:27 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 23 Apr 2016 14:27:03 +0000 (15:27 +0100)
test/lua/unit/regxep.lua
test/lua/unit/sqlite3.lua
test/lua/unit/trie.lua
test/lua/unit/url.lua

index 0bb4db9351df235fed00a24f04cb210e16fee650..a27e7b3639c13f7ae59ae995ba099ea797c79fdb 100644 (file)
@@ -9,13 +9,13 @@ context("Regexp unit tests", function()
   end)
   test("Regexp match", function()
     local cases = {
+      {'/Тест/iu', 'тест', true},
       {'/test$/m', '123test', true},
       {'/^test$/m', '123test', false},
       {'m,test,', 'test', true},
       {'m,test,', 'test123', false},
       {'m{https?://[^/?\\s]+?:\\d+(?<!:80)(?<!:443)(?<!:8080)(?:/|\\s|$)}', '', false},
       {'/test/i', 'TeSt123', true},
-      {'/ТесТ/iu', 'тест', true},
       -- Raw regexp
       {'/\\S<[-\\w\\.]+\\@[-\\w\\.]+>/r', 'some<example@example.com>', true},
       -- Cyrillic utf8 letter
index 9fec2b69413f2d1efa19c64e19a5d46d3d3f18e9..15dc3d3fb0796780022a3dd5dce45bb0c81c2a05 100644 (file)
@@ -41,7 +41,7 @@ context("Sqlite3 API", function()
     assert_true(ret, "should be able to insert row")
 
     for row in db:rows([[SELECT * FROM x;]]) do
-      assert_equal(row.id, 1)
+      assert_equal(row.id, '1')
       assert_equal(row.value, 'test')
     end
     os.remove('/tmp/rspamd_unit_test_sqlite3-2.sqlite')
index 5191d9e261e21960e1dae1b3dcae2e3b4bfadc88..e37d40e3626561da1387fbc5f87fd2b7240b19dc 100644 (file)
@@ -2,7 +2,8 @@
 
 context("Trie search functions", function()
   local t = require "rspamd_trie"
-  
+  local logger = require "rspamd_logger"
+
   test("Trie search", function()
     local patterns = {
       'test',
@@ -11,47 +12,52 @@ context("Trie search functions", function()
       'she',
       'str\0ing'
     }
-    
+
     local trie = t.create(patterns)
     assert_not_nil(trie, "cannot create trie")
-    
+
     local cases = {
       {'test', true, {{4, 1}, {4, 2}}},
       {'she test test', true, {{3, 4}, {3, 3}, {8, 1}, {8, 2}, {13, 1}, {13, 2}}},
       {'non-existent', false},
       {'str\0ing test', true, {{7, 5}, {12, 1}, {12, 2}}},
     }
-    
+
     local function comparetables(t1, t2)
       if #t1 ~= #t2 then return false end
       for i=1,#t1 do
         if type(t1[i]) ~= type(t2[i]) then return false
         elseif type(t1[i]) == 'table' then
           if not comparetables(t1[i], t2[i]) then return false end
-        elseif t1[i] ~= t2[i] then 
-          return false 
+        elseif t1[i] ~= t2[i] then
+          return false
         end
       end
       return true
     end
-    
+
     for _,c in ipairs(cases) do
       local res = {}
       local function cb(idx, pos)
         table.insert(res, {pos, idx})
-        
+
         return 0
       end
-      
+
       ret = trie:match(c[1], cb)
-      
+
       assert_equal(c[2], ret, tostring(c[2]) .. ' while matching ' .. c[1])
-      
+
       if ret then
+        table.sort(res, function(a, b) return a[2] > b[2] end)
+        table.sort(c[3], function(a, b) return a[2] > b[2] end)
         local cmp = comparetables(res, c[3])
-        assert_true(cmp, 'valid results for case: ' .. c[1])
+        assert_true(cmp, 'valid results for case: ' .. c[1] ..
+          ' got: ' .. logger.slog('%s', res) .. ' expected: ' ..
+          logger.slog('%s', c[3])
+        )
       end
     end
-    
+
   end)
-end)
\ No newline at end of file
+end)
index 0b385c063238d7fe7db40eb4fa04dd6210371c85..06082afe0036832045819788de0c4d20740339cf 100644 (file)
@@ -18,6 +18,8 @@ context("URL check functions", function()
     local pool = mpool.create()
     local cases = {
       {"test.com text", {"test.com", nil}},
+      {" test.com text", {"test.com", nil}},
+      {"<test.com> text", {"test.com", nil}},
       {"test.com. text", {"test.com", nil}},
       {"mailto:A.User@example.com text", {"example.com", "A.User"}},
       {"http://Тест.Рф:18 text", {"тест.рф", nil}},
@@ -60,6 +62,11 @@ context("URL check functions", function()
         host = 'www.google.com', path = 'foo', query = 'bar=baz', tld = 'google.com'
       }},
       {"http://[www.google.com]/", false},
+      {"<test.com", true, {
+        host = 'test.com', tld = 'test.com',
+      }},
+      {"test.com>", false},
+      {",test.com text", false},
       {"ht\ttp:@www.google.com:80/;p?#", false},
       {"http://user:pass@/", false},
       {"http://foo:-80/", false},