OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library utils_test; | 5 library utils_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'test_pub.dart'; | 8 import 'test_pub.dart'; |
9 import '../lib/src/utils.dart'; | 9 import '../lib/src/utils.dart'; |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 expect(yamlToString("apostrophe'"), equals('"apostrophe\'"')); | 36 expect(yamlToString("apostrophe'"), equals('"apostrophe\'"')); |
37 expect(yamlToString("new\nline"), equals(r'"new\nline"')); | 37 expect(yamlToString("new\nline"), equals(r'"new\nline"')); |
38 expect(yamlToString("?unctu@t!on"), equals(r'"?unctu@t!on"')); | 38 expect(yamlToString("?unctu@t!on"), equals(r'"?unctu@t!on"')); |
39 }); | 39 }); |
40 | 40 |
41 test('lists use JSON style', () { | 41 test('lists use JSON style', () { |
42 expect(yamlToString([1, 2, 3]), equals('[1,2,3]')); | 42 expect(yamlToString([1, 2, 3]), equals('[1,2,3]')); |
43 }); | 43 }); |
44 | 44 |
45 test('uses indentation for maps', () { | 45 test('uses indentation for maps', () { |
46 expect(yamlToString({'a': {'b': 1, 'c': 2}, 'd': 3}), | 46 expect(yamlToString({ |
47 equals(""" | 47 'a': { |
| 48 'b': 1, |
| 49 'c': 2 |
| 50 }, |
| 51 'd': 3 |
| 52 }), equals(""" |
48 a: | 53 a: |
49 b: 1 | 54 b: 1 |
50 c: 2 | 55 c: 2 |
51 d: 3""")); | 56 d: 3""")); |
52 }); | 57 }); |
53 | 58 |
54 test('sorts map keys', () { | 59 test('sorts map keys', () { |
55 expect(yamlToString({'a': 1, 'c': 2, 'b': 3, 'd': 4}), | 60 expect(yamlToString({ |
56 equals(""" | 61 'a': 1, |
| 62 'c': 2, |
| 63 'b': 3, |
| 64 'd': 4 |
| 65 }), equals(""" |
57 a: 1 | 66 a: 1 |
58 b: 3 | 67 b: 3 |
59 c: 2 | 68 c: 2 |
60 d: 4""")); | 69 d: 4""")); |
61 }); | 70 }); |
62 | 71 |
63 test('quotes map keys as needed', () { | 72 test('quotes map keys as needed', () { |
64 expect(yamlToString({'no': 1, 'yes!': 2, '123': 3}), | 73 expect(yamlToString({ |
65 equals(""" | 74 'no': 1, |
| 75 'yes!': 2, |
| 76 '123': 3 |
| 77 }), equals(""" |
66 "123": 3 | 78 "123": 3 |
67 no: 1 | 79 no: 1 |
68 "yes!": 2""")); | 80 "yes!": 2""")); |
69 }); | 81 }); |
70 | 82 |
71 test('handles non-string map keys', () { | 83 test('handles non-string map keys', () { |
72 var map = new Map(); | 84 var map = new Map(); |
73 map[null] = "null"; | 85 map[null] = "null"; |
74 map[123] = "num"; | 86 map[123] = "num"; |
75 map[true] = "bool"; | 87 map[true] = "bool"; |
76 | 88 |
77 expect(yamlToString(map), | 89 expect(yamlToString(map), equals(""" |
78 equals(""" | |
79 123: num | 90 123: num |
80 null: null | 91 null: null |
81 true: bool""")); | 92 true: bool""")); |
82 }); | 93 }); |
83 | 94 |
84 test('handles empty maps', () { | 95 test('handles empty maps', () { |
85 expect(yamlToString({}), equals("{}")); | 96 expect(yamlToString({}), equals("{}")); |
86 expect(yamlToString({'a': {}, 'b': {}}), equals(""" | 97 expect(yamlToString({ |
| 98 'a': {}, |
| 99 'b': {} |
| 100 }), equals(""" |
87 a: {} | 101 a: {} |
88 b: {}""")); | 102 b: {}""")); |
89 }); | 103 }); |
90 }); | 104 }); |
91 } | 105 } |
OLD | NEW |