diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:26 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:56 +0800 |
| commit | e02321107277a63e7dcb12ab163c9942ac101b87 (patch) | |
| tree | f38c6f2fbf4ee35df4938933dbc1e645733356f4 /spec/outputs/test/literals_spec.lua | |
| parent | 5d5b657f606b5939062983b1f90c3359d542672e (diff) | |
| download | yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2 yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip | |
Updated tests.
Diffstat (limited to 'spec/outputs/test/literals_spec.lua')
| -rw-r--r-- | spec/outputs/test/literals_spec.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/outputs/test/literals_spec.lua b/spec/outputs/test/literals_spec.lua new file mode 100644 index 0000000..3fa36eb --- /dev/null +++ b/spec/outputs/test/literals_spec.lua | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | return describe("literals", function() | ||
| 2 | it("should support integer literals", function() | ||
| 3 | return assert.same(123, 123) | ||
| 4 | end) | ||
| 5 | it("should support float literals", function() | ||
| 6 | return assert.same(1.5, 1.5) | ||
| 7 | end) | ||
| 8 | it("should support scientific notation", function() | ||
| 9 | return assert.same(1.5e2, 150) | ||
| 10 | end) | ||
| 11 | it("should support negative numbers", function() | ||
| 12 | return assert.same(-42, -42) | ||
| 13 | end) | ||
| 14 | it("should support hexadecimal literals", function() | ||
| 15 | return assert.same(0xff, 255) | ||
| 16 | end) | ||
| 17 | it("should support hexadecimal with uppercase", function() | ||
| 18 | return assert.same(0XFF, 255) | ||
| 19 | end) | ||
| 20 | it("should support binary literals", function() | ||
| 21 | return assert.same(5, 5) | ||
| 22 | end) | ||
| 23 | it("should support binary with uppercase", function() | ||
| 24 | return assert.same(5, 5) | ||
| 25 | end) | ||
| 26 | it("should support number with underscores", function() | ||
| 27 | return assert.same(1000000, 1000000) | ||
| 28 | end) | ||
| 29 | it("should support hex with underscores", function() | ||
| 30 | return assert.same(0xDEADBEEF, 0xDEADBEEF) | ||
| 31 | end) | ||
| 32 | it("should support double quote strings", function() | ||
| 33 | return assert.same("hello", "hello") | ||
| 34 | end) | ||
| 35 | it("should support single quote strings", function() | ||
| 36 | return assert.same('world', 'world') | ||
| 37 | end) | ||
| 38 | it("should support multi-line strings with [[", function() | ||
| 39 | local s = [[ hello | ||
| 40 | world | ||
| 41 | ]] | ||
| 42 | return assert.is_true((s:match("hello") ~= nil)) | ||
| 43 | end) | ||
| 44 | it("should support multi-line strings with [=[", function() | ||
| 45 | local s = [==[ test | ||
| 46 | ]==] | ||
| 47 | return assert.is_true((s:match("test") ~= nil)) | ||
| 48 | end) | ||
| 49 | it("should support boolean true", function() | ||
| 50 | return assert.same(true, true) | ||
| 51 | end) | ||
| 52 | it("should support boolean false", function() | ||
| 53 | return assert.same(false, false) | ||
| 54 | end) | ||
| 55 | it("should support nil", function() | ||
| 56 | return assert.same(nil, nil) | ||
| 57 | end) | ||
| 58 | it("should support empty table", function() | ||
| 59 | local t = { } | ||
| 60 | return assert.same(#t, 0) | ||
| 61 | end) | ||
| 62 | it("should support table with keys", function() | ||
| 63 | local t = { | ||
| 64 | a = 1, | ||
| 65 | b = 2 | ||
| 66 | } | ||
| 67 | assert.same(t.a, 1) | ||
| 68 | return assert.same(t.b, 2) | ||
| 69 | end) | ||
| 70 | it("should support array literal", function() | ||
| 71 | local t = { | ||
| 72 | 1, | ||
| 73 | 2, | ||
| 74 | 3 | ||
| 75 | } | ||
| 76 | assert.same(t[1], 1) | ||
| 77 | assert.same(t[2], 2) | ||
| 78 | return assert.same(t[3], 3) | ||
| 79 | end) | ||
| 80 | return it("should support mixed table", function() | ||
| 81 | local t = { | ||
| 82 | 1, | ||
| 83 | 2, | ||
| 84 | 3, | ||
| 85 | key = "value" | ||
| 86 | } | ||
| 87 | assert.same(t[1], 1) | ||
| 88 | return assert.same(t.key, "value") | ||
| 89 | end) | ||
| 90 | end) | ||
