aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/yaml_string_spec.yue
blob: 12963400f56d8660f45c1d1e8110b967048c1d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
describe "yaml string", ->
	it "should create basic yaml string", ->
		s = |
			hello
			world
		assert.is_true s\match "hello"
		assert.is_true s\match "world"

	it "should preserve indentation", ->
		s = |
			key1: value1
			key2: value2
		assert.is_true s\match "key1"
		assert.is_true s\match "key2"

	it "should support interpolation", ->
		name = "test"
		s = |
			hello #{name}
		assert.same s, "hello test"

	it "should handle complex interpolation", ->
		x, y = 10, 20
		s = |
			point:
				x: #{x}
				y: #{y}
		assert.is_true s\match "x: 10"
		assert.is_true s\match "y: 20"

	it "should work with expressions", ->
		s = |
			result: #{1 + 2}
		assert.is_true s\match "result: 3"

	it "should support multiline with variables", ->
		config = |
			database:
				host: localhost
				port: 5432
				name: mydb
		assert.is_true config\match "database:"
		assert.is_true config\match "host:"

	it "should escape special characters", ->
		s = |
			path: "C:\Program Files\App"
			note: 'He said: "#{Hello}!"'
		assert.is_true s\match "path:"
		assert.is_true s\match "note:"

	it "should work in function", ->
		fn = ->
			str = |
				foo:
					bar: baz
			return str

		result = fn!
		assert.is_true result\match "foo:"
		assert.is_true result\match "bar:"

	it "should strip common leading whitespace", ->
		fn = ->
			s = |
				nested:
					item: value
			s

		result = fn!
		assert.is_true result\match "nested:"
		assert.is_true result\match "item:"

	it "should support empty lines", ->
		s = |
			line1

			line3
		assert.is_true s\match "line1"
		assert.is_true s\match "line3"

	it "should work with table access in interpolation", ->
		t = {value: 100}
		s = |
			value: #{t.value}
		assert.is_true s\match "value: 100"

	it "should support function calls in interpolation", ->
		s = |
			result: #{(-> 42)!}
		assert.is_true s\match "result: 42"

	it "should handle quotes correctly", ->
		s = |
			"quoted"
			'single quoted'
		assert.is_true s\match '"quoted"'
		assert.is_true s\match "'single quoted'"

	it "should work with multiple interpolations", ->
		a, b, c = 1, 2, 3
		s = |
			values: #{a}, #{b}, #{c}
		assert.is_true s\match "values: 1, 2, 3"

	it "should preserve newlines", ->
		s = |
			first line
			second line
			third line
		lines = [line for line in s\gmatch "[^\n]+"]
		assert.same #lines, 3