scratch – Diff between revs 75 and 125

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 75 Rev 125
1 // Generated by CoffeeScript 1.10.0 1 // Generated by CoffeeScript 1.12.4
2 var YAML, examplePath, ref, url; 2 var YAML, examplePath, ref, url;
3   3  
4 if (typeof YAML === "undefined" || YAML === null) { 4 if (typeof YAML === "undefined" || YAML === null) {
5 YAML = require('../../src/Yaml'); 5 YAML = require('../../src/Yaml');
6 } 6 }
7   7  
8 describe('Parsed YAML Collections', function() { 8 describe('Parsed YAML Collections', function() {
9 it('can be simple sequence', function() { 9 it('can be simple sequence', function() {
10 return expect(YAML.parse("- apple\n- banana\n- carrot")).toEqual(['apple', 'banana', 'carrot']); 10 return expect(YAML.parse("- apple\n- banana\n- carrot")).toEqual(['apple', 'banana', 'carrot']);
11 }); 11 });
12 it('can be nested sequences', function() { 12 it('can be nested sequences', function() {
13 return expect(YAML.parse("-\n - foo\n - bar\n - baz")).toEqual([['foo', 'bar', 'baz']]); 13 return expect(YAML.parse("-\n - foo\n - bar\n - baz")).toEqual([['foo', 'bar', 'baz']]);
14 }); 14 });
15 it('can be mixed sequences', function() { 15 it('can be mixed sequences', function() {
16 return expect(YAML.parse("- apple\n-\n - foo\n - bar\n - x123\n- banana\n- carrot")).toEqual(['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot']); 16 return expect(YAML.parse("- apple\n-\n - foo\n - bar\n - x123\n- banana\n- carrot")).toEqual(['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot']);
17 }); 17 });
18 it('can be deeply nested sequences', function() { 18 it('can be deeply nested sequences', function() {
19 return expect(YAML.parse("-\n -\n - uno\n - dos")).toEqual([[['uno', 'dos']]]); 19 return expect(YAML.parse("-\n -\n - uno\n - dos")).toEqual([[['uno', 'dos']]]);
20 }); 20 });
21 it('can be simple mapping', function() { 21 it('can be simple mapping', function() {
22 return expect(YAML.parse("foo: whatever\nbar: stuff")).toEqual({ 22 return expect(YAML.parse("foo: whatever\nbar: stuff")).toEqual({
23 foo: 'whatever', 23 foo: 'whatever',
24 bar: 'stuff' 24 bar: 'stuff'
25 }); 25 });
26 }); 26 });
27 it('can be sequence in a mapping', function() { 27 it('can be sequence in a mapping', function() {
28 return expect(YAML.parse("foo: whatever\nbar:\n - uno\n - dos")).toEqual({ 28 return expect(YAML.parse("foo: whatever\nbar:\n - uno\n - dos")).toEqual({
29 foo: 'whatever', 29 foo: 'whatever',
30 bar: ['uno', 'dos'] 30 bar: ['uno', 'dos']
31 }); 31 });
32 }); 32 });
33 it('can be nested mappings', function() { 33 it('can be nested mappings', function() {
34 return expect(YAML.parse("foo: whatever\nbar:\n fruit: apple\n name: steve\n sport: baseball")).toEqual({ 34 return expect(YAML.parse("foo: whatever\nbar:\n fruit: apple\n name: steve\n sport: baseball")).toEqual({
35 foo: 'whatever', 35 foo: 'whatever',
36 bar: { 36 bar: {
37 fruit: 'apple', 37 fruit: 'apple',
38 name: 'steve', 38 name: 'steve',
39 sport: 'baseball' 39 sport: 'baseball'
40 } 40 }
41 }); 41 });
42 }); 42 });
43 it('can be mixed mapping', function() { 43 it('can be mixed mapping', function() {
44 return expect(YAML.parse("foo: whatever\nbar:\n -\n fruit: apple\n name: steve\n sport: baseball\n - more\n -\n python: rocks\n perl: papers\n ruby: scissorses")).toEqual({ 44 return expect(YAML.parse("foo: whatever\nbar:\n -\n fruit: apple\n name: steve\n sport: baseball\n - more\n -\n python: rocks\n perl: papers\n ruby: scissorses")).toEqual({
45 foo: 'whatever', 45 foo: 'whatever',
46 bar: [ 46 bar: [
47 { 47 {
48 fruit: 'apple', 48 fruit: 'apple',
49 name: 'steve', 49 name: 'steve',
50 sport: 'baseball' 50 sport: 'baseball'
51 }, 'more', { 51 }, 'more', {
52 python: 'rocks', 52 python: 'rocks',
53 perl: 'papers', 53 perl: 'papers',
54 ruby: 'scissorses' 54 ruby: 'scissorses'
55 } 55 }
56 ] 56 ]
57 }); 57 });
58 }); 58 });
59 it('can have mapping-in-sequence shortcut', function() { 59 it('can have mapping-in-sequence shortcut', function() {
60 return expect(YAML.parse("- work on YAML.py:\n - work on Store")).toEqual([ 60 return expect(YAML.parse("- work on YAML.py:\n - work on Store")).toEqual([
61 { 61 {
62 'work on YAML.py': ['work on Store'] 62 'work on YAML.py': ['work on Store']
63 } 63 }
64 ]); 64 ]);
65 }); 65 });
66 it('can have unindented sequence-in-mapping shortcut', function() { 66 it('can have unindented sequence-in-mapping shortcut', function() {
67 return expect(YAML.parse("allow:\n- 'localhost'\n- '%.sourceforge.net'\n- '%.freepan.org'")).toEqual({ 67 return expect(YAML.parse("allow:\n- 'localhost'\n- '%.sourceforge.net'\n- '%.freepan.org'")).toEqual({
68 allow: ['localhost', '%.sourceforge.net', '%.freepan.org'] 68 allow: ['localhost', '%.sourceforge.net', '%.freepan.org']
69 }); 69 });
70 }); 70 });
71 it('can merge key', function() { 71 it('can merge key', function() {
72 return expect(YAML.parse("mapping:\n name: Joe\n job: Accountant\n <<:\n age: 38")).toEqual({ 72 return expect(YAML.parse("mapping:\n name: Joe\n job: Accountant\n <<:\n age: 38")).toEqual({
73 mapping: { 73 mapping: {
74 name: 'Joe', 74 name: 'Joe',
75 job: 'Accountant', 75 job: 'Accountant',
76 age: 38 76 age: 38
77 } 77 }
78 }); 78 });
79 }); 79 });
80 return it('can ignore trailing empty lines for smallest indent', function() { 80 return it('can ignore trailing empty lines for smallest indent', function() {
81 return expect(YAML.parse(" trailing: empty lines\n")).toEqual({ 81 return expect(YAML.parse(" trailing: empty lines\n")).toEqual({
82 trailing: 'empty lines' 82 trailing: 'empty lines'
83 }); 83 });
84 }); 84 });
85 }); 85 });
86   86  
87 describe('Parsed YAML Inline Collections', function() { 87 describe('Parsed YAML Inline Collections', function() {
88 it('can be simple inline array', function() { 88 it('can be simple inline array', function() {
89 return expect(YAML.parse("---\nseq: [ a, b, c ]")).toEqual({ 89 return expect(YAML.parse("---\nseq: [ a, b, c ]")).toEqual({
90 seq: ['a', 'b', 'c'] 90 seq: ['a', 'b', 'c']
91 }); 91 });
92 }); 92 });
93 it('can be simple inline hash', function() { 93 it('can be simple inline hash', function() {
94 return expect(YAML.parse("---\nhash: { name: Steve, foo: bar }")).toEqual({ 94 return expect(YAML.parse("---\nhash: { name: Steve, foo: bar }")).toEqual({
95 hash: { 95 hash: {
96 name: 'Steve', 96 name: 'Steve',
97 foo: 'bar' 97 foo: 'bar'
98 } 98 }
99 }); 99 });
100 }); 100 });
101 it('can be nested inline hash', function() { 101 it('can be nested inline hash', function() {
102 return expect(YAML.parse("---\nhash: { val1: \"string\", val2: { v2k1: \"v2k1v\" } }")).toEqual({ 102 return expect(YAML.parse("---\nhash: { val1: \"string\", val2: { v2k1: \"v2k1v\" } }")).toEqual({
103 hash: { 103 hash: {
104 val1: 'string', 104 val1: 'string',
105 val2: { 105 val2: {
106 v2k1: 'v2k1v' 106 v2k1: 'v2k1v'
107 } 107 }
108 } 108 }
109 }); 109 });
110 }); 110 });
111 return it('can be multi-line inline collections', function() { 111 return it('can be multi-line inline collections', function() {
112 return expect(YAML.parse("languages: [ Ruby,\n Perl,\n Python ]\nwebsites: { YAML: yaml.org,\n Ruby: ruby-lang.org,\n Python: python.org,\n Perl: use.perl.org }")).toEqual({ 112 return expect(YAML.parse("languages: [ Ruby,\n Perl,\n Python ]\nwebsites: { YAML: yaml.org,\n Ruby: ruby-lang.org,\n Python: python.org,\n Perl: use.perl.org }")).toEqual({
113 languages: ['Ruby', 'Perl', 'Python'], 113 languages: ['Ruby', 'Perl', 'Python'],
114 websites: { 114 websites: {
115 YAML: 'yaml.org', 115 YAML: 'yaml.org',
116 Ruby: 'ruby-lang.org', 116 Ruby: 'ruby-lang.org',
117 Python: 'python.org', 117 Python: 'python.org',
118 Perl: 'use.perl.org' 118 Perl: 'use.perl.org'
119 } 119 }
120 }); 120 });
121 }); 121 });
122 }); 122 });
123   123  
124 describe('Parsed YAML Basic Types', function() { 124 describe('Parsed YAML Basic Types', function() {
125 it('can be strings', function() { 125 it('can be strings', function() {
126 return expect(YAML.parse("---\nString")).toEqual('String'); 126 return expect(YAML.parse("---\nString")).toEqual('String');
127 }); 127 });
128 it('can be double-quoted strings with backslashes', function() { 128 it('can be double-quoted strings with backslashes', function() {
129 return expect(YAML.parse("str:\n \"string with \\\\ inside\"")).toEqual({ 129 return expect(YAML.parse("str:\n \"string with \\\\ inside\"")).toEqual({
130 str: 'string with \\ inside' 130 str: 'string with \\ inside'
131 }); 131 });
132 }); 132 });
133 it('can be single-quoted strings with backslashes', function() { 133 it('can be single-quoted strings with backslashes', function() {
134 return expect(YAML.parse("str:\n 'string with \\\\ inside'")).toEqual({ 134 return expect(YAML.parse("str:\n 'string with \\\\ inside'")).toEqual({
135 str: 'string with \\\\ inside' 135 str: 'string with \\\\ inside'
136 }); 136 });
137 }); 137 });
138 it('can be double-quoted strings with line breaks', function() { 138 it('can be double-quoted strings with line breaks', function() {
139 return expect(YAML.parse("str:\n \"string with \\n inside\"")).toEqual({ 139 return expect(YAML.parse("str:\n \"string with \\n inside\"")).toEqual({
140 str: 'string with \n inside' 140 str: 'string with \n inside'
141 }); 141 });
142 }); 142 });
143 it('can be single-quoted strings with escaped line breaks', function() { 143 it('can be single-quoted strings with escaped line breaks', function() {
144 return expect(YAML.parse("str:\n 'string with \\n inside'")).toEqual({ 144 return expect(YAML.parse("str:\n 'string with \\n inside'")).toEqual({
145 str: 'string with \\n inside' 145 str: 'string with \\n inside'
146 }); 146 });
147 }); 147 });
148 it('can be double-quoted strings with line breaks and backslashes', function() { 148 it('can be double-quoted strings with line breaks and backslashes', function() {
149 return expect(YAML.parse("str:\n \"string with \\n inside and \\\\ also\"")).toEqual({ 149 return expect(YAML.parse("str:\n \"string with \\n inside and \\\\ also\"")).toEqual({
150 str: 'string with \n inside and \\ also' 150 str: 'string with \n inside and \\ also'
151 }); 151 });
152 }); 152 });
153 it('can be single-quoted strings with line breaks and backslashes', function() { 153 it('can be single-quoted strings with line breaks and backslashes', function() {
154 return expect(YAML.parse("str:\n 'string with \\n inside and \\\\ also'")).toEqual({ 154 return expect(YAML.parse("str:\n 'string with \\n inside and \\\\ also'")).toEqual({
155 str: 'string with \\n inside and \\\\ also' 155 str: 'string with \\n inside and \\\\ also'
156 }); 156 });
157 }); 157 });
158 it('can have string characters in sequences', function() { 158 it('can have string characters in sequences', function() {
159 return expect(YAML.parse("- What's Yaml?\n- It's for writing data structures in plain text.\n- And?\n- And what? That's not good enough for you?\n- No, I mean, \"And what about Yaml?\"\n- Oh, oh yeah. Uh.. Yaml for JavaScript.")).toEqual(["What's Yaml?", "It's for writing data structures in plain text.", "And?", "And what? That's not good enough for you?", "No, I mean, \"And what about Yaml?\"", "Oh, oh yeah. Uh.. Yaml for JavaScript."]); 159 return expect(YAML.parse("- What's Yaml?\n- It's for writing data structures in plain text.\n- And?\n- And what? That's not good enough for you?\n- No, I mean, \"And what about Yaml?\"\n- Oh, oh yeah. Uh.. Yaml for JavaScript.")).toEqual(["What's Yaml?", "It's for writing data structures in plain text.", "And?", "And what? That's not good enough for you?", "No, I mean, \"And what about Yaml?\"", "Oh, oh yeah. Uh.. Yaml for JavaScript."]);
160 }); 160 });
161 it('can have indicators in strings', function() { 161 it('can have indicators in strings', function() {
162 return expect(YAML.parse("the colon followed by space is an indicator: but is a string:right here\nsame for the pound sign: here we have it#in a string\nthe comma can, honestly, be used in most cases: [ but not in, inline collections ]")).toEqual({ 162 return expect(YAML.parse("the colon followed by space is an indicator: but is a string:right here\nsame for the pound sign: here we have it#in a string\nthe comma can, honestly, be used in most cases: [ but not in, inline collections ]")).toEqual({
163 'the colon followed by space is an indicator': 'but is a string:right here', 163 'the colon followed by space is an indicator': 'but is a string:right here',
164 'same for the pound sign': 'here we have it#in a string', 164 'same for the pound sign': 'here we have it#in a string',
165 'the comma can, honestly, be used in most cases': ['but not in', 'inline collections'] 165 'the comma can, honestly, be used in most cases': ['but not in', 'inline collections']
166 }); 166 });
167 }); 167 });
168 it('can force strings', function() { 168 it('can force strings', function() {
169 return expect(YAML.parse("date string: !str 2001-08-01\nnumber string: !str 192\ndate string 2: !!str 2001-08-01\nnumber string 2: !!str 192")).toEqual({ 169 return expect(YAML.parse("date string: !str 2001-08-01\nnumber string: !str 192\ndate string 2: !!str 2001-08-01\nnumber string 2: !!str 192")).toEqual({
170 'date string': '2001-08-01', 170 'date string': '2001-08-01',
171 'number string': '192', 171 'number string': '192',
172 'date string 2': '2001-08-01', 172 'date string 2': '2001-08-01',
173 'number string 2': '192' 173 'number string 2': '192'
174 }); 174 });
175 }); 175 });
176 it('can be single-quoted strings', function() { 176 it('can be single-quoted strings', function() {
177 return expect(YAML.parse("all my favorite symbols: '#:!/%.)'\na few i hate: '&(*'\nwhy do i hate them?: 'it''s very hard to explain'")).toEqual({ 177 return expect(YAML.parse("all my favorite symbols: '#:!/%.)'\na few i hate: '&(*'\nwhy do i hate them?: 'it''s very hard to explain'")).toEqual({
178 'all my favorite symbols': '#:!/%.)', 178 'all my favorite symbols': '#:!/%.)',
179 'a few i hate': '&(*', 179 'a few i hate': '&(*',
180 'why do i hate them?': 'it\'s very hard to explain' 180 'why do i hate them?': 'it\'s very hard to explain'
181 }); 181 });
182 }); 182 });
183 it('can be double-quoted strings', function() { 183 it('can be double-quoted strings', function() {
184 return expect(YAML.parse("i know where i want my line breaks: \"one here\\nand another here\\n\"")).toEqual({ 184 return expect(YAML.parse("i know where i want my line breaks: \"one here\\nand another here\\n\"")).toEqual({
185 'i know where i want my line breaks': "one here\nand another here\n" 185 'i know where i want my line breaks': "one here\nand another here\n"
186 }); 186 });
187 }); 187 });
188 it('can be null', function() { 188 it('can be null', function() {
189 return expect(YAML.parse("name: Mr. Show\nhosted by: Bob and David\ndate of next season: ~")).toEqual({ 189 return expect(YAML.parse("name: Mr. Show\nhosted by: Bob and David\ndate of next season: ~")).toEqual({
190 'name': 'Mr. Show', 190 'name': 'Mr. Show',
191 'hosted by': 'Bob and David', 191 'hosted by': 'Bob and David',
192 'date of next season': null 192 'date of next season': null
193 }); 193 });
194 }); 194 });
195 it('can be boolean', function() { 195 it('can be boolean', function() {
196 return expect(YAML.parse("Is Gus a Liar?: true\nDo I rely on Gus for Sustenance?: false")).toEqual({ 196 return expect(YAML.parse("Is Gus a Liar?: true\nDo I rely on Gus for Sustenance?: false")).toEqual({
197 'Is Gus a Liar?': true, 197 'Is Gus a Liar?': true,
198 'Do I rely on Gus for Sustenance?': false 198 'Do I rely on Gus for Sustenance?': false
199 }); 199 });
200 }); 200 });
201 it('can be integers', function() { 201 it('can be integers', function() {
202 return expect(YAML.parse("zero: 0\nsimple: 12\none-thousand: 1,000\nnegative one-thousand: -1,000")).toEqual({ 202 return expect(YAML.parse("zero: 0\nsimple: 12\none-thousand: 1,000\nnegative one-thousand: -1,000")).toEqual({
203 'zero': 0, 203 'zero': 0,
204 'simple': 12, 204 'simple': 12,
205 'one-thousand': 1000, 205 'one-thousand': 1000,
206 'negative one-thousand': -1000 206 'negative one-thousand': -1000
207 }); 207 });
208 }); 208 });
209 it('can be integers as map keys', function() { 209 it('can be integers as map keys', function() {
210 return expect(YAML.parse("1: one\n2: two\n3: three")).toEqual({ 210 return expect(YAML.parse("1: one\n2: two\n3: three")).toEqual({
211 1: 'one', 211 1: 'one',
212 2: 'two', 212 2: 'two',
213 3: 'three' 213 3: 'three'
214 }); 214 });
215 }); 215 });
216 it('can be floats', function() { 216 it('can be floats', function() {
217 return expect(YAML.parse("a simple float: 2.00\nlarger float: 1,000.09\nscientific notation: 1.00009e+3")).toEqual({ 217 return expect(YAML.parse("a simple float: 2.00\nlarger float: 1,000.09\nscientific notation: 1.00009e+3")).toEqual({
218 'a simple float': 2.0, 218 'a simple float': 2.0,
219 'larger float': 1000.09, 219 'larger float': 1000.09,
220 'scientific notation': 1000.09 220 'scientific notation': 1000.09
221 }); 221 });
222 }); 222 });
223 it('can be time', function() { 223 it('can be time', function() {
224 var iso8601Date, spaceSeparatedDate, withDatesToTime; 224 var iso8601Date, spaceSeparatedDate, withDatesToTime;
225 iso8601Date = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10)); 225 iso8601Date = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
226 iso8601Date.setTime(iso8601Date.getTime() - 5 * 3600 * 1000); 226 iso8601Date.setTime(iso8601Date.getTime() - 5 * 3600 * 1000);
227 spaceSeparatedDate = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10)); 227 spaceSeparatedDate = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
228 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() - 5 * 3600 * 1000); 228 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() + 5 * 3600 * 1000);
229 withDatesToTime = function(input) { 229 withDatesToTime = function(input) {
230 var key, res, val; 230 var key, res, val;
231 res = {}; 231 res = {};
232 for (key in input) { 232 for (key in input) {
233 val = input[key]; 233 val = input[key];
234 res[key] = Math.round(val.getTime() / 1000) * 1000; 234 res[key] = val.getTime();
235 } 235 }
236 return res; 236 return res;
237 }; 237 };
238 return expect(withDatesToTime(YAML.parse("iso8601: 2001-12-14t21:59:43.10-05:00\nspace seperated: 2001-12-14 21:59:43.10 -05:00"))).toEqual(withDatesToTime({ 238 return expect(withDatesToTime(YAML.parse("iso8601: 2001-12-14t21:59:43.010+05:00\nspace separated: 2001-12-14 21:59:43.010 -05:00"))).toEqual(withDatesToTime({
239 'iso8601': iso8601Date, 239 'iso8601': iso8601Date,
240 'space seperated': spaceSeparatedDate 240 'space separated': spaceSeparatedDate
241 })); 241 }));
242 }); 242 });
243 return it('can be date', function() { 243 return it('can be date', function() {
244 var aDate, withDatesToTime; 244 var aDate, withDatesToTime;
245 aDate = new Date(Date.UTC(1976, 7 - 1, 31, 0, 0, 0, 0)); 245 aDate = new Date(Date.UTC(1976, 7 - 1, 31, 0, 0, 0, 0));
246 withDatesToTime = function(input) { 246 withDatesToTime = function(input) {
247 var key, res, val; 247 var key, res, val;
248 return input; 248 return input;
249 res = {}; 249 res = {};
250 for (key in input) { 250 for (key in input) {
251 val = input[key]; 251 val = input[key];
252 res[key] = Math.round(val.getTime() / 1000) * 1000; 252 res[key] = val.getTime();
253 } 253 }
254 return res; 254 return res;
255 }; 255 };
256 return expect(withDatesToTime(YAML.parse("date: 1976-07-31"))).toEqual(withDatesToTime({ 256 return expect(withDatesToTime(YAML.parse("date: 1976-07-31"))).toEqual(withDatesToTime({
257 'date': aDate 257 'date': aDate
258 })); 258 }));
259 }); 259 });
260 }); 260 });
261   261  
262 describe('Parsed YAML Blocks', function() { 262 describe('Parsed YAML Blocks', function() {
263 it('can be single ending newline', function() { 263 it('can be single ending newline', function() {
264 return expect(YAML.parse("---\nthis: |\n Foo\n Bar")).toEqual({ 264 return expect(YAML.parse("---\nthis: |\n Foo\n Bar")).toEqual({
265 'this': "Foo\nBar\n" 265 'this': "Foo\nBar\n"
266 }); 266 });
267 }); 267 });
268 it('can be single ending newline with \'+\' indicator', function() { 268 it('can be single ending newline with \'+\' indicator', function() {
269 return expect(YAML.parse("normal: |\n extra new lines not kept\n\npreserving: |+\n extra new lines are kept\n\n\ndummy: value")).toEqual({ 269 return expect(YAML.parse("normal: |\n extra new lines not kept\n\npreserving: |+\n extra new lines are kept\n\n\ndummy: value")).toEqual({
270 'normal': "extra new lines not kept\n", 270 'normal': "extra new lines not kept\n",
271 'preserving': "extra new lines are kept\n\n\n", 271 'preserving': "extra new lines are kept\n\n\n",
272 'dummy': 'value' 272 'dummy': 'value'
273 }); 273 });
274 }); 274 });
275 it('can be multi-line block handling trailing newlines in function of \'+\', \'-\' indicators', function() { 275 it('can be multi-line block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
276 return expect(YAML.parse("clipped: |\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: |-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: |+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual({ 276 return expect(YAML.parse("clipped: |\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: |-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: |+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual({
277 'clipped': "This has one newline.\n", 277 'clipped': "This has one newline.\n",
278 'same as "clipped" above': "This has one newline.\n", 278 'same as "clipped" above': "This has one newline.\n",
279 'stripped': 'This has no newline.', 279 'stripped': 'This has no newline.',
280 'same as "stripped" above': 'This has no newline.', 280 'same as "stripped" above': 'This has no newline.',
281 'kept': "This has four newlines.\n\n\n\n", 281 'kept': "This has four newlines.\n\n\n\n",
282 'same as "kept" above': "This has four newlines.\n\n\n\n" 282 'same as "kept" above': "This has four newlines.\n\n\n\n"
283 }); 283 });
284 }); 284 });
285 it('can be folded block in a sequence', function() { 285 it('can be folded block in a sequence', function() {
286 return expect(YAML.parse("---\n- apple\n- banana\n- >\n can't you see\n the beauty of yaml?\n hmm\n- dog")).toEqual(['apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog']); 286 return expect(YAML.parse("---\n- apple\n- banana\n- >\n can't you see\n the beauty of yaml?\n hmm\n- dog")).toEqual(['apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog']);
287 }); 287 });
288 it('can be folded block as a mapping value', function() { 288 it('can be folded block as a mapping value', function() {
289 return expect(YAML.parse("---\nquote: >\n Mark McGwire's\n year was crippled\n by a knee injury.\nsource: espn")).toEqual({ 289 return expect(YAML.parse("---\nquote: >\n Mark McGwire's\n year was crippled\n by a knee injury.\nsource: espn")).toEqual({
290 'quote': "Mark McGwire's year was crippled by a knee injury.\n", 290 'quote': "Mark McGwire's year was crippled by a knee injury.\n",
291 'source': 'espn' 291 'source': 'espn'
292 }); 292 });
293 }); 293 });
294 it('can be folded block handling trailing newlines in function of \'+\', \'-\' indicators', function() { 294 it('can be folded block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
295 return expect(YAML.parse("clipped: >\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: >-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: >+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual({ 295 return expect(YAML.parse("clipped: >\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: >-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: >+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual({
296 'clipped': "This has one newline.\n", 296 'clipped': "This has one newline.\n",
297 'same as "clipped" above': "This has one newline.\n", 297 'same as "clipped" above': "This has one newline.\n",
298 'stripped': 'This has no newline.', 298 'stripped': 'This has no newline.',
299 'same as "stripped" above': 'This has no newline.', 299 'same as "stripped" above': 'This has no newline.',
300 'kept': "This has four newlines.\n\n\n\n", 300 'kept': "This has four newlines.\n\n\n\n",
301 'same as "kept" above': "This has four newlines.\n\n\n\n" 301 'same as "kept" above': "This has four newlines.\n\n\n\n"
302 }); 302 });
303 }); 303 });
304 return it('can be the whole document as intented block', function() { 304 return it('can be the whole document as intented block', function() {
305 return expect(YAML.parse("---\n foo: \"bar\"\n baz:\n - \"qux\"\n - \"quxx\"\n corge: null")).toEqual({ 305 return expect(YAML.parse("---\n foo: \"bar\"\n baz:\n - \"qux\"\n - \"quxx\"\n corge: null")).toEqual({
306 'foo': "bar", 306 'foo': "bar",
307 'baz': ['qux', 'quxx'], 307 'baz': ['qux', 'quxx'],
308 'corge': null 308 'corge': null
309 }); 309 });
310 }); 310 });
311 }); 311 });
312   312  
313 describe('Parsed YAML Comments', function() { 313 describe('Parsed YAML Comments', function() {
314 it('can begin the document', function() { 314 it('can begin the document', function() {
315 return expect(YAML.parse("# This is a comment\nhello: world")).toEqual({ 315 return expect(YAML.parse("# This is a comment\nhello: world")).toEqual({
316 hello: 'world' 316 hello: 'world'
317 }); 317 });
318 }); 318 });
319 it('can be less indented in mapping', function() { 319 it('can be less indented in mapping', function() {
320 return expect(YAML.parse("parts:\n a: 'b'\n # normally indented comment\n c: 'd'\n# less indented comment\n e: 'f'")).toEqual({ 320 return expect(YAML.parse("parts:\n a: 'b'\n # normally indented comment\n c: 'd'\n# less indented comment\n e: 'f'")).toEqual({
321 parts: { 321 parts: {
322 a: 'b', 322 a: 'b',
323 c: 'd', 323 c: 'd',
324 e: 'f' 324 e: 'f'
325 } 325 }
326 }); 326 });
327 }); 327 });
328 it('can be less indented in sequence', function() { 328 it('can be less indented in sequence', function() {
329 return expect(YAML.parse("list-header:\n - item1\n# - item2\n - item3\n # - item4")).toEqual({ 329 return expect(YAML.parse("list-header:\n - item1\n# - item2\n - item3\n # - item4")).toEqual({
330 'list-header': ['item1', 'item3'] 330 'list-header': ['item1', 'item3']
331 }); 331 });
332 }); 332 });
333 it('can finish a line', function() { 333 it('can finish a line', function() {
334 return expect(YAML.parse("hello: world # This is a comment")).toEqual({ 334 return expect(YAML.parse("hello: world # This is a comment")).toEqual({
335 hello: 'world' 335 hello: 'world'
336 }); 336 });
337 }); 337 });
338 return it('can end the document', function() { 338 return it('can end the document', function() {
339 return expect(YAML.parse("hello: world\n# This is a comment")).toEqual({ 339 return expect(YAML.parse("hello: world\n# This is a comment")).toEqual({
340 hello: 'world' 340 hello: 'world'
341 }); 341 });
342 }); 342 });
343 }); 343 });
344   344  
345 describe('Parsed YAML Aliases and Anchors', function() { 345 describe('Parsed YAML Aliases and Anchors', function() {
346 it('can be simple alias', function() { 346 it('can be simple alias', function() {
347 return expect(YAML.parse("- &showell Steve\n- Clark\n- Brian\n- Oren\n- *showell")).toEqual(['Steve', 'Clark', 'Brian', 'Oren', 'Steve']); 347 return expect(YAML.parse("- &showell Steve\n- Clark\n- Brian\n- Oren\n- *showell")).toEqual(['Steve', 'Clark', 'Brian', 'Oren', 'Steve']);
348 }); 348 });
349 return it('can be alias of a mapping', function() { 349 return it('can be alias of a mapping', function() {
350 return expect(YAML.parse("- &hello\n Meat: pork\n Starch: potato\n- banana\n- *hello")).toEqual([ 350 return expect(YAML.parse("- &hello\n Meat: pork\n Starch: potato\n- banana\n- *hello")).toEqual([
351 { 351 {
352 Meat: 'pork', 352 Meat: 'pork',
353 Starch: 'potato' 353 Starch: 'potato'
354 }, 'banana', { 354 }, 'banana', {
355 Meat: 'pork', 355 Meat: 'pork',
356 Starch: 'potato' 356 Starch: 'potato'
357 } 357 }
358 ]); 358 ]);
359 }); 359 });
360 }); 360 });
361   361  
362 describe('Parsed YAML Documents', function() { 362 describe('Parsed YAML Documents', function() {
363 it('can have YAML header', function() { 363 it('can have YAML header', function() {
364 return expect(YAML.parse("--- %YAML:1.0\nfoo: 1\nbar: 2")).toEqual({ 364 return expect(YAML.parse("--- %YAML:1.0\nfoo: 1\nbar: 2")).toEqual({
365 foo: 1, 365 foo: 1,
366 bar: 2 366 bar: 2
367 }); 367 });
368 }); 368 });
369 it('can have leading document separator', function() { 369 it('can have leading document separator', function() {
370 return expect(YAML.parse("---\n- foo: 1\n bar: 2")).toEqual([ 370 return expect(YAML.parse("---\n- foo: 1\n bar: 2")).toEqual([
371 { 371 {
372 foo: 1, 372 foo: 1,
373 bar: 2 373 bar: 2
374 } 374 }
375 ]); 375 ]);
376 }); 376 });
377 return it('can have multiple document separators in block', function() { 377 return it('can have multiple document separators in block', function() {
378 return expect(YAML.parse("foo: |\n ---\n foo: bar\n ---\n yo: baz\nbar: |\n fooness")).toEqual({ 378 return expect(YAML.parse("foo: |\n ---\n foo: bar\n ---\n yo: baz\nbar: |\n fooness")).toEqual({
379 foo: "---\nfoo: bar\n---\nyo: baz\n", 379 foo: "---\nfoo: bar\n---\nyo: baz\n",
380 bar: "fooness\n" 380 bar: "fooness\n"
381 }); 381 });
382 }); 382 });
383 }); 383 });
384   384  
385 describe('Dumped YAML Collections', function() { 385 describe('Dumped YAML Collections', function() {
386 it('can be simple sequence', function() { 386 it('can be simple sequence', function() {
387 return expect(YAML.parse("- apple\n- banana\n- carrot")).toEqual(YAML.parse(YAML.dump(['apple', 'banana', 'carrot']))); 387 return expect(YAML.parse("- apple\n- banana\n- carrot")).toEqual(YAML.parse(YAML.dump(['apple', 'banana', 'carrot'])));
388 }); 388 });
389 it('can be nested sequences', function() { 389 it('can be nested sequences', function() {
390 return expect(YAML.parse("-\n - foo\n - bar\n - baz")).toEqual(YAML.parse(YAML.dump([['foo', 'bar', 'baz']]))); 390 return expect(YAML.parse("-\n - foo\n - bar\n - baz")).toEqual(YAML.parse(YAML.dump([['foo', 'bar', 'baz']])));
391 }); 391 });
392 it('can be mixed sequences', function() { 392 it('can be mixed sequences', function() {
393 return expect(YAML.parse("- apple\n-\n - foo\n - bar\n - x123\n- banana\n- carrot")).toEqual(YAML.parse(YAML.dump(['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot']))); 393 return expect(YAML.parse("- apple\n-\n - foo\n - bar\n - x123\n- banana\n- carrot")).toEqual(YAML.parse(YAML.dump(['apple', ['foo', 'bar', 'x123'], 'banana', 'carrot'])));
394 }); 394 });
395 it('can be deeply nested sequences', function() { 395 it('can be deeply nested sequences', function() {
396 return expect(YAML.parse("-\n -\n - uno\n - dos")).toEqual(YAML.parse(YAML.dump([[['uno', 'dos']]]))); 396 return expect(YAML.parse("-\n -\n - uno\n - dos")).toEqual(YAML.parse(YAML.dump([[['uno', 'dos']]])));
397 }); 397 });
398 it('can be simple mapping', function() { 398 it('can be simple mapping', function() {
399 return expect(YAML.parse("foo: whatever\nbar: stuff")).toEqual(YAML.parse(YAML.dump({ 399 return expect(YAML.parse("foo: whatever\nbar: stuff")).toEqual(YAML.parse(YAML.dump({
400 foo: 'whatever', 400 foo: 'whatever',
401 bar: 'stuff' 401 bar: 'stuff'
402 }))); 402 })));
403 }); 403 });
404 it('can be sequence in a mapping', function() { 404 it('can be sequence in a mapping', function() {
405 return expect(YAML.parse("foo: whatever\nbar:\n - uno\n - dos")).toEqual(YAML.parse(YAML.dump({ 405 return expect(YAML.parse("foo: whatever\nbar:\n - uno\n - dos")).toEqual(YAML.parse(YAML.dump({
406 foo: 'whatever', 406 foo: 'whatever',
407 bar: ['uno', 'dos'] 407 bar: ['uno', 'dos']
408 }))); 408 })));
409 }); 409 });
410 it('can be nested mappings', function() { 410 it('can be nested mappings', function() {
411 return expect(YAML.parse("foo: whatever\nbar:\n fruit: apple\n name: steve\n sport: baseball")).toEqual(YAML.parse(YAML.dump({ 411 return expect(YAML.parse("foo: whatever\nbar:\n fruit: apple\n name: steve\n sport: baseball")).toEqual(YAML.parse(YAML.dump({
412 foo: 'whatever', 412 foo: 'whatever',
413 bar: { 413 bar: {
414 fruit: 'apple', 414 fruit: 'apple',
415 name: 'steve', 415 name: 'steve',
416 sport: 'baseball' 416 sport: 'baseball'
417 } 417 }
418 }))); 418 })));
419 }); 419 });
420 it('can be mixed mapping', function() { 420 it('can be mixed mapping', function() {
421 return expect(YAML.parse("foo: whatever\nbar:\n -\n fruit: apple\n name: steve\n sport: baseball\n - more\n -\n python: rocks\n perl: papers\n ruby: scissorses")).toEqual(YAML.parse(YAML.dump({ 421 return expect(YAML.parse("foo: whatever\nbar:\n -\n fruit: apple\n name: steve\n sport: baseball\n - more\n -\n python: rocks\n perl: papers\n ruby: scissorses")).toEqual(YAML.parse(YAML.dump({
422 foo: 'whatever', 422 foo: 'whatever',
423 bar: [ 423 bar: [
424 { 424 {
425 fruit: 'apple', 425 fruit: 'apple',
426 name: 'steve', 426 name: 'steve',
427 sport: 'baseball' 427 sport: 'baseball'
428 }, 'more', { 428 }, 'more', {
429 python: 'rocks', 429 python: 'rocks',
430 perl: 'papers', 430 perl: 'papers',
431 ruby: 'scissorses' 431 ruby: 'scissorses'
432 } 432 }
433 ] 433 ]
434 }))); 434 })));
435 }); 435 });
436 it('can have mapping-in-sequence shortcut', function() { 436 it('can have mapping-in-sequence shortcut', function() {
437 return expect(YAML.parse("- work on YAML.py:\n - work on Store")).toEqual(YAML.parse(YAML.dump([ 437 return expect(YAML.parse("- work on YAML.py:\n - work on Store")).toEqual(YAML.parse(YAML.dump([
438 { 438 {
439 'work on YAML.py': ['work on Store'] 439 'work on YAML.py': ['work on Store']
440 } 440 }
441 ]))); 441 ])));
442 }); 442 });
443 it('can have unindented sequence-in-mapping shortcut', function() { 443 it('can have unindented sequence-in-mapping shortcut', function() {
444 return expect(YAML.parse("allow:\n- 'localhost'\n- '%.sourceforge.net'\n- '%.freepan.org'")).toEqual(YAML.parse(YAML.dump({ 444 return expect(YAML.parse("allow:\n- 'localhost'\n- '%.sourceforge.net'\n- '%.freepan.org'")).toEqual(YAML.parse(YAML.dump({
445 allow: ['localhost', '%.sourceforge.net', '%.freepan.org'] 445 allow: ['localhost', '%.sourceforge.net', '%.freepan.org']
446 }))); 446 })));
447 }); 447 });
448 return it('can merge key', function() { 448 return it('can merge key', function() {
449 return expect(YAML.parse("mapping:\n name: Joe\n job: Accountant\n <<:\n age: 38")).toEqual(YAML.parse(YAML.dump({ 449 return expect(YAML.parse("mapping:\n name: Joe\n job: Accountant\n <<:\n age: 38")).toEqual(YAML.parse(YAML.dump({
450 mapping: { 450 mapping: {
451 name: 'Joe', 451 name: 'Joe',
452 job: 'Accountant', 452 job: 'Accountant',
453 age: 38 453 age: 38
454 } 454 }
455 }))); 455 })));
456 }); 456 });
457 }); 457 });
458   458  
459 describe('Dumped YAML Inline Collections', function() { 459 describe('Dumped YAML Inline Collections', function() {
460 it('can be simple inline array', function() { 460 it('can be simple inline array', function() {
461 return expect(YAML.parse("---\nseq: [ a, b, c ]")).toEqual(YAML.parse(YAML.dump({ 461 return expect(YAML.parse("---\nseq: [ a, b, c ]")).toEqual(YAML.parse(YAML.dump({
462 seq: ['a', 'b', 'c'] 462 seq: ['a', 'b', 'c']
463 }))); 463 })));
464 }); 464 });
465 it('can be simple inline hash', function() { 465 it('can be simple inline hash', function() {
466 return expect(YAML.parse("---\nhash: { name: Steve, foo: bar }")).toEqual(YAML.parse(YAML.dump({ 466 return expect(YAML.parse("---\nhash: { name: Steve, foo: bar }")).toEqual(YAML.parse(YAML.dump({
467 hash: { 467 hash: {
468 name: 'Steve', 468 name: 'Steve',
469 foo: 'bar' 469 foo: 'bar'
470 } 470 }
471 }))); 471 })));
472 }); 472 });
473 it('can be multi-line inline collections', function() { 473 it('can be multi-line inline collections', function() {
474 return expect(YAML.parse("languages: [ Ruby,\n Perl,\n Python ]\nwebsites: { YAML: yaml.org,\n Ruby: ruby-lang.org,\n Python: python.org,\n Perl: use.perl.org }")).toEqual(YAML.parse(YAML.dump({ 474 return expect(YAML.parse("languages: [ Ruby,\n Perl,\n Python ]\nwebsites: { YAML: yaml.org,\n Ruby: ruby-lang.org,\n Python: python.org,\n Perl: use.perl.org }")).toEqual(YAML.parse(YAML.dump({
475 languages: ['Ruby', 'Perl', 'Python'], 475 languages: ['Ruby', 'Perl', 'Python'],
476 websites: { 476 websites: {
477 YAML: 'yaml.org', 477 YAML: 'yaml.org',
478 Ruby: 'ruby-lang.org', 478 Ruby: 'ruby-lang.org',
479 Python: 'python.org', 479 Python: 'python.org',
480 Perl: 'use.perl.org' 480 Perl: 'use.perl.org'
481 } 481 }
482 }))); 482 })));
483 }); 483 });
484 return it('can be dumped empty sequences in mappings', function() { 484 it('can be dumped empty sequences in mappings', function() {
485 return expect(YAML.parse(YAML.dump({ 485 return expect(YAML.parse(YAML.dump({
486 key: [] 486 key: []
487 }))).toEqual({ 487 }))).toEqual({
488 key: [] 488 key: []
489 }); 489 });
490 }); 490 });
-   491 return it('can be dumpted empty inline collections', function() {
-   492 return expect(YAML.parse(YAML.dump({
-   493 key: {}
-   494 }))).toEqual({
-   495 key: {}
-   496 });
-   497 });
491 }); 498 });
492   499  
493 describe('Dumped YAML Basic Types', function() { 500 describe('Dumped YAML Basic Types', function() {
494 it('can be strings', function() { 501 it('can be strings', function() {
495 return expect(YAML.parse("---\nString")).toEqual(YAML.parse(YAML.dump('String'))); 502 return expect(YAML.parse("---\nString")).toEqual(YAML.parse(YAML.dump('String')));
496 }); 503 });
497 it('can be double-quoted strings with backslashes', function() { 504 it('can be double-quoted strings with backslashes', function() {
498 return expect(YAML.parse("str:\n \"string with \\\\ inside\"")).toEqual(YAML.parse(YAML.dump({ 505 return expect(YAML.parse("str:\n \"string with \\\\ inside\"")).toEqual(YAML.parse(YAML.dump({
499 str: 'string with \\ inside' 506 str: 'string with \\ inside'
500 }))); 507 })));
501 }); 508 });
502 it('can be single-quoted strings with backslashes', function() { 509 it('can be single-quoted strings with backslashes', function() {
503 return expect(YAML.parse("str:\n 'string with \\\\ inside'")).toEqual(YAML.parse(YAML.dump({ 510 return expect(YAML.parse("str:\n 'string with \\\\ inside'")).toEqual(YAML.parse(YAML.dump({
504 str: 'string with \\\\ inside' 511 str: 'string with \\\\ inside'
505 }))); 512 })));
506 }); 513 });
507 it('can be double-quoted strings with line breaks', function() { 514 it('can be double-quoted strings with line breaks', function() {
508 return expect(YAML.parse("str:\n \"string with \\n inside\"")).toEqual(YAML.parse(YAML.dump({ 515 return expect(YAML.parse("str:\n \"string with \\n inside\"")).toEqual(YAML.parse(YAML.dump({
509 str: 'string with \n inside' 516 str: 'string with \n inside'
510 }))); 517 })));
511 }); 518 });
512 it('can be double-quoted strings with line breaks and backslashes', function() { 519 it('can be double-quoted strings with line breaks and backslashes', function() {
513 return expect(YAML.parse("str:\n \"string with \\n inside and \\\\ also\"")).toEqual(YAML.parse(YAML.dump({ 520 return expect(YAML.parse("str:\n \"string with \\n inside and \\\\ also\"")).toEqual(YAML.parse(YAML.dump({
514 str: 'string with \n inside and \\ also' 521 str: 'string with \n inside and \\ also'
515 }))); 522 })));
516 }); 523 });
517 it('can be single-quoted strings with line breaks and backslashes', function() { 524 it('can be single-quoted strings with line breaks and backslashes', function() {
518 return expect(YAML.parse("str:\n 'string with \\n inside and \\\\ also'")).toEqual(YAML.parse(YAML.dump({ 525 return expect(YAML.parse("str:\n 'string with \\n inside and \\\\ also'")).toEqual(YAML.parse(YAML.dump({
519 str: 'string with \\n inside and \\\\ also' 526 str: 'string with \\n inside and \\\\ also'
520 }))); 527 })));
521 }); 528 });
522 it('can be single-quoted strings with escaped line breaks', function() { 529 it('can be single-quoted strings with escaped line breaks', function() {
523 return expect(YAML.parse("str:\n 'string with \\n inside'")).toEqual(YAML.parse(YAML.dump({ 530 return expect(YAML.parse("str:\n 'string with \\n inside'")).toEqual(YAML.parse(YAML.dump({
524 str: 'string with \\n inside' 531 str: 'string with \\n inside'
525 }))); 532 })));
526 }); 533 });
527 it('can have string characters in sequences', function() { 534 it('can have string characters in sequences', function() {
528 return expect(YAML.parse("- What's Yaml?\n- It's for writing data structures in plain text.\n- And?\n- And what? That's not good enough for you?\n- No, I mean, \"And what about Yaml?\"\n- Oh, oh yeah. Uh.. Yaml for JavaScript.")).toEqual(YAML.parse(YAML.dump(["What's Yaml?", "It's for writing data structures in plain text.", "And?", "And what? That's not good enough for you?", "No, I mean, \"And what about Yaml?\"", "Oh, oh yeah. Uh.. Yaml for JavaScript."]))); 535 return expect(YAML.parse("- What's Yaml?\n- It's for writing data structures in plain text.\n- And?\n- And what? That's not good enough for you?\n- No, I mean, \"And what about Yaml?\"\n- Oh, oh yeah. Uh.. Yaml for JavaScript.")).toEqual(YAML.parse(YAML.dump(["What's Yaml?", "It's for writing data structures in plain text.", "And?", "And what? That's not good enough for you?", "No, I mean, \"And what about Yaml?\"", "Oh, oh yeah. Uh.. Yaml for JavaScript."])));
529 }); 536 });
530 it('can have indicators in strings', function() { 537 it('can have indicators in strings', function() {
531 return expect(YAML.parse("the colon followed by space is an indicator: but is a string:right here\nsame for the pound sign: here we have it#in a string\nthe comma can, honestly, be used in most cases: [ but not in, inline collections ]")).toEqual(YAML.parse(YAML.dump({ 538 return expect(YAML.parse("the colon followed by space is an indicator: but is a string:right here\nsame for the pound sign: here we have it#in a string\nthe comma can, honestly, be used in most cases: [ but not in, inline collections ]")).toEqual(YAML.parse(YAML.dump({
532 'the colon followed by space is an indicator': 'but is a string:right here', 539 'the colon followed by space is an indicator': 'but is a string:right here',
533 'same for the pound sign': 'here we have it#in a string', 540 'same for the pound sign': 'here we have it#in a string',
534 'the comma can, honestly, be used in most cases': ['but not in', 'inline collections'] 541 'the comma can, honestly, be used in most cases': ['but not in', 'inline collections']
535 }))); 542 })));
536 }); 543 });
537 it('can force strings', function() { 544 it('can force strings', function() {
538 return expect(YAML.parse("date string: !str 2001-08-01\nnumber string: !str 192\ndate string 2: !!str 2001-08-01\nnumber string 2: !!str 192")).toEqual(YAML.parse(YAML.dump({ 545 return expect(YAML.parse("date string: !str 2001-08-01\nnumber string: !str 192\ndate string 2: !!str 2001-08-01\nnumber string 2: !!str 192")).toEqual(YAML.parse(YAML.dump({
539 'date string': '2001-08-01', 546 'date string': '2001-08-01',
540 'number string': '192', 547 'number string': '192',
541 'date string 2': '2001-08-01', 548 'date string 2': '2001-08-01',
542 'number string 2': '192' 549 'number string 2': '192'
543 }))); 550 })));
544 }); 551 });
545 it('can be single-quoted strings', function() { 552 it('can be single-quoted strings', function() {
546 return expect(YAML.parse("all my favorite symbols: '#:!/%.)'\na few i hate: '&(*'\nwhy do i hate them?: 'it''s very hard to explain'")).toEqual(YAML.parse(YAML.dump({ 553 return expect(YAML.parse("all my favorite symbols: '#:!/%.)'\na few i hate: '&(*'\nwhy do i hate them?: 'it''s very hard to explain'")).toEqual(YAML.parse(YAML.dump({
547 'all my favorite symbols': '#:!/%.)', 554 'all my favorite symbols': '#:!/%.)',
548 'a few i hate': '&(*', 555 'a few i hate': '&(*',
549 'why do i hate them?': 'it\'s very hard to explain' 556 'why do i hate them?': 'it\'s very hard to explain'
550 }))); 557 })));
551 }); 558 });
552 it('can be double-quoted strings', function() { 559 it('can be double-quoted strings', function() {
553 return expect(YAML.parse("i know where i want my line breaks: \"one here\\nand another here\\n\"")).toEqual(YAML.parse(YAML.dump({ 560 return expect(YAML.parse("i know where i want my line breaks: \"one here\\nand another here\\n\"")).toEqual(YAML.parse(YAML.dump({
554 'i know where i want my line breaks': "one here\nand another here\n" 561 'i know where i want my line breaks': "one here\nand another here\n"
555 }))); 562 })));
556 }); 563 });
557 it('can be null', function() { 564 it('can be null', function() {
558 return expect(YAML.parse("name: Mr. Show\nhosted by: Bob and David\ndate of next season: ~")).toEqual(YAML.parse(YAML.dump({ 565 return expect(YAML.parse("name: Mr. Show\nhosted by: Bob and David\ndate of next season: ~")).toEqual(YAML.parse(YAML.dump({
559 'name': 'Mr. Show', 566 'name': 'Mr. Show',
560 'hosted by': 'Bob and David', 567 'hosted by': 'Bob and David',
561 'date of next season': null 568 'date of next season': null
562 }))); 569 })));
563 }); 570 });
564 it('can be boolean', function() { 571 it('can be boolean', function() {
565 return expect(YAML.parse("Is Gus a Liar?: true\nDo I rely on Gus for Sustenance?: false")).toEqual(YAML.parse(YAML.dump({ 572 return expect(YAML.parse("Is Gus a Liar?: true\nDo I rely on Gus for Sustenance?: false")).toEqual(YAML.parse(YAML.dump({
566 'Is Gus a Liar?': true, 573 'Is Gus a Liar?': true,
567 'Do I rely on Gus for Sustenance?': false 574 'Do I rely on Gus for Sustenance?': false
568 }))); 575 })));
569 }); 576 });
570 it('can be integers', function() { 577 it('can be integers', function() {
571 return expect(YAML.parse("zero: 0\nsimple: 12\none-thousand: 1,000\nnegative one-thousand: -1,000")).toEqual(YAML.parse(YAML.dump({ 578 return expect(YAML.parse("zero: 0\nsimple: 12\none-thousand: 1,000\nnegative one-thousand: -1,000")).toEqual(YAML.parse(YAML.dump({
572 'zero': 0, 579 'zero': 0,
573 'simple': 12, 580 'simple': 12,
574 'one-thousand': 1000, 581 'one-thousand': 1000,
575 'negative one-thousand': -1000 582 'negative one-thousand': -1000
576 }))); 583 })));
577 }); 584 });
578 it('can be integers as map keys', function() { 585 it('can be integers as map keys', function() {
579 return expect(YAML.parse("1: one\n2: two\n3: three")).toEqual(YAML.parse(YAML.dump({ 586 return expect(YAML.parse("1: one\n2: two\n3: three")).toEqual(YAML.parse(YAML.dump({
580 1: 'one', 587 1: 'one',
581 2: 'two', 588 2: 'two',
582 3: 'three' 589 3: 'three'
583 }))); 590 })));
584 }); 591 });
585 it('can be floats', function() { 592 it('can be floats', function() {
586 return expect(YAML.parse("a simple float: 2.00\nlarger float: 1,000.09\nscientific notation: 1.00009e+3")).toEqual(YAML.parse(YAML.dump({ 593 return expect(YAML.parse("a simple float: 2.00\nlarger float: 1,000.09\nscientific notation: 1.00009e+3")).toEqual(YAML.parse(YAML.dump({
587 'a simple float': 2.0, 594 'a simple float': 2.0,
588 'larger float': 1000.09, 595 'larger float': 1000.09,
589 'scientific notation': 1000.09 596 'scientific notation': 1000.09
590 }))); 597 })));
591 }); 598 });
592 it('can be time', function() { 599 it('can be time', function() {
593 var iso8601Date, spaceSeparatedDate, withDatesToTime; 600 var iso8601Date, spaceSeparatedDate, withDatesToTime;
594 iso8601Date = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10)); 601 iso8601Date = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
595 iso8601Date.setTime(iso8601Date.getTime() - 5 * 3600 * 1000); 602 iso8601Date.setTime(iso8601Date.getTime() + 5 * 3600 * 1000);
596 spaceSeparatedDate = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10)); 603 spaceSeparatedDate = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
597 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() - 5 * 3600 * 1000); 604 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() - 5 * 3600 * 1000);
598 withDatesToTime = function(input) { 605 withDatesToTime = function(input) {
599 var key, res, val; 606 var key, res, val;
600 res = {}; 607 res = {};
601 for (key in input) { 608 for (key in input) {
602 val = input[key]; 609 val = input[key];
603 res[key] = Math.round(val.getTime() / 1000) * 1000; 610 res[key] = val.getTime();
604 } 611 }
605 return res; 612 return res;
606 }; 613 };
607 return expect(withDatesToTime(YAML.parse("iso8601: 2001-12-14t21:59:43.10-05:00\nspace seperated: 2001-12-14 21:59:43.10 -05:00"))).toEqual(YAML.parse(YAML.dump(withDatesToTime({ 614 return expect(withDatesToTime(YAML.parse("iso8601: 2001-12-14t21:59:43.010-05:00\nspace separated: 2001-12-14 21:59:43.010 +05:00"))).toEqual(YAML.parse(YAML.dump(withDatesToTime({
608 'iso8601': iso8601Date, 615 'iso8601': iso8601Date,
609 'space seperated': spaceSeparatedDate 616 'space separated': spaceSeparatedDate
610 })))); 617 }))));
611 }); 618 });
612 return it('can be date', function() { 619 return it('can be date', function() {
613 var aDate, withDatesToTime; 620 var aDate, withDatesToTime;
614 aDate = new Date(Date.UTC(1976, 7 - 1, 31, 0, 0, 0, 0)); 621 aDate = new Date(Date.UTC(1976, 7 - 1, 31, 0, 0, 0, 0));
615 withDatesToTime = function(input) { 622 withDatesToTime = function(input) {
616 var key, res, val; 623 var key, res, val;
617 return input; 624 return input;
618 res = {}; 625 res = {};
619 for (key in input) { 626 for (key in input) {
620 val = input[key]; 627 val = input[key];
621 res[key] = Math.round(val.getTime() / 1000) * 1000; 628 res[key] = val.getTime();
622 } 629 }
623 return res; 630 return res;
624 }; 631 };
625 return expect(withDatesToTime(YAML.parse("date: 1976-07-31"))).toEqual(YAML.parse(YAML.dump(withDatesToTime({ 632 return expect(withDatesToTime(YAML.parse("date: 1976-07-31"))).toEqual(YAML.parse(YAML.dump(withDatesToTime({
626 'date': aDate 633 'date': aDate
627 })))); 634 }))));
628 }); 635 });
629 }); 636 });
630   637  
631 describe('Dumped YAML Blocks', function() { 638 describe('Dumped YAML Blocks', function() {
632 it('can be single ending newline', function() { 639 it('can be single ending newline', function() {
633 return expect(YAML.parse("---\nthis: |\n Foo\n Bar")).toEqual(YAML.parse(YAML.dump({ 640 return expect(YAML.parse("---\nthis: |\n Foo\n Bar")).toEqual(YAML.parse(YAML.dump({
634 'this': "Foo\nBar\n" 641 'this': "Foo\nBar\n"
635 }))); 642 })));
636 }); 643 });
637 it('can be single ending newline with \'+\' indicator', function() { 644 it('can be single ending newline with \'+\' indicator', function() {
638 return expect(YAML.parse("normal: |\n extra new lines not kept\n\npreserving: |+\n extra new lines are kept\n\n\ndummy: value")).toEqual(YAML.parse(YAML.dump({ 645 return expect(YAML.parse("normal: |\n extra new lines not kept\n\npreserving: |+\n extra new lines are kept\n\n\ndummy: value")).toEqual(YAML.parse(YAML.dump({
639 'normal': "extra new lines not kept\n", 646 'normal': "extra new lines not kept\n",
640 'preserving': "extra new lines are kept\n\n\n", 647 'preserving': "extra new lines are kept\n\n\n",
641 'dummy': 'value' 648 'dummy': 'value'
642 }))); 649 })));
643 }); 650 });
644 it('can be multi-line block handling trailing newlines in function of \'+\', \'-\' indicators', function() { 651 it('can be multi-line block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
645 return expect(YAML.parse("clipped: |\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: |-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: |+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual(YAML.parse(YAML.dump({ 652 return expect(YAML.parse("clipped: |\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: |-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: |+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual(YAML.parse(YAML.dump({
646 'clipped': "This has one newline.\n", 653 'clipped': "This has one newline.\n",
647 'same as "clipped" above': "This has one newline.\n", 654 'same as "clipped" above': "This has one newline.\n",
648 'stripped': 'This has no newline.', 655 'stripped': 'This has no newline.',
649 'same as "stripped" above': 'This has no newline.', 656 'same as "stripped" above': 'This has no newline.',
650 'kept': "This has four newlines.\n\n\n\n", 657 'kept': "This has four newlines.\n\n\n\n",
651 'same as "kept" above': "This has four newlines.\n\n\n\n" 658 'same as "kept" above': "This has four newlines.\n\n\n\n"
652 }))); 659 })));
653 }); 660 });
654 it('can be folded block in a sequence', function() { 661 it('can be folded block in a sequence', function() {
655 return expect(YAML.parse("---\n- apple\n- banana\n- >\n can't you see\n the beauty of yaml?\n hmm\n- dog")).toEqual(YAML.parse(YAML.dump(['apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog']))); 662 return expect(YAML.parse("---\n- apple\n- banana\n- >\n can't you see\n the beauty of yaml?\n hmm\n- dog")).toEqual(YAML.parse(YAML.dump(['apple', 'banana', "can't you see the beauty of yaml? hmm\n", 'dog'])));
656 }); 663 });
657 it('can be folded block as a mapping value', function() { 664 it('can be folded block as a mapping value', function() {
658 return expect(YAML.parse("---\nquote: >\n Mark McGwire's\n year was crippled\n by a knee injury.\nsource: espn")).toEqual(YAML.parse(YAML.dump({ 665 return expect(YAML.parse("---\nquote: >\n Mark McGwire's\n year was crippled\n by a knee injury.\nsource: espn")).toEqual(YAML.parse(YAML.dump({
659 'quote': "Mark McGwire's year was crippled by a knee injury.\n", 666 'quote': "Mark McGwire's year was crippled by a knee injury.\n",
660 'source': 'espn' 667 'source': 'espn'
661 }))); 668 })));
662 }); 669 });
663 return it('can be folded block handling trailing newlines in function of \'+\', \'-\' indicators', function() { 670 return it('can be folded block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
664 return expect(YAML.parse("clipped: >\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: >-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: >+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual(YAML.parse(YAML.dump({ 671 return expect(YAML.parse("clipped: >\n This has one newline.\n\n\n\nsame as \"clipped\" above: \"This has one newline.\\n\"\n\nstripped: >-\n This has no newline.\n\n\n\nsame as \"stripped\" above: \"This has no newline.\"\n\nkept: >+\n This has four newlines.\n\n\n\nsame as \"kept\" above: \"This has four newlines.\\n\\n\\n\\n\"")).toEqual(YAML.parse(YAML.dump({
665 'clipped': "This has one newline.\n", 672 'clipped': "This has one newline.\n",
666 'same as "clipped" above': "This has one newline.\n", 673 'same as "clipped" above': "This has one newline.\n",
667 'stripped': 'This has no newline.', 674 'stripped': 'This has no newline.',
668 'same as "stripped" above': 'This has no newline.', 675 'same as "stripped" above': 'This has no newline.',
669 'kept': "This has four newlines.\n\n\n\n", 676 'kept': "This has four newlines.\n\n\n\n",
670 'same as "kept" above': "This has four newlines.\n\n\n\n" 677 'same as "kept" above': "This has four newlines.\n\n\n\n"
671 }))); 678 })));
672 }); 679 });
673 }); 680 });
674   681  
675 describe('Dumped YAML Comments', function() { 682 describe('Dumped YAML Comments', function() {
676 it('can begin the document', function() { 683 it('can begin the document', function() {
677 return expect(YAML.parse("# This is a comment\nhello: world")).toEqual(YAML.parse(YAML.dump({ 684 return expect(YAML.parse("# This is a comment\nhello: world")).toEqual(YAML.parse(YAML.dump({
678 hello: 'world' 685 hello: 'world'
679 }))); 686 })));
680 }); 687 });
681 it('can finish a line', function() { 688 it('can finish a line', function() {
682 return expect(YAML.parse("hello: world # This is a comment")).toEqual(YAML.parse(YAML.dump({ 689 return expect(YAML.parse("hello: world # This is a comment")).toEqual(YAML.parse(YAML.dump({
683 hello: 'world' 690 hello: 'world'
684 }))); 691 })));
685 }); 692 });
686 return it('can end the document', function() { 693 return it('can end the document', function() {
687 return expect(YAML.parse("hello: world\n# This is a comment")).toEqual(YAML.parse(YAML.dump({ 694 return expect(YAML.parse("hello: world\n# This is a comment")).toEqual(YAML.parse(YAML.dump({
688 hello: 'world' 695 hello: 'world'
689 }))); 696 })));
690 }); 697 });
691 }); 698 });
692   699  
693 describe('Dumped YAML Aliases and Anchors', function() { 700 describe('Dumped YAML Aliases and Anchors', function() {
694 it('can be simple alias', function() { 701 it('can be simple alias', function() {
695 return expect(YAML.parse("- &showell Steve\n- Clark\n- Brian\n- Oren\n- *showell")).toEqual(YAML.parse(YAML.dump(['Steve', 'Clark', 'Brian', 'Oren', 'Steve']))); 702 return expect(YAML.parse("- &showell Steve\n- Clark\n- Brian\n- Oren\n- *showell")).toEqual(YAML.parse(YAML.dump(['Steve', 'Clark', 'Brian', 'Oren', 'Steve'])));
696 }); 703 });
697 return it('can be alias of a mapping', function() { 704 return it('can be alias of a mapping', function() {
698 return expect(YAML.parse("- &hello\n Meat: pork\n Starch: potato\n- banana\n- *hello")).toEqual(YAML.parse(YAML.dump([ 705 return expect(YAML.parse("- &hello\n Meat: pork\n Starch: potato\n- banana\n- *hello")).toEqual(YAML.parse(YAML.dump([
699 { 706 {
700 Meat: 'pork', 707 Meat: 'pork',
701 Starch: 'potato' 708 Starch: 'potato'
702 }, 'banana', { 709 }, 'banana', {
703 Meat: 'pork', 710 Meat: 'pork',
704 Starch: 'potato' 711 Starch: 'potato'
705 } 712 }
706 ]))); 713 ])));
707 }); 714 });
708 }); 715 });
709   716  
710 describe('Dumped YAML Documents', function() { 717 describe('Dumped YAML Documents', function() {
711 it('can have YAML header', function() { 718 it('can have YAML header', function() {
712 return expect(YAML.parse("--- %YAML:1.0\nfoo: 1\nbar: 2")).toEqual(YAML.parse(YAML.dump({ 719 return expect(YAML.parse("--- %YAML:1.0\nfoo: 1\nbar: 2")).toEqual(YAML.parse(YAML.dump({
713 foo: 1, 720 foo: 1,
714 bar: 2 721 bar: 2
715 }))); 722 })));
716 }); 723 });
717 it('can have leading document separator', function() { 724 it('can have leading document separator', function() {
718 return expect(YAML.parse("---\n- foo: 1\n bar: 2")).toEqual(YAML.parse(YAML.dump([ 725 return expect(YAML.parse("---\n- foo: 1\n bar: 2")).toEqual(YAML.parse(YAML.dump([
719 { 726 {
720 foo: 1, 727 foo: 1,
721 bar: 2 728 bar: 2
722 } 729 }
723 ]))); 730 ])));
724 }); 731 });
725 return it('can have multiple document separators in block', function() { 732 return it('can have multiple document separators in block', function() {
726 return expect(YAML.parse("foo: |\n ---\n foo: bar\n ---\n yo: baz\nbar: |\n fooness")).toEqual(YAML.parse(YAML.dump({ 733 return expect(YAML.parse("foo: |\n ---\n foo: bar\n ---\n yo: baz\nbar: |\n fooness")).toEqual(YAML.parse(YAML.dump({
727 foo: "---\nfoo: bar\n---\nyo: baz\n", 734 foo: "---\nfoo: bar\n---\nyo: baz\n",
728 bar: "fooness\n" 735 bar: "fooness\n"
729 }))); 736 })));
730 }); 737 });
731 }); 738 });
732   739  
733 url = typeof document !== "undefined" && document !== null ? (ref = document.location) != null ? ref.href : void 0 : void 0; 740 url = typeof document !== "undefined" && document !== null ? (ref = document.location) != null ? ref.href : void 0 : void 0;
734   741  
735 if (!(url != null) || url.indexOf('file://') === -1) { 742 if (!(url != null) || url.indexOf('file://') === -1) {
736 examplePath = 'spec/example.yml'; 743 examplePath = 'spec/example.yml';
737 if (typeof __dirname !== "undefined" && __dirname !== null) { 744 if (typeof __dirname !== "undefined" && __dirname !== null) {
738 examplePath = __dirname + '/example.yml'; 745 examplePath = __dirname + '/example.yml';
739 } 746 }
740 describe('YAML loading', function() { 747 describe('YAML loading', function() {
741 it('can be done synchronously', function() { 748 it('can be done synchronously', function() {
742 return expect(YAML.load(examplePath)).toEqual({ 749 return expect(YAML.load(examplePath)).toEqual({
743 "this": 'is', 750 "this": 'is',
744 a: ['YAML', 'example'] 751 a: ['YAML', 'example']
745 }); 752 });
746 }); 753 });
747 return it('can be done asynchronously', function(done) { 754 return it('can be done asynchronously', function(done) {
748 return YAML.load(examplePath, function(result) { 755 return YAML.load(examplePath, function(result) {
749 expect(result).toEqual({ 756 expect(result).toEqual({
750 "this": 'is', 757 "this": 'is',
751 a: ['YAML', 'example'] 758 a: ['YAML', 'example']
752 }); 759 });
753 return done(); 760 return done();
754 }); 761 });
755 }); 762 });
756 }); 763 });
757 } 764 }
758   765