diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-06-16 09:50:59 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-06-16 09:50:59 +0200 |
commit | 83eadc932dd0100a7dac254d8ba92a7e02deddd8 (patch) | |
tree | e672e33ec24cad57af8efcc29fe8189f5dccb692 /tests | |
parent | 5e25d4a0dec29f7f73d9492487ac30163c951d6e (diff) | |
download | fengari-83eadc932dd0100a7dac254d8ba92a7e02deddd8.tar.gz fengari-83eadc932dd0100a7dac254d8ba92a7e02deddd8.tar.bz2 fengari-83eadc932dd0100a7dac254d8ba92a7e02deddd8.zip |
[test-suite] pm.js passes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-suite/pm-classes.lua | 9 | ||||
-rw-r--r-- | tests/test-suite/pm-gsub.lua | 17 | ||||
-rw-r--r-- | tests/test-suite/pm.js (renamed from tests/test-suite/inprogress/pm.js) | 40 |
3 files changed, 35 insertions, 31 deletions
diff --git a/tests/test-suite/pm-classes.lua b/tests/test-suite/pm-classes.lua new file mode 100644 index 0000000..59cca12 --- /dev/null +++ b/tests/test-suite/pm-classes.lua @@ -0,0 +1,9 @@ +assert(string.match("alo xyzK", "(%w+)K") == "xyz") +assert(string.match("254 K", "(%d*)K") == "") +assert(string.match("alo ", "(%w*)$") == "") +assert(string.match("alo ", "(%w+)$") == nil) +assert(string.find("(álo)", "%(á") == 1) +local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") +assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) +a, b, c, d = string.match('0123456789', '(.+(.?)())') +assert(a == '0123456789' and b == '' and c == 11 and d == nil) diff --git a/tests/test-suite/pm-gsub.lua b/tests/test-suite/pm-gsub.lua new file mode 100644 index 0000000..d873cce --- /dev/null +++ b/tests/test-suite/pm-gsub.lua @@ -0,0 +1,17 @@ +assert(string.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo') +assert(string.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim +assert(string.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim +assert(string.gsub('alo alo \n 123\n ', '%s+', ' ') == 'alo alo 123 ') +t = "abç d" +a, b = string.gsub(t, '(.)', '%1@') +assert('@'..a == string.gsub(t, '', '@') and b == 5) +a, b = string.gsub('abçd', '(.)', '%0@', 2) +assert(a == 'a@b@çd' and b == 2) +assert(string.gsub('alo alo', '()[al]', '%1') == '12o 56o') +assert(string.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") == + "xyz=abc-abc=xyz") +assert(string.gsub("abc", "%w", "%1%0") == "aabbcc") +assert(string.gsub("abc", "%w+", "%0%1") == "abcabc") +assert(string.gsub('áéí', '$', '\0óú') == 'áéí\0óú') +assert(string.gsub('', '^', 'r') == 'r') +assert(string.gsub('', '$', 'r') == 'r') diff --git a/tests/test-suite/inprogress/pm.js b/tests/test-suite/pm.js index d54a848..a8a58cd 100644 --- a/tests/test-suite/inprogress/pm.js +++ b/tests/test-suite/pm.js @@ -4,9 +4,9 @@ const test = require('tape'); global.WEB = false; -const lua = require('../../../src/lua.js'); -const lauxlib = require('../../../src/lauxlib.js'); -const lualib = require('../../../src/lualib.js'); +const lua = require('../../src/lua.js'); +const lauxlib = require('../../src/lauxlib.js'); +const lualib = require('../../src/lualib.js'); test("[test-suite] pm: pattern matching", function (t) { @@ -200,18 +200,11 @@ test("[test-suite] pm: range", function (t) { }); - +// Can't be represented by JS string, testing from actual lua file test("[test-suite] pm: classes", function (t) { let luaCode = ` - assert(string.match("alo xyzK", "(%w+)K") == "xyz") - assert(string.match("254 K", "(%d*)K") == "") - assert(string.match("alo ", "(%w*)$") == "") - assert(string.match("alo ", "(%w+)$") == nil) - assert(string.find("(álo)", "%(á") == 1) - local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") - assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) - a, b, c, d = string.match('0123456789', '(.+(.?)())') - assert(a == '0123456789' and b == '' and c == 11 and d == nil) + local f = loadfile("tests/test-suite/pm-classes.lua") + return f() `, L; t.plan(2); @@ -234,26 +227,11 @@ test("[test-suite] pm: classes", function (t) { }); - +// Can't be represented by JS string, testing from actual lua file test("[test-suite] pm: gsub", function (t) { let luaCode = ` - assert(string.gsub('ülo ülo', 'ü', 'x') == 'xlo xlo') - assert(string.gsub('alo úlo ', ' +$', '') == 'alo úlo') -- trim - assert(string.gsub(' alo alo ', '^%s*(.-)%s*$', '%1') == 'alo alo') -- double trim - assert(string.gsub('alo alo \\n 123\\n ', '%s+', ' ') == 'alo alo 123 ') - t = "abç d" - a, b = string.gsub(t, '(.)', '%1@') - assert('@'..a == string.gsub(t, '', '@') and b == 5) - a, b = string.gsub('abçd', '(.)', '%0@', 2) - assert(a == 'a@b@çd' and b == 2) - assert(string.gsub('alo alo', '()[al]', '%1') == '12o 56o') - assert(string.gsub("abc=xyz", "(%w*)(%p)(%w+)", "%3%2%1-%0") == - "xyz=abc-abc=xyz") - assert(string.gsub("abc", "%w", "%1%0") == "aabbcc") - assert(string.gsub("abc", "%w+", "%0%1") == "abcabc") - assert(string.gsub('áéÃ', '$', '\\0óú') == 'áéÃ\\0óú') - assert(string.gsub('', '^', 'r') == 'r') - assert(string.gsub('', '$', 'r') == 'r') + local f = loadfile("tests/test-suite/pm-gsub.lua") + return f() `, L; t.plan(2); |