-
-
Notifications
You must be signed in to change notification settings - Fork 764
/
0529.js
194 lines (164 loc) · 4.38 KB
/
0529.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
'use strict';
/* eslint-disable max-len */
const assert = require('assert');
const yaml = require('../../');
const sample = {
// normal key-value pair
simple_key: 'value',
// special characters in key
'foo\'bar"baz': 1,
// non-printables in key
'foo\vbar': 1,
// multiline key
'foo\nbar\nbaz': 1,
// ambiguous type, looks like a number
'0x1234': 1,
ambiguous: '0x1234',
// ambiguous type, looks like a quoted string
"'foo'": 1,
ambiguous1: "'foo'",
'"foo"': 1,
ambiguous2: '"foo"',
// quote in output
quote1: "foo'bar",
quote2: 'foo"bar',
// spaces at the beginning or end
space1: ' test',
space2: 'test ',
// test test test ...
wrapped: 'test '.repeat(20).trim(),
// multiline value
multiline: 'foo\nbar\nbaz',
// needs leading space indicator
leading_space: '\n test',
// non-printables in value
nonprintable1: 'foo\vbar',
nonprintable2: 'foo\vbar ' + 'test '.repeat(20).trim(),
nonprintable3: 'foo\vbar ' + 'foo\nbar\nbaz',
// empty string
empty: '',
// bool compat
yes: 'yes'
};
describe('should format strings with specified quoting type', function () {
it('quotingType=\', forceQuotes=false', function () {
const expected = `
simple_key: value
foo'bar"baz: 1
"foo\\vbar": 1
"foo\\nbar\\nbaz": 1
'0x1234': 1
ambiguous: '0x1234'
'''foo''': 1
ambiguous1: '''foo'''
'"foo"': 1
ambiguous2: '"foo"'
quote1: foo'bar
quote2: foo"bar
space1: ' test'
space2: 'test '
wrapped: >-
test test test test test test test test test test test test test test test
test test test test test
multiline: |-
foo
bar
baz
leading_space: |2-
test
nonprintable1: "foo\\vbar"
nonprintable2: "foo\\vbar test test test test test test test test test test test test test test test test test test test test"
nonprintable3: "foo\\vbar foo\\nbar\\nbaz"
empty: ''
'yes': 'yes'
`.replace(/^\n/, '');
assert.strictEqual(yaml.dump(sample, { quotingType: "'", forceQuotes: false }), expected);
});
it('quotingType=\", forceQuotes=false', function () {
const expected = `
simple_key: value
foo'bar"baz: 1
"foo\\vbar": 1
"foo\\nbar\\nbaz": 1
"0x1234": 1
ambiguous: "0x1234"
"'foo'": 1
ambiguous1: "'foo'"
"\\"foo\\"": 1
ambiguous2: "\\"foo\\""
quote1: foo'bar
quote2: foo"bar
space1: " test"
space2: "test "
wrapped: >-
test test test test test test test test test test test test test test test
test test test test test
multiline: |-
foo
bar
baz
leading_space: |2-
test
nonprintable1: "foo\\vbar"
nonprintable2: "foo\\vbar test test test test test test test test test test test test test test test test test test test test"
nonprintable3: "foo\\vbar foo\\nbar\\nbaz"
empty: ""
"yes": "yes"
`.replace(/^\n/, '');
assert.strictEqual(yaml.dump(sample, { quotingType: '"', forceQuotes: false }), expected);
});
it('quotingType=\', forceQuotes=true', function () {
const expected = `
simple_key: 'value'
foo'bar"baz: 1
"foo\\vbar": 1
"foo\\nbar\\nbaz": 1
'0x1234': 1
ambiguous: '0x1234'
'''foo''': 1
ambiguous1: '''foo'''
'"foo"': 1
ambiguous2: '"foo"'
quote1: 'foo''bar'
quote2: 'foo"bar'
space1: ' test'
space2: 'test '
wrapped: 'test test test test test test test test test test test test test test test test test test test test'
multiline: "foo\\nbar\\nbaz"
leading_space: "\\n test"
nonprintable1: "foo\\vbar"
nonprintable2: "foo\\vbar test test test test test test test test test test test test test test test test test test test test"
nonprintable3: "foo\\vbar foo\\nbar\\nbaz"
empty: ''
'yes': 'yes'
`.replace(/^\n/, '');
assert.strictEqual(yaml.dump(sample, { quotingType: "'", forceQuotes: true }), expected);
});
it('quotingType=\", forceQuotes=true', function () {
const expected = `
simple_key: "value"
foo'bar"baz: 1
"foo\\vbar": 1
"foo\\nbar\\nbaz": 1
"0x1234": 1
ambiguous: "0x1234"
"'foo'": 1
ambiguous1: "'foo'"
"\\"foo\\"": 1
ambiguous2: "\\"foo\\""
quote1: "foo'bar"
quote2: "foo\\"bar"
space1: " test"
space2: "test "
wrapped: "test test test test test test test test test test test test test test test test test test test test"
multiline: "foo\\nbar\\nbaz"
leading_space: "\\n test"
nonprintable1: "foo\\vbar"
nonprintable2: "foo\\vbar test test test test test test test test test test test test test test test test test test test test"
nonprintable3: "foo\\vbar foo\\nbar\\nbaz"
empty: ""
"yes": "yes"
`.replace(/^\n/, '');
assert.strictEqual(yaml.dump(sample, { quotingType: '"', forceQuotes: true }), expected);
});
});