forked from nodeca/js-yaml
/
0470.js
145 lines (123 loc) · 3.26 KB
/
0470.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
'use strict';
var assert = require('assert');
var yaml = require('../..');
test('should not unnecessarily apply quotes', function () {
var expected = 'url: https://github.com/nodeca/js-yaml\n';
var input = {
url: 'https://github.com/nodeca/js-yaml'
};
var actual = yaml.dump(input);
assert.strictEqual(actual, expected);
var roundTrip = yaml.safeLoad(actual);
assert.deepStrictEqual(roundTrip, input);
});
test('should not unnecessarily apply quotes - space then /\n at end of value', function () {
var expected = 'url: \'https://github.com/nodeca/js-yaml \'\n';
var input = {
url: 'https://github.com/nodeca/js-yaml '
};
var actual = yaml.dump(input);
assert.strictEqual(actual, expected);
var roundTrip = yaml.safeLoad(actual);
assert.deepStrictEqual(roundTrip, input);
});
test('should not unnecessarily apply quotes - space after colon', function () {
var expected = 'url: \'https: //github.com/nodeca/js-yaml\'\n';
var input = {
url: 'https: //github.com/nodeca/js-yaml'
};
var actual = yaml.dump(input);
assert.strictEqual(actual, expected);
var roundTrip = yaml.safeLoad(actual);
assert.deepStrictEqual(roundTrip, input);
});
/*
check for the removal of these dumper checks to deliver proper output
&& c !== CHAR_COMMA
&& c !== CHAR_LEFT_SQUARE_BRACKET
&& c !== CHAR_RIGHT_SQUARE_BRACKET
&& c !== CHAR_LEFT_CURLY_BRACKET
&& c !== CHAR_RIGHT_CURLY_BRACKET
// - ":" - "#"
&& c !== CHAR_COLON
&& c !== CHAR_SHARP;
*/
test('should not unnecessarily apply quotes - : colon, # sharp, comma and []{}', function () {
var expected = [
'sharp1: C#123',
'sharp2: C# 123',
"sharp3: 'C #123'",
'sharp4: C123#',
"sharp5: '#C123'",
"sharp6: '#C123#'",
'colon1: C:123',
"colon2: 'C: 123'",
'colon3: C :123',
"colon4: 'C123:'",
"colon5: ':C123'",
"colon6: ':C123:'",
'comma1: C,123',
'comma2: C, 123',
'comma3: C ,123',
'comma4: C123,',
"comma5: ',C123'",
"comma6: ',C123,'",
'sqbr1: C[1]23',
'sqbr2: C [1]23',
"sqbr3: '[C] 123'",
'sqbr4: C12[3]',
"sqbr5: '[C]123'",
"sqbr6: '[C]12[3]'",
"sqbr7: '[]C123[]'",
'sqbr8: C [123]',
'cbr1: C{1}23',
'cbr2: C {1}23',
"cbr3: '{C} 123'",
'cbr4: C12{3}',
"cbr5: '{C}123'",
"cbr6: '{C}12{3}'",
"cbr7: '{}C123{}'",
'cbr8: C {123}',
''
].join('\n');
var input = {
sharp1: 'C#123',
sharp2: 'C# 123',
sharp3: 'C #123',
sharp4: 'C123#',
sharp5: '#C123',
sharp6: '#C123#',
colon1: 'C:123',
colon2: 'C: 123',
colon3: 'C :123',
colon4: 'C123:',
colon5: ':C123',
colon6: ':C123:',
comma1: 'C,123',
comma2: 'C, 123',
comma3: 'C ,123',
comma4: 'C123,',
comma5: ',C123',
comma6: ',C123,',
sqbr1: 'C[1]23',
sqbr2: 'C [1]23',
sqbr3: '[C] 123',
sqbr4: 'C12[3]',
sqbr5: '[C]123',
sqbr6: '[C]12[3]',
sqbr7: '[]C123[]',
sqbr8: 'C [123]',
cbr1: 'C{1}23',
cbr2: 'C {1}23',
cbr3: '{C} 123',
cbr4: 'C12{3}',
cbr5: '{C}123',
cbr6: '{C}12{3}',
cbr7: '{}C123{}',
cbr8: 'C {123}'
};
var actual = yaml.dump(input);
assert.strictEqual(actual, expected);
var roundTrip = yaml.safeLoad(actual);
assert.deepStrictEqual(roundTrip, input);
});