Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/lyaml/spec/ext_yaml_emitter_spec.yaml
178467 views
1
# LYAML binding for Lua 5.1, 5.2, 5.3 & 5.4
2
# Copyright (C) 2013-2022 Gary V. Vaughan
3
4
specify emitting:
5
- it diagnoses an invalid event:
6
emitter = yaml.emitter ()
7
expect (emitter.emit "not an event").to_raise "expected table"
8
- it can generate an empty stream:
9
pending (github_issue "2")
10
expect (emit {
11
{type = "DOCUMENT_START", implicit = true},
12
{type = "SCALAR", value = ""},
13
{type = "DOCUMENT_END", implicit = true},
14
}).
15
to_equal ""
16
17
- describe STREAM_START:
18
- it diagnoses unrecognised encodings:
19
expect (emitevents (yaml.emitter (), {
20
{type = "STREAM_START", encoding = "notexists"},
21
"STREAM_END"})).
22
to_raise "invalid stream encoding 'notexists'"
23
- it accepts an encoding parameter:
24
expect (emitevents (yaml.emitter (), {
25
{type = "STREAM_START", encoding = "UTF16BE"},
26
"STREAM_END"})).
27
to_equal (BOM)
28
29
- describe STREAM_END:
30
- it returns the yaml document from the preceding events:
31
expect (emit {"DOCUMENT_START", {type = "SCALAR", value = "woo!"},
32
"DOCUMENT_END"}).
33
to_equal "--- woo!\n...\n"
34
35
- describe DOCUMENT_START:
36
- it accepts a version directive parameter:
37
expect (emit {{type = "DOCUMENT_START",
38
version_directive = { major = 1, minor = 1 }},
39
{type = "SCALAR", value = ""},
40
"DOCUMENT_END"}).
41
to_match "^%%YAML 1.1\n---"
42
- it accepts a list of tag directives:
43
expect (emit {{type = "DOCUMENT_START",
44
tag_directives = {{handle = "!",
45
prefix = "tag:ben-kiki.org,2000:app/"}}},
46
{type = "SCALAR", value = ""},
47
"DOCUMENT_END"}).
48
to_contain "%TAG ! tag:ben-kiki.org,2000:app/\n---"
49
expect (emit {
50
{type = "DOCUMENT_START",
51
tag_directives = {{handle = "!",
52
prefix = "tag:ben-kiki.org,2000:app/"},
53
{handle = "!!",
54
prefix = "tag:yaml.org,2002:"}}},
55
{type = "SCALAR", value = ""},
56
"DOCUMENT_END"}).
57
to_contain ("%TAG ! tag:ben-kiki.org,2000:app/\n" ..
58
"%TAG !! tag:yaml.org,2002:\n---")
59
- it accepts an implicit parameter:
60
expect (emit {{type = "DOCUMENT_START", implicit = true},
61
{type = "SCALAR", value = ""}, "DOCUMENT_END"}).
62
not_to_contain "--- \n"
63
pending (github_issue "2")
64
expect (emit {{type = "DOCUMENT_START", implicit = false},
65
{type = "SCALAR", value = ""}, "DOCUMENT_END"}).
66
not_to_contain "---"
67
68
- describe DOCUMENT_END:
69
- it accepts an implicit parameter:
70
expect (emit {"DOCUMENT_START", {type = "SCALAR", value = ""},
71
{type = "DOCUMENT_END", implicit = false}}).
72
to_contain "\n..."
73
pending (github_issue "2")
74
expect (emit {"DOCUMENT_START", {type = "SCALAR", value = ""},
75
{type = "DOCUMENT_END", implicit = true}}).
76
not_to_contain "\n..."
77
78
- describe MAPPING_START:
79
- it accepts an anchor parameter:
80
expect (emit {"DOCUMENT_START",
81
{type = "MAPPING_START", anchor = "foo"},
82
"MAPPING_END", "DOCUMENT_END"}).
83
to_contain "&foo"
84
- it diagnoses unrecognised styles:
85
expect (emit {"DOCUMENT_START",
86
{type = "MAPPING_START", style = "notexists"},
87
"MAPPING_END", "DOCUMENT_END"}).
88
to_raise "invalid mapping style 'notexists'"
89
- it understands block style: '
90
expect (emit {"DOCUMENT_START",
91
{type = "MAPPING_START", style = "BLOCK"},
92
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
93
"MAPPING_END", "DOCUMENT_END"}).
94
to_contain "foo: bar\n"'
95
- it understands flow style: '
96
expect (emit {"DOCUMENT_START",
97
{type = "MAPPING_START", style = "FLOW"},
98
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
99
{type = "SCALAR", value = "baz"}, {type = "SCALAR", value = "qux"},
100
"MAPPING_END", "DOCUMENT_END"}).
101
to_contain "{foo: bar, baz: qux}\n"'
102
- it accepts an explicit tag parameter: '
103
expect (emit {"DOCUMENT_START",
104
{type = "MAPPING_START", style = "FLOW",
105
tag = "tag:yaml.org,2002:map", implicit = false},
106
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
107
"MAPPING_END", "DOCUMENT_END"}).
108
to_contain "!!map {foo: bar}"'
109
- it accepts an implicit tag parameter: '
110
expect (emit {"DOCUMENT_START",
111
{type = "MAPPING_START", tag = "tag:yaml.org,2002:map", implicit = true},
112
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
113
"MAPPING_END", "DOCUMENT_END"}).
114
not_to_contain "map"'
115
116
- describe MAPPING_END:
117
- it requires no parameters: '
118
expect (emit {"DOCUMENT_START", "MAPPING_START",
119
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
120
"MAPPING_END", "DOCUMENT_END"}).
121
to_contain "foo: bar\n"'
122
123
- describe SEQUENCE_START:
124
- it accepts an anchor parameter:
125
expect (emit {"DOCUMENT_START",
126
{type = "SEQUENCE_START", anchor = "foo"},
127
"SEQUENCE_END", "DOCUMENT_END"}).
128
to_contain "&foo"
129
- it diagnoses unrecognised styles:
130
expect (emit {"DOCUMENT_START",
131
{type = "SEQUENCE_START", style = "notexists"},
132
"SEQUENCE_END", "DOCUMENT_END"}).
133
to_raise "invalid sequence style 'notexists'"
134
- it understands block style:
135
expect (emit {"DOCUMENT_START",
136
{type = "SEQUENCE_START", style = "BLOCK"},
137
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
138
"SEQUENCE_END", "DOCUMENT_END"}).
139
to_contain "- foo\n- bar\n"
140
- it understands flow style:
141
expect (emit {"DOCUMENT_START",
142
{type = "SEQUENCE_START", style = "FLOW"},
143
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
144
"SEQUENCE_END", "DOCUMENT_END"}).
145
to_contain "[foo, bar]"
146
- it accepts an explicit tag parameter:
147
expect (emit {"DOCUMENT_START",
148
{type = "SEQUENCE_START", style = "FLOW",
149
tag = "tag:yaml.org,2002:sequence", implicit = false},
150
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
151
"SEQUENCE_END", "DOCUMENT_END"}).
152
to_contain "!!sequence [foo, bar]\n"
153
- it accepts an implicit tag parameter:
154
expect (emit {"DOCUMENT_START",
155
{type = "SEQUENCE_START", style = "FLOW",
156
tag = "tag:yaml.org,2002:sequence", implicit = true},
157
{type = "SCALAR", value = "foo"}, {type = "SCALAR", value = "bar"},
158
"SEQUENCE_END", "DOCUMENT_END"}).
159
not_to_contain "sequence"
160
161
- describe SEQUENCE_END:
162
- it requires no parameters: '
163
expect (emit {"DOCUMENT_START", "SEQUENCE_START",
164
{type = "SCALAR", value = "moo"},
165
"SEQUENCE_END", "DOCUMENT_END"}).
166
to_contain "- moo\n"'
167
168
- describe SCALAR:
169
- it diagnoses a missing value parameter:
170
- it accepts a value parameter:
171
expect (emit {"DOCUMENT_START", {type = "SCALAR", value = "boo"},
172
"DOCUMENT_END"}).
173
to_contain "boo"
174
- it diagnoses unrecognised styles:
175
expect (emit {"DOCUMENT_START",
176
{type = "SCALAR", style = "notexists", value = "foo"},
177
"DOCUMENT_END"}).
178
to_raise "invalid scalar style 'notexists'"
179
- it understands plain style:
180
expect (emit {"DOCUMENT_START",
181
{type = "SCALAR", style = "PLAIN", value = "boo"},
182
"DOCUMENT_END"}).
183
to_contain "boo\n"
184
- it understands single quoted style:
185
expect (emit {"DOCUMENT_START",
186
{type = "SCALAR", style = "SINGLE_QUOTED", value = "bar"},
187
"DOCUMENT_END"}).
188
to_contain "'bar'\n"
189
expect (emit {"DOCUMENT_START",
190
{type = "SCALAR", style = "SINGLE_QUOTED", value = "bar'"},
191
"DOCUMENT_END"}).
192
to_contain "'bar'''\n"
193
- it understands double quoted style:
194
expect (emit {"DOCUMENT_START",
195
{type = "SCALAR", style = "DOUBLE_QUOTED", value = "baz"},
196
"DOCUMENT_END"}).
197
to_contain '"baz"\n'
198
expect (emit {"DOCUMENT_START",
199
{type = "SCALAR", style = "DOUBLE_QUOTED", value = '"baz"'},
200
"DOCUMENT_END"}).
201
to_contain ([["\"baz\""]] .. "\n")
202
- it understands literal style:
203
expect (emit {"DOCUMENT_START",
204
{type = "SCALAR", style = "LITERAL", value = "quux"},
205
"DOCUMENT_END"}).
206
to_contain "|-\n quux\n"
207
- it understands folded style:
208
expect (emit {"DOCUMENT_START",
209
{type = "SCALAR", style = "FOLDED", value = "thud"},
210
"DOCUMENT_END"}).
211
to_contain ">-\n thud\n"
212
- it understands plain_implicit:
213
expect (emit {"DOCUMENT_START",
214
{type = "SCALAR", style = "PLAIN", value = "hello", plain_implicit=false},
215
"DOCUMENT_END"}).
216
to_contain "'hello'\n"
217
- it understands quoted_implicit:
218
expect (emit {"DOCUMENT_START",
219
{type = "SCALAR", style = "PLAIN", value = "- world", quoted_implicit=false},
220
"DOCUMENT_END"}).
221
to_contain "! '- world'\n"
222
- it understands tag:
223
expect (emit {"DOCUMENT_START",
224
{type = "SCALAR", style = "PLAIN", value = "bug_squash", tag="tagger", plain_implicit=false, quoted_implicit=false},
225
"DOCUMENT_END"}).
226
to_contain "!<tagger> bug_squash\n"
227
228
- describe ALIAS:
229
- it diagnoses missing anchor parameter:
230
- it diagnoses non-alphanumeric anchor characters:
231
expect (emit {"DOCUMENT_START", {type = "ALIAS", anchor = "woo!"},
232
"DOCUMENT_END"}).
233
to_raise "must contain alphanumerical characters only"
234
- it accepts an anchor parameter:
235
expect (emit {"DOCUMENT_START", "SEQUENCE_START",
236
{type = "SCALAR", anchor = "woo", value = "hoo"},
237
{type = "ALIAS", anchor = "woo"},
238
"SEQUENCE_END", "DOCUMENT_END"}).
239
to_contain.all_of {"&woo", "*woo"}
240
241