| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library utils_test; | |
| 6 | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 import 'test_pub.dart'; | |
| 9 import '../lib/src/utils.dart'; | |
| 10 | |
| 11 main() { | |
| 12 initConfig(); | |
| 13 | |
| 14 group('yamlToString()', () { | |
| 15 test('null', () { | |
| 16 expect(yamlToString(null), equals('null')); | |
| 17 }); | |
| 18 | |
| 19 test('numbers', () { | |
| 20 expect(yamlToString(123), equals('123')); | |
| 21 expect(yamlToString(12.34), equals('12.34')); | |
| 22 }); | |
| 23 | |
| 24 test('does not quote strings that do not need it', () { | |
| 25 expect(yamlToString('a'), equals('a')); | |
| 26 expect(yamlToString('some-string'), equals('some-string')); | |
| 27 expect(yamlToString('hey123CAPS'), equals('hey123CAPS')); | |
| 28 expect(yamlToString("_under_score"), equals('_under_score')); | |
| 29 }); | |
| 30 | |
| 31 test('quotes other strings', () { | |
| 32 expect(yamlToString(''), equals('""')); | |
| 33 expect(yamlToString('123'), equals('"123"')); | |
| 34 expect(yamlToString('white space'), equals('"white space"')); | |
| 35 expect(yamlToString('"quote"'), equals(r'"\"quote\""')); | |
| 36 expect(yamlToString("apostrophe'"), equals('"apostrophe\'"')); | |
| 37 expect(yamlToString("new\nline"), equals(r'"new\nline"')); | |
| 38 expect(yamlToString("?unctu@t!on"), equals(r'"?unctu@t!on"')); | |
| 39 }); | |
| 40 | |
| 41 test('lists use JSON style', () { | |
| 42 expect(yamlToString([1, 2, 3]), equals('[1,2,3]')); | |
| 43 }); | |
| 44 | |
| 45 test('uses indentation for maps', () { | |
| 46 expect(yamlToString({ | |
| 47 'a': { | |
| 48 'b': 1, | |
| 49 'c': 2 | |
| 50 }, | |
| 51 'd': 3 | |
| 52 }), equals(""" | |
| 53 a: | |
| 54 b: 1 | |
| 55 c: 2 | |
| 56 d: 3""")); | |
| 57 }); | |
| 58 | |
| 59 test('sorts map keys', () { | |
| 60 expect(yamlToString({ | |
| 61 'a': 1, | |
| 62 'c': 2, | |
| 63 'b': 3, | |
| 64 'd': 4 | |
| 65 }), equals(""" | |
| 66 a: 1 | |
| 67 b: 3 | |
| 68 c: 2 | |
| 69 d: 4""")); | |
| 70 }); | |
| 71 | |
| 72 test('quotes map keys as needed', () { | |
| 73 expect(yamlToString({ | |
| 74 'no': 1, | |
| 75 'yes!': 2, | |
| 76 '123': 3 | |
| 77 }), equals(""" | |
| 78 "123": 3 | |
| 79 no: 1 | |
| 80 "yes!": 2""")); | |
| 81 }); | |
| 82 | |
| 83 test('handles non-string map keys', () { | |
| 84 var map = new Map(); | |
| 85 map[null] = "null"; | |
| 86 map[123] = "num"; | |
| 87 map[true] = "bool"; | |
| 88 | |
| 89 expect(yamlToString(map), equals(""" | |
| 90 123: num | |
| 91 null: null | |
| 92 true: bool""")); | |
| 93 }); | |
| 94 | |
| 95 test('handles empty maps', () { | |
| 96 expect(yamlToString({}), equals("{}")); | |
| 97 expect(yamlToString({ | |
| 98 'a': {}, | |
| 99 'b': {} | |
| 100 }), equals(""" | |
| 101 a: {} | |
| 102 b: {}""")); | |
| 103 }); | |
| 104 }); | |
| 105 } | |
| OLD | NEW |