diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/definition/set.lua | 26 | ||||
-rw-r--r-- | test/implementation/arg.lua | 23 | ||||
-rw-r--r-- | test/implementation/bug.lua | 15 | ||||
-rw-r--r-- | test/implementation/function.lua | 24 | ||||
-rw-r--r-- | test/implementation/init.lua | 22 | ||||
-rw-r--r-- | test/implementation/local.lua | 191 | ||||
-rw-r--r-- | test/implementation/set.lua | 31 | ||||
-rw-r--r-- | test/implementation/table.lua | 6 | ||||
-rw-r--r-- | test/main.lua | 1 |
9 files changed, 339 insertions, 0 deletions
diff --git a/test/definition/set.lua b/test/definition/set.lua index 4cbb5926..2e48e490 100644 --- a/test/definition/set.lua +++ b/test/definition/set.lua @@ -2,3 +2,29 @@ TEST [[ <!x!> = 1 <?x?> = 1 ]] + +TEST [[ +do + <!global!> = 1 +end +<?global?> = 1 +]] + +TEST [[ +<!x!> = 1 +do + local x = 1 +end +<?x?> = 1 +]] + +TEST [[ +x = 1 +do + local <!x!> = 1 + do + x = 2 + end + <?x?> = 1 +end +]] diff --git a/test/implementation/arg.lua b/test/implementation/arg.lua new file mode 100644 index 00000000..2004d666 --- /dev/null +++ b/test/implementation/arg.lua @@ -0,0 +1,23 @@ +TEST [[ +local function xx (<!xx!>) + <?xx?> = 1 +end +]] + +TEST [[ +local function x (x, <!...!>) + x = <?...?> +end +]] + +TEST [[ +function mt<!:!>x() + <?self?> = 1 +end +]] + +TEST [[ +function mt:x(<!self!>) + <?self?> = 1 +end +]] diff --git a/test/implementation/bug.lua b/test/implementation/bug.lua new file mode 100644 index 00000000..b0e890ca --- /dev/null +++ b/test/implementation/bug.lua @@ -0,0 +1,15 @@ +TEST [[ +local <!x!> +function _(x) +end +function _() + <?x?> +end +]] + +TEST [[ +function _(<!x!>) + do return end + <?x?> = 1 +end +]] diff --git a/test/implementation/function.lua b/test/implementation/function.lua new file mode 100644 index 00000000..90b75da8 --- /dev/null +++ b/test/implementation/function.lua @@ -0,0 +1,24 @@ + +TEST [[ +function <!x!> () end +<?x?> = 1 +]] + +TEST [[ +local function <!x!> () end +<?x?> = 1 +]] + +TEST [[ +local x +local function <!x!> () + <?x?> = 1 +end +]] + +TEST [[ +local x +function <!x!>() +end +<?x?> = 1 +]] diff --git a/test/implementation/init.lua b/test/implementation/init.lua new file mode 100644 index 00000000..3033f340 --- /dev/null +++ b/test/implementation/init.lua @@ -0,0 +1,22 @@ +local matcher = require 'matcher' + +rawset(_G, 'TEST', true) + +function TEST(script) + local start = script:find('<!', 1, true) + 2 + local finish = script:find('!>', 1, true) - 1 + local pos = script:find('<?', 1, true) + 2 + local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + + local suc, a, b = matcher.implementation(new_script, pos) + assert(suc) + assert(a == start) + assert(b == finish) +end + +require 'implementation.set' +require 'implementation.local' +require 'implementation.arg' +require 'implementation.function' +--require 'implementation.table' +require 'implementation.bug' diff --git a/test/implementation/local.lua b/test/implementation/local.lua new file mode 100644 index 00000000..0737443d --- /dev/null +++ b/test/implementation/local.lua @@ -0,0 +1,191 @@ +TEST [[ +local <!x!> +<?x?> = 1 +]] + +TEST [[ +local z, y, <!x!> +<?x?> = 1 +]] + +TEST [[ +local <!x!> = 1 +<?x?> = 1 +]] + +TEST [[ +local z, y, <!x!> = 1 +<?x?> = 1 +]] + +TEST [[ +local x +local <!x!> +<?x?> = 1 +]] + +TEST [[ +local <!x!> +do + <?x?> = 1 +end +]] + +TEST [[ +local <!x!> +do + local x +end +<?x?> = 1 +]] + +TEST [[ +local <!x!> +if <?x?> then + local x +end +]] + +TEST [[ +local <!x!> +if x then + local x +elseif <?x?> then + local x +end +]] + +TEST [[ +local <!x!> +if x then + local x +elseif x then + local x +else + local x +end +<?x?> = 1 +]] + +TEST [[ +local <!x!> +if x then + <?x?> = 1 +elseif x then + local x +else + local x +end +]] + +TEST [[ +local <!x!> +for x = 1, 10 do +end +<?x?> = 1 +]] + +TEST [[ +local x +for <!x!> = 1, 10 do + <?x?> = 1 +end +]] + +TEST [[ +local <!x!> +for x in x do +end +<?x?> = 1 +]] + +TEST [[ +local <!x!> +for x in <?x?> do +end +]] + +TEST [[ +local x +for <!x!> in x do + <?x?> = 1 +end +]] + +TEST [[ +local x +for z, y, <!x!> in x do + <?x?> = 1 +end +]] + +TEST [[ +local <!x!> +while <?x?> do +end +]] + +TEST [[ +local <!x!> +while x do + <?x?> = 1 +end +]] + +TEST [[ +local <!x!> +while x do + local x +end +<?x?> = 1 +]] + +TEST [[ +local <!x!> +repeat + <?x?> = 1 +until true +]] + +TEST [[ +local <!x!> +repeat + local x +until true +<?x?> = 1 +]] + +TEST [[ +local <!x!> +repeat +until <?x?> +]] + +TEST [[ +local x +repeat + local <!x!> +until <?x?> +]] + +TEST [[ +local <!x!> +function _() + local x +end +<?x?> = 1 +]] + +TEST [[ +local <!x!> +return function () + <?x?> = 1 +end +]] + +TEST [[ +local <!x!> +local x = function () + <?x?> = 1 +end +]] diff --git a/test/implementation/set.lua b/test/implementation/set.lua new file mode 100644 index 00000000..5c4a1a2e --- /dev/null +++ b/test/implementation/set.lua @@ -0,0 +1,31 @@ +TEST [[ +<!x!> = 1 +<?x?> = 1 +]] + +TEST [[ +global = 1 +do + <!global!> = 2 +end +<?global?> = 3 +]] + +TEST [[ +<!x!> = 1 +do + local x = 1 +end +<?x?> = 1 +]] + +TEST [[ +x = 1 +do + local x = 1 + do + <!x!> = 2 + end + <?x?> = 1 +end +]] diff --git a/test/implementation/table.lua b/test/implementation/table.lua new file mode 100644 index 00000000..13a3b555 --- /dev/null +++ b/test/implementation/table.lua @@ -0,0 +1,6 @@ +TEST [[ +local t = { + <!x!> = 1, +} +t.<?x?> = 1 +]] diff --git a/test/main.lua b/test/main.lua index 972a1068..c33526c6 100644 --- a/test/main.lua +++ b/test/main.lua @@ -21,6 +21,7 @@ local function main() end test 'definition' + test 'implementation' print('测试完成') end |