OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 import "package:compiler/src/platform_configuration.dart"; |
| 6 import "package:expect/expect.dart"; |
| 7 |
| 8 /// Runs the parser on [input] and compares it with [expectedResult] |
| 9 /// |
| 10 /// A '*' in [input] indicates that the parser will report an error at the |
| 11 /// given point (On [input] with the "*" removed). |
| 12 test(String input, [Map<String, Map<String, String>> expectedOutput]) { |
| 13 int starIndex = input.indexOf("*"); |
| 14 String inputWithoutStar = input.replaceFirst("*", ""); |
| 15 |
| 16 parse() => parseIni(inputWithoutStar.codeUnits, |
| 17 allowedSections: new Set.from(["AA", "BB"])); |
| 18 |
| 19 if (starIndex != -1) { |
| 20 Expect.equals(expectedOutput, null); |
| 21 Expect.throws(parse, (e) { |
| 22 Expect.isTrue(e is FormatException); |
| 23 Expect.equals(starIndex, e.offset); |
| 24 return e is FormatException; |
| 25 }); |
| 26 } else { |
| 27 Map<String, Map<String, String>> result = parse(); |
| 28 Expect.equals(expectedOutput.length, result.length); |
| 29 expectedOutput.forEach((String name, Map<String, String> properties) { |
| 30 Expect.isTrue(expectedOutput.containsKey(name), "Missing section $name"); |
| 31 Expect.mapEquals(expectedOutput[name], properties); |
| 32 }); |
| 33 } |
| 34 } |
| 35 |
| 36 main() { |
| 37 // Empty file. |
| 38 test( |
| 39 """ |
| 40 # Nothing here |
| 41 """, |
| 42 {}); |
| 43 |
| 44 // Text outside section. |
| 45 test(""" |
| 46 *aaa |
| 47 """); |
| 48 |
| 49 // Malformed header. |
| 50 test(""" |
| 51 *[AABC |
| 52 name:value |
| 53 """); |
| 54 |
| 55 // Text after header. |
| 56 test(""" |
| 57 [AABC]*abcde |
| 58 """); |
| 59 |
| 60 // Empty section name. |
| 61 test(""" |
| 62 [*] |
| 63 """); |
| 64 |
| 65 // Duplicate section name. |
| 66 test(""" |
| 67 [AA] |
| 68 [BB] |
| 69 [*AA] |
| 70 """); |
| 71 |
| 72 // Unrecognized section name. |
| 73 test(""" |
| 74 [*CC] |
| 75 """); |
| 76 |
| 77 // Empty property name. |
| 78 test(""" |
| 79 [AA] |
| 80 *:value |
| 81 name:value |
| 82 """); |
| 83 |
| 84 // Ok. |
| 85 test( |
| 86 """ |
| 87 [AA] |
| 88 name:value |
| 89 [BB] |
| 90 name:value |
| 91 name2:value2 |
| 92 """, |
| 93 { |
| 94 "AA": {"name": "value"}, |
| 95 "BB": {"name": "value", "name2": "value2"} |
| 96 }); |
| 97 |
| 98 // Ok, file not ending in newline. |
| 99 test( |
| 100 """ |
| 101 [AA] |
| 102 name:value""", |
| 103 { |
| 104 "A": {"name": "value"} |
| 105 }); |
| 106 |
| 107 // Ok, whitespace is trimmed away. |
| 108 test( |
| 109 """ |
| 110 [ AA ] |
| 111 name\t: value """, |
| 112 { |
| 113 "A": {"name": "value"} |
| 114 }); |
| 115 |
| 116 // Duplicate property name. |
| 117 test(""" |
| 118 [AA] |
| 119 a:b |
| 120 b:c |
| 121 *a:c |
| 122 """); |
| 123 |
| 124 // No ':' on property line. |
| 125 test(""" |
| 126 [AA] |
| 127 *name1 |
| 128 name2:value |
| 129 """); |
| 130 } |
OLD | NEW |