scratch – Blame information for rev 75

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