Ticket #593: xapian-1.2.9-lua-smoketest.diff
File xapian-1.2.9-lua-smoketest.diff, 2.5 KB (added by , 13 years ago) |
---|
-
xapian-bindings-1.2.
old new 21 21 -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 22 22 -- USA 23 23 24 require("xapian") 25 26 function expect(m, n) 24 --- 25 -- m: expected value 26 -- n: obtained value 27 -- msg: failure message (a string) 28 function expect(m, n, msg) 29 msg = msg and msg..': ' or '' 27 30 if type(m) == "table" then 28 assert(#m == #n) 31 assert('table' == type(n), msg..'not a table') 32 assert(#m == #n, msg..'got: '..tostring(#n)..' want: '..tostring(#m)) 29 33 for i = 1, #m do 30 34 expect(m[i], n[i]) 31 35 end 32 36 else 33 assert(m == n )37 assert(m == n, msg..'got: '..(tostring(n) or '???')..' want: '..(tostring(m) or '???')) 34 38 end 35 39 end 36 40 37 41 function run_tests() 42 print('Xapian Lua binding smoke test...') 43 44 -- require must return module table 45 local xap = require'xapian' 46 expect(true, nil ~= xap, 'xapian returned by require is nil') 47 expect('table', type(xap), 'xapian returned by require is not a table') 48 -- require must set global "xapian" 49 expect(true, nil ~= xapian, 'global xapian is nil') 50 expect('table', type(xapian), 'global xapian is not a table') 51 38 52 stem = xapian.Stem("english") 39 53 doc = xapian.Document() 40 54 doc:set_data("is there anybody out there?") … … 63 77 64 78 -- Test stem 65 79 expect(tostring(stem), "Xapian::Stem(english)") 66 expect("is", stem("is") )67 expect("go", stem("going") )68 expect("want", stem("wanted") )69 expect("refer", stem("reference") )80 expect("is", stem("is"), 'stem noop "is" fails') 81 expect("go", stem("going"), 'stem noop "go" fails') 82 expect("want", stem("wanted"), 'stem(english) "wanted" -> "want" fails') 83 expect("refer", stem("reference"), 'stem(english) "reference" -> "refer" fails') 70 84 71 85 -- Test document 72 86 expect(doc:termlist_count(), 5) … … 76 90 77 91 -- Test database 78 92 expect(tostring(db), "WritableDatabase()") 79 expect(db:get_doccount(), 1 )93 expect(db:get_doccount(), 1, 'db should have 1 document') 80 94 81 95 term_count = 0 82 96 for term in db:allterms() do … … 193 207 for j = 0, #a -1 do 194 208 hit = mset:get_hit(j) 195 209 if hit:get_docid() ~= a[j + 1] then 196 197 210 print(string.format("Expected MSet[%i] to be %i, got %i.\n", j, a[j + 1], hit:get_docid())) 211 os.exit(-1) 198 212 end 199 213 end 200 214 end