diff options
Diffstat (limited to 'spec/inputs/test/string_spec.yue')
| -rw-r--r-- | spec/inputs/test/string_spec.yue | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/spec/inputs/test/string_spec.yue b/spec/inputs/test/string_spec.yue new file mode 100644 index 0000000..b790518 --- /dev/null +++ b/spec/inputs/test/string_spec.yue | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | describe "string", -> | ||
| 2 | it "should support single quote strings", -> | ||
| 3 | s = 'hello' | ||
| 4 | assert.same s, "hello" | ||
| 5 | |||
| 6 | it "should support double quote strings", -> | ||
| 7 | s = "world" | ||
| 8 | assert.same s, "world" | ||
| 9 | |||
| 10 | it "should support escape sequences", -> | ||
| 11 | s = "hello\nworld" | ||
| 12 | assert.is_true s\match("\n") ~= nil | ||
| 13 | |||
| 14 | it "should support escaped quotes", -> | ||
| 15 | s = "he said \"hello\"" | ||
| 16 | assert.same s, 'he said "hello"' | ||
| 17 | |||
| 18 | it "should support backslash escape", -> | ||
| 19 | s = "\\" | ||
| 20 | assert.same s, "\\" | ||
| 21 | |||
| 22 | it "should support multi-line strings with [[ ]]", -> | ||
| 23 | s = [[ | ||
| 24 | hello | ||
| 25 | world | ||
| 26 | ]] | ||
| 27 | assert.is_true s\match("hello") ~= nil | ||
| 28 | assert.is_true s\match("world") ~= nil | ||
| 29 | |||
| 30 | it "should support multi-line strings with [=[ ]=]", -> | ||
| 31 | s = [==[ | ||
| 32 | hello | ||
| 33 | world | ||
| 34 | ]==] | ||
| 35 | assert.is_true s\match("hello") ~= nil | ||
| 36 | assert.is_true s\match("world") ~= nil | ||
| 37 | |||
| 38 | it "should support string interpolation with double quotes", -> | ||
| 39 | name = "world" | ||
| 40 | s = "hello #{name}" | ||
| 41 | assert.same s, "hello world" | ||
| 42 | |||
| 43 | it "should support expression interpolation", -> | ||
| 44 | a, b = 1, 2 | ||
| 45 | s = "#{a} + #{b} = #{a + b}" | ||
| 46 | assert.same s, "1 + 2 = 3" | ||
| 47 | |||
| 48 | it "should not interpolate in single quotes", -> | ||
| 49 | name = "world" | ||
| 50 | s = 'hello #{name}' | ||
| 51 | assert.same s, "hello #{name}" | ||
| 52 | |||
| 53 | it "should escape interpolation with \\#", -> | ||
| 54 | name = "world" | ||
| 55 | s = "hello \\#{name}" | ||
| 56 | assert.same s, "hello #{name}" | ||
| 57 | |||
| 58 | it "should support method calls on string literals", -> | ||
| 59 | result = "hello"\upper! | ||
| 60 | assert.same result, "HELLO" | ||
| 61 | |||
| 62 | it "should support chained method calls", -> | ||
| 63 | result = "hello world"\upper!\match "HELLO" | ||
| 64 | assert.same result, "HELLO" | ||
| 65 | |||
| 66 | it "should support YAML style strings", -> | ||
| 67 | s = | | ||
| 68 | hello | ||
| 69 | world | ||
| 70 | assert.is_true s\match("hello") ~= nil | ||
| 71 | assert.is_true s\match("world") ~= nil | ||
| 72 | |||
| 73 | it "should support YAML style with interpolation", -> | ||
| 74 | name = "test" | ||
| 75 | s = | | ||
| 76 | hello #{name} | ||
| 77 | assert.same s, "hello test\n" | ||
| 78 | |||
| 79 | it "should support string concatenation", -> | ||
| 80 | s = "hello" .. " " .. "world" | ||
| 81 | assert.same s, "hello world" | ||
| 82 | |||
| 83 | it "should handle empty strings", -> | ||
| 84 | s = "" | ||
| 85 | assert.same s, "" | ||
| 86 | |||
| 87 | it "should support Unicode characters", -> | ||
| 88 | s = "hello 世界" | ||
| 89 | assert.is_true s\match("世界") ~= nil | ||
| 90 | |||
| 91 | it "should support string length", -> | ||
| 92 | s = "hello" | ||
| 93 | assert.same #s, 5 | ||
| 94 | |||
| 95 | it "should support multi-line YAML with complex content", -> | ||
| 96 | config = | | ||
| 97 | key1: value1 | ||
| 98 | key2: value2 | ||
| 99 | key3: value3 | ||
| 100 | assert.is_true config\match("key1") ~= nil | ||
| 101 | |||
| 102 | it "should support interpolation in YAML strings", -> | ||
| 103 | x, y = 10, 20 | ||
| 104 | s = | | ||
| 105 | point: | ||
| 106 | x: #{x} | ||
| 107 | y: #{y} | ||
| 108 | assert.is_true s\match("x: 10") ~= nil | ||
| 109 | assert.is_true s\match("y: 20") ~= nil | ||
| 110 | |||
| 111 | it "should support function call in interpolation", -> | ||
| 112 | s = "result: #{-> 42}" | ||
| 113 | assert.same s, "result: 42" | ||
| 114 | |||
| 115 | it "should support table indexing in interpolation", -> | ||
| 116 | t = {value: 100} | ||
| 117 | s = "value: #{t.value}" | ||
| 118 | assert.same s, "value: 100" | ||
| 119 | |||
| 120 | it "should handle escaped characters correctly", -> | ||
| 121 | s = "tab:\t, newline:\n, return:\r" | ||
| 122 | assert.is_true s\match("\t") ~= nil | ||
| 123 | assert.is_true s\match("\n") ~= nil | ||
| 124 | |||
| 125 | it "should support string methods with colon syntax", -> | ||
| 126 | s = "hello" | ||
| 127 | assert.same s\sub(1, 2), "he" | ||
| 128 | |||
| 129 | it "should work in expressions", -> | ||
| 130 | result = "hello" .. " world" | ||
| 131 | assert.same result, "hello world" | ||
| 132 | |||
| 133 | it "should support octal escape", -> | ||
| 134 | s = "\65" | ||
| 135 | assert.same s, "A" | ||
| 136 | |||
| 137 | it "should support hex escape", -> | ||
| 138 | s = "\x41" | ||
| 139 | assert.same s, "A" | ||
| 140 | |||
| 141 | it "should support unicode escape", -> | ||
| 142 | s = "\u{4e16}" | ||
| 143 | assert.same s, "世" | ||
