scratch – Blame information for rev 125

Subversion Repositories:
Rev:
Rev Author Line No. Line
125 office 1 // Generated by CoffeeScript 1.12.4
75 office 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));
125 office 228 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() + 5 * 3600 * 1000);
75 office 229 withDatesToTime = function(input) {
230 var key, res, val;
231 res = {};
232 for (key in input) {
233 val = input[key];
125 office 234 res[key] = val.getTime();
75 office 235 }
236 return res;
237 };
125 office 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({
75 office 239 'iso8601': iso8601Date,
125 office 240 'space separated': spaceSeparatedDate
75 office 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];
125 office 252 res[key] = val.getTime();
75 office 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 });
125 office 484 it('can be dumped empty sequences in mappings', function() {
75 office 485 return expect(YAML.parse(YAML.dump({
486 key: []
487 }))).toEqual({
488 key: []
489 });
490 });
125 office 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 });
75 office 498 });
499  
500 describe('Dumped YAML Basic Types', function() {
501 it('can be strings', function() {
502 return expect(YAML.parse("---\nString")).toEqual(YAML.parse(YAML.dump('String')));
503 });
504 it('can be double-quoted strings with backslashes', function() {
505 return expect(YAML.parse("str:\n \"string with \\\\ inside\"")).toEqual(YAML.parse(YAML.dump({
506 str: 'string with \\ inside'
507 })));
508 });
509 it('can be single-quoted strings with backslashes', function() {
510 return expect(YAML.parse("str:\n 'string with \\\\ inside'")).toEqual(YAML.parse(YAML.dump({
511 str: 'string with \\\\ inside'
512 })));
513 });
514 it('can be double-quoted strings with line breaks', function() {
515 return expect(YAML.parse("str:\n \"string with \\n inside\"")).toEqual(YAML.parse(YAML.dump({
516 str: 'string with \n inside'
517 })));
518 });
519 it('can be double-quoted strings with line breaks and backslashes', function() {
520 return expect(YAML.parse("str:\n \"string with \\n inside and \\\\ also\"")).toEqual(YAML.parse(YAML.dump({
521 str: 'string with \n inside and \\ also'
522 })));
523 });
524 it('can be single-quoted strings with line breaks and backslashes', function() {
525 return expect(YAML.parse("str:\n 'string with \\n inside and \\\\ also'")).toEqual(YAML.parse(YAML.dump({
526 str: 'string with \\n inside and \\\\ also'
527 })));
528 });
529 it('can be single-quoted strings with escaped line breaks', function() {
530 return expect(YAML.parse("str:\n 'string with \\n inside'")).toEqual(YAML.parse(YAML.dump({
531 str: 'string with \\n inside'
532 })));
533 });
534 it('can have string characters in sequences', function() {
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."])));
536 });
537 it('can have indicators in strings', function() {
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({
539 'the colon followed by space is an indicator': 'but is a string:right here',
540 'same for the pound sign': 'here we have it#in a string',
541 'the comma can, honestly, be used in most cases': ['but not in', 'inline collections']
542 })));
543 });
544 it('can force strings', function() {
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({
546 'date string': '2001-08-01',
547 'number string': '192',
548 'date string 2': '2001-08-01',
549 'number string 2': '192'
550 })));
551 });
552 it('can be single-quoted strings', function() {
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({
554 'all my favorite symbols': '#:!/%.)',
555 'a few i hate': '&(*',
556 'why do i hate them?': 'it\'s very hard to explain'
557 })));
558 });
559 it('can be double-quoted strings', function() {
560 return expect(YAML.parse("i know where i want my line breaks: \"one here\\nand another here\\n\"")).toEqual(YAML.parse(YAML.dump({
561 'i know where i want my line breaks': "one here\nand another here\n"
562 })));
563 });
564 it('can be null', function() {
565 return expect(YAML.parse("name: Mr. Show\nhosted by: Bob and David\ndate of next season: ~")).toEqual(YAML.parse(YAML.dump({
566 'name': 'Mr. Show',
567 'hosted by': 'Bob and David',
568 'date of next season': null
569 })));
570 });
571 it('can be boolean', function() {
572 return expect(YAML.parse("Is Gus a Liar?: true\nDo I rely on Gus for Sustenance?: false")).toEqual(YAML.parse(YAML.dump({
573 'Is Gus a Liar?': true,
574 'Do I rely on Gus for Sustenance?': false
575 })));
576 });
577 it('can be integers', function() {
578 return expect(YAML.parse("zero: 0\nsimple: 12\none-thousand: 1,000\nnegative one-thousand: -1,000")).toEqual(YAML.parse(YAML.dump({
579 'zero': 0,
580 'simple': 12,
581 'one-thousand': 1000,
582 'negative one-thousand': -1000
583 })));
584 });
585 it('can be integers as map keys', function() {
586 return expect(YAML.parse("1: one\n2: two\n3: three")).toEqual(YAML.parse(YAML.dump({
587 1: 'one',
588 2: 'two',
589 3: 'three'
590 })));
591 });
592 it('can be floats', function() {
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({
594 'a simple float': 2.0,
595 'larger float': 1000.09,
596 'scientific notation': 1000.09
597 })));
598 });
599 it('can be time', function() {
600 var iso8601Date, spaceSeparatedDate, withDatesToTime;
601 iso8601Date = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
125 office 602 iso8601Date.setTime(iso8601Date.getTime() + 5 * 3600 * 1000);
75 office 603 spaceSeparatedDate = new Date(Date.UTC(2001, 12 - 1, 14, 21, 59, 43, 10));
604 spaceSeparatedDate.setTime(spaceSeparatedDate.getTime() - 5 * 3600 * 1000);
605 withDatesToTime = function(input) {
606 var key, res, val;
607 res = {};
608 for (key in input) {
609 val = input[key];
125 office 610 res[key] = val.getTime();
75 office 611 }
612 return res;
613 };
125 office 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({
75 office 615 'iso8601': iso8601Date,
125 office 616 'space separated': spaceSeparatedDate
75 office 617 }))));
618 });
619 return it('can be date', function() {
620 var aDate, withDatesToTime;
621 aDate = new Date(Date.UTC(1976, 7 - 1, 31, 0, 0, 0, 0));
622 withDatesToTime = function(input) {
623 var key, res, val;
624 return input;
625 res = {};
626 for (key in input) {
627 val = input[key];
125 office 628 res[key] = val.getTime();
75 office 629 }
630 return res;
631 };
632 return expect(withDatesToTime(YAML.parse("date: 1976-07-31"))).toEqual(YAML.parse(YAML.dump(withDatesToTime({
633 'date': aDate
634 }))));
635 });
636 });
637  
638 describe('Dumped YAML Blocks', function() {
639 it('can be single ending newline', function() {
640 return expect(YAML.parse("---\nthis: |\n Foo\n Bar")).toEqual(YAML.parse(YAML.dump({
641 'this': "Foo\nBar\n"
642 })));
643 });
644 it('can be single ending newline with \'+\' indicator', function() {
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({
646 'normal': "extra new lines not kept\n",
647 'preserving': "extra new lines are kept\n\n\n",
648 'dummy': 'value'
649 })));
650 });
651 it('can be multi-line block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
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({
653 'clipped': "This has one newline.\n",
654 'same as "clipped" above': "This has one newline.\n",
655 'stripped': 'This has no newline.',
656 'same as "stripped" above': 'This has no newline.',
657 'kept': "This has four newlines.\n\n\n\n",
658 'same as "kept" above': "This has four newlines.\n\n\n\n"
659 })));
660 });
661 it('can be folded block in a sequence', function() {
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'])));
663 });
664 it('can be folded block as a mapping value', function() {
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({
666 'quote': "Mark McGwire's year was crippled by a knee injury.\n",
667 'source': 'espn'
668 })));
669 });
670 return it('can be folded block handling trailing newlines in function of \'+\', \'-\' indicators', function() {
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({
672 'clipped': "This has one newline.\n",
673 'same as "clipped" above': "This has one newline.\n",
674 'stripped': 'This has no newline.',
675 'same as "stripped" above': 'This has no newline.',
676 'kept': "This has four newlines.\n\n\n\n",
677 'same as "kept" above': "This has four newlines.\n\n\n\n"
678 })));
679 });
680 });
681  
682 describe('Dumped YAML Comments', function() {
683 it('can begin the document', function() {
684 return expect(YAML.parse("# This is a comment\nhello: world")).toEqual(YAML.parse(YAML.dump({
685 hello: 'world'
686 })));
687 });
688 it('can finish a line', function() {
689 return expect(YAML.parse("hello: world # This is a comment")).toEqual(YAML.parse(YAML.dump({
690 hello: 'world'
691 })));
692 });
693 return it('can end the document', function() {
694 return expect(YAML.parse("hello: world\n# This is a comment")).toEqual(YAML.parse(YAML.dump({
695 hello: 'world'
696 })));
697 });
698 });
699  
700 describe('Dumped YAML Aliases and Anchors', function() {
701 it('can be simple alias', function() {
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'])));
703 });
704 return it('can be alias of a mapping', function() {
705 return expect(YAML.parse("- &hello\n Meat: pork\n Starch: potato\n- banana\n- *hello")).toEqual(YAML.parse(YAML.dump([
706 {
707 Meat: 'pork',
708 Starch: 'potato'
709 }, 'banana', {
710 Meat: 'pork',
711 Starch: 'potato'
712 }
713 ])));
714 });
715 });
716  
717 describe('Dumped YAML Documents', function() {
718 it('can have YAML header', function() {
719 return expect(YAML.parse("--- %YAML:1.0\nfoo: 1\nbar: 2")).toEqual(YAML.parse(YAML.dump({
720 foo: 1,
721 bar: 2
722 })));
723 });
724 it('can have leading document separator', function() {
725 return expect(YAML.parse("---\n- foo: 1\n bar: 2")).toEqual(YAML.parse(YAML.dump([
726 {
727 foo: 1,
728 bar: 2
729 }
730 ])));
731 });
732 return it('can have multiple document separators in block', function() {
733 return expect(YAML.parse("foo: |\n ---\n foo: bar\n ---\n yo: baz\nbar: |\n fooness")).toEqual(YAML.parse(YAML.dump({
734 foo: "---\nfoo: bar\n---\nyo: baz\n",
735 bar: "fooness\n"
736 })));
737 });
738 });
739  
740 url = typeof document !== "undefined" && document !== null ? (ref = document.location) != null ? ref.href : void 0 : void 0;
741  
742 if (!(url != null) || url.indexOf('file://') === -1) {
743 examplePath = 'spec/example.yml';
744 if (typeof __dirname !== "undefined" && __dirname !== null) {
745 examplePath = __dirname + '/example.yml';
746 }
747 describe('YAML loading', function() {
748 it('can be done synchronously', function() {
749 return expect(YAML.load(examplePath)).toEqual({
750 "this": 'is',
751 a: ['YAML', 'example']
752 });
753 });
754 return it('can be done asynchronously', function(done) {
755 return YAML.load(examplePath, function(result) {
756 expect(result).toEqual({
757 "this": 'is',
758 a: ['YAML', 'example']
759 });
760 return done();
761 });
762 });
763 });
764 }