From ca74bf859726257525bc067e44a50bfb01297f98 Mon Sep 17 00:00:00 2001 From: Mauro Iazzi Date: Thu, 2 Apr 2009 11:52:09 +0200 Subject: [PATCH] added a test file --- test.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test.lua diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..b06c5c3 --- /dev/null +++ b/test.lua @@ -0,0 +1,30 @@ +#!/usr/bin/lua + +require 'lpeg' + +local gr = dofile'mime.lua' + +local tests = { + { string = '\r\n ', rule = 'FWS', match = true, capture = ' ' }, + { string = '"rrr\r\n aaa"', rule ='quoted-string', match = true, capture = 'rrr aaa'}, + { string = '(some stupid comment \\( ** \r\n )', rule ='comment', match = true, capture = ' '}, +} + +for i, t in ipairs(tests) do + local s, r, m, c = t.string, t.rule, t.match, t.capture + gr[1] = lpeg.V(r) * lpeg.Cp() + local patt = lpeg.P(gr) + print('performing test ' .. i .. ' on rule ' .. r) + local ret, n = patt:match(s) + if m then + assert(ret, 'test '..i..' failed by not matching a conforming string') + assert(n==#s+1, 'test '..i..' failed by not matching the full string') + if c then + assert(ret==c, 'test '..i..' failed by not returning the correct capture') + end + else + assert(ret==nil, 'test '..i..' failed by matching a wrong string') + end +end + + -- 2.11.4.GIT