diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
| commit | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch) | |
| tree | ceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/inputs/test/yaml_string_spec.yue | |
| parent | e70e63a9737ed3a9e72f1329901075498190e6b4 (diff) | |
| download | yuescript-compiler-improvements.tar.gz yuescript-compiler-improvements.tar.bz2 yuescript-compiler-improvements.zip | |
Add compiler improvements and comprehensive test suitecompiler-improvements
- Fixed path option handling to avoid semicolon concatenation issues
- Added exception handling for std::length_error and general exceptions
- Added comprehensive test specifications for advanced language features
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'spec/inputs/test/yaml_string_spec.yue')
| -rw-r--r-- | spec/inputs/test/yaml_string_spec.yue | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/spec/inputs/test/yaml_string_spec.yue b/spec/inputs/test/yaml_string_spec.yue new file mode 100644 index 0000000..1296340 --- /dev/null +++ b/spec/inputs/test/yaml_string_spec.yue | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | describe "yaml string", -> | ||
| 2 | it "should create basic yaml string", -> | ||
| 3 | s = | | ||
| 4 | hello | ||
| 5 | world | ||
| 6 | assert.is_true s\match "hello" | ||
| 7 | assert.is_true s\match "world" | ||
| 8 | |||
| 9 | it "should preserve indentation", -> | ||
| 10 | s = | | ||
| 11 | key1: value1 | ||
| 12 | key2: value2 | ||
| 13 | assert.is_true s\match "key1" | ||
| 14 | assert.is_true s\match "key2" | ||
| 15 | |||
| 16 | it "should support interpolation", -> | ||
| 17 | name = "test" | ||
| 18 | s = | | ||
| 19 | hello #{name} | ||
| 20 | assert.same s, "hello test" | ||
| 21 | |||
| 22 | it "should handle complex interpolation", -> | ||
| 23 | x, y = 10, 20 | ||
| 24 | s = | | ||
| 25 | point: | ||
| 26 | x: #{x} | ||
| 27 | y: #{y} | ||
| 28 | assert.is_true s\match "x: 10" | ||
| 29 | assert.is_true s\match "y: 20" | ||
| 30 | |||
| 31 | it "should work with expressions", -> | ||
| 32 | s = | | ||
| 33 | result: #{1 + 2} | ||
| 34 | assert.is_true s\match "result: 3" | ||
| 35 | |||
| 36 | it "should support multiline with variables", -> | ||
| 37 | config = | | ||
| 38 | database: | ||
| 39 | host: localhost | ||
| 40 | port: 5432 | ||
| 41 | name: mydb | ||
| 42 | assert.is_true config\match "database:" | ||
| 43 | assert.is_true config\match "host:" | ||
| 44 | |||
| 45 | it "should escape special characters", -> | ||
| 46 | s = | | ||
| 47 | path: "C:\Program Files\App" | ||
| 48 | note: 'He said: "#{Hello}!"' | ||
| 49 | assert.is_true s\match "path:" | ||
| 50 | assert.is_true s\match "note:" | ||
| 51 | |||
| 52 | it "should work in function", -> | ||
| 53 | fn = -> | ||
| 54 | str = | | ||
| 55 | foo: | ||
| 56 | bar: baz | ||
| 57 | return str | ||
| 58 | |||
| 59 | result = fn! | ||
| 60 | assert.is_true result\match "foo:" | ||
| 61 | assert.is_true result\match "bar:" | ||
| 62 | |||
| 63 | it "should strip common leading whitespace", -> | ||
| 64 | fn = -> | ||
| 65 | s = | | ||
| 66 | nested: | ||
| 67 | item: value | ||
| 68 | s | ||
| 69 | |||
| 70 | result = fn! | ||
| 71 | assert.is_true result\match "nested:" | ||
| 72 | assert.is_true result\match "item:" | ||
| 73 | |||
| 74 | it "should support empty lines", -> | ||
| 75 | s = | | ||
| 76 | line1 | ||
| 77 | |||
| 78 | line3 | ||
| 79 | assert.is_true s\match "line1" | ||
| 80 | assert.is_true s\match "line3" | ||
| 81 | |||
| 82 | it "should work with table access in interpolation", -> | ||
| 83 | t = {value: 100} | ||
| 84 | s = | | ||
| 85 | value: #{t.value} | ||
| 86 | assert.is_true s\match "value: 100" | ||
| 87 | |||
| 88 | it "should support function calls in interpolation", -> | ||
| 89 | s = | | ||
| 90 | result: #{(-> 42)!} | ||
| 91 | assert.is_true s\match "result: 42" | ||
| 92 | |||
| 93 | it "should handle quotes correctly", -> | ||
| 94 | s = | | ||
| 95 | "quoted" | ||
| 96 | 'single quoted' | ||
| 97 | assert.is_true s\match '"quoted"' | ||
| 98 | assert.is_true s\match "'single quoted'" | ||
| 99 | |||
| 100 | it "should work with multiple interpolations", -> | ||
| 101 | a, b, c = 1, 2, 3 | ||
| 102 | s = | | ||
| 103 | values: #{a}, #{b}, #{c} | ||
| 104 | assert.is_true s\match "values: 1, 2, 3" | ||
| 105 | |||
| 106 | it "should preserve newlines", -> | ||
| 107 | s = | | ||
| 108 | first line | ||
| 109 | second line | ||
| 110 | third line | ||
| 111 | lines = [line for line in s\gmatch "[^\n]+"] | ||
| 112 | assert.same #lines, 3 | ||
