| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 pub.test.preprocess_test; | 5 library pub.test.preprocess_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import '../lib/src/preprocess.dart'; | 9 import '../lib/src/preprocess.dart'; |
| 10 import '../lib/src/version.dart'; | 10 import '../lib/src/version.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 test("allows empty insert directive", () { | 31 test("allows empty insert directive", () { |
| 32 expect(_preprocess(''' | 32 expect(_preprocess(''' |
| 33 //> foo | 33 //> foo |
| 34 //> | 34 //> |
| 35 //> bar | 35 //> bar |
| 36 '''), equals('foo\n\nbar\n')); | 36 '''), equals('foo\n\nbar\n')); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 group("if", () { | 39 group("if", () { |
| 40 test("removes sections with non-matching versions", () { | 40 group("with a version range", () { |
| 41 expect(_preprocess(''' | 41 test("removes sections with non-matching versions", () { |
| 42 expect(_preprocess(''' |
| 42 before | 43 before |
| 43 //# if barback <1.0.0 | 44 //# if barback <1.0.0 |
| 44 inside | 45 inside |
| 45 //# end | 46 //# end |
| 46 after | 47 after |
| 47 '''), equals(''' | 48 '''), equals(''' |
| 48 before | 49 before |
| 49 after | 50 after |
| 50 ''')); | 51 ''')); |
| 51 }); | 52 }); |
| 52 | 53 |
| 53 test("doesn't insert section with non-matching versions", () { | 54 test("doesn't insert section with non-matching versions", () { |
| 54 expect(_preprocess(''' | 55 expect(_preprocess(''' |
| 55 before | 56 before |
| 56 //# if barback <1.0.0 | 57 //# if barback <1.0.0 |
| 57 //> inside | 58 //> inside |
| 58 //# end | 59 //# end |
| 59 after | 60 after |
| 60 '''), equals(''' | 61 '''), equals(''' |
| 61 before | 62 before |
| 62 after | 63 after |
| 63 ''')); | 64 ''')); |
| 64 }); | 65 }); |
| 65 | 66 |
| 66 test("doesn't remove sections with matching versions", () { | 67 test("doesn't remove sections with matching versions", () { |
| 67 expect(_preprocess(''' | 68 expect(_preprocess(''' |
| 68 before | 69 before |
| 69 //# if barback >1.0.0 | 70 //# if barback >1.0.0 |
| 70 inside | 71 inside |
| 71 //# end | 72 //# end |
| 72 after | 73 after |
| 73 '''), equals(''' | 74 '''), equals(''' |
| 74 before | 75 before |
| 75 inside | 76 inside |
| 76 after | 77 after |
| 77 ''')); | 78 ''')); |
| 78 }); | 79 }); |
| 79 | 80 |
| 80 test("inserts sections with matching versions", () { | 81 test("inserts sections with matching versions", () { |
| 81 expect(_preprocess(''' | 82 expect(_preprocess(''' |
| 82 before | 83 before |
| 83 //# if barback >1.0.0 | 84 //# if barback >1.0.0 |
| 84 //> inside | 85 //> inside |
| 85 //# end | 86 //# end |
| 86 after | 87 after |
| 87 '''), equals(''' | 88 '''), equals(''' |
| 88 before | 89 before |
| 89 inside | 90 inside |
| 90 after | 91 after |
| 91 ''')); | 92 ''')); |
| 92 }); | 93 }); |
| 93 | 94 |
| 94 test("allows version ranges", () { | 95 test("allows multi-element version ranges", () { |
| 95 expect(_preprocess(''' | 96 expect(_preprocess(''' |
| 96 before | 97 before |
| 97 //# if barback >=1.0.0 <2.0.0 | 98 //# if barback >=1.0.0 <2.0.0 |
| 98 inside 1 | 99 inside 1 |
| 99 //# end | 100 //# end |
| 100 //# if barback >=0.9.0 <1.0.0 | 101 //# if barback >=0.9.0 <1.0.0 |
| 101 inside 2 | 102 inside 2 |
| 102 //# end | 103 //# end |
| 103 after | 104 after |
| 104 '''), equals(''' | 105 '''), equals(''' |
| 105 before | 106 before |
| 106 inside 1 | 107 inside 1 |
| 107 after | 108 after |
| 108 ''')); | 109 ''')); |
| 110 }); |
| 111 }); |
| 112 |
| 113 group("with a package name", () { |
| 114 test("removes sections for a nonexistent package", () { |
| 115 expect(_preprocess(''' |
| 116 before |
| 117 //# if fblthp |
| 118 inside |
| 119 //# end |
| 120 after |
| 121 '''), equals(''' |
| 122 before |
| 123 after |
| 124 ''')); |
| 125 }); |
| 126 |
| 127 test("doesn't insert sections for a nonexistent package", () { |
| 128 expect(_preprocess(''' |
| 129 before |
| 130 //# if fblthp |
| 131 //> inside |
| 132 //# end |
| 133 after |
| 134 '''), equals(''' |
| 135 before |
| 136 after |
| 137 ''')); |
| 138 }); |
| 139 |
| 140 test("doesn't remove sections with an existent package", () { |
| 141 expect(_preprocess(''' |
| 142 before |
| 143 //# if barback |
| 144 inside |
| 145 //# end |
| 146 after |
| 147 '''), equals(''' |
| 148 before |
| 149 inside |
| 150 after |
| 151 ''')); |
| 152 }); |
| 153 |
| 154 test("inserts sections with an existent package", () { |
| 155 expect(_preprocess(''' |
| 156 before |
| 157 //# if barback |
| 158 //> inside |
| 159 //# end |
| 160 after |
| 161 '''), equals(''' |
| 162 before |
| 163 inside |
| 164 after |
| 165 ''')); |
| 166 }); |
| 109 }); | 167 }); |
| 110 }); | 168 }); |
| 111 | 169 |
| 112 group("else", () { | 170 group("else", () { |
| 113 test("removes non-matching sections", () { | 171 test("removes non-matching sections", () { |
| 114 expect(_preprocess(''' | 172 expect(_preprocess(''' |
| 115 before | 173 before |
| 116 //# if barback >1.0.0 | 174 //# if barback >1.0.0 |
| 117 inside 1 | 175 inside 1 |
| 118 //# else | 176 //# else |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 240 |
| 183 test("disallows insert directive without space", () { | 241 test("disallows insert directive without space", () { |
| 184 expect(() => _preprocess('//>foo'), throwsFormatException); | 242 expect(() => _preprocess('//>foo'), throwsFormatException); |
| 185 }); | 243 }); |
| 186 | 244 |
| 187 group("if", () { | 245 group("if", () { |
| 188 test("disallows if with no arguments", () { | 246 test("disallows if with no arguments", () { |
| 189 expect(() => _preprocess('//# if\n//# end'), throwsFormatException); | 247 expect(() => _preprocess('//# if\n//# end'), throwsFormatException); |
| 190 }); | 248 }); |
| 191 | 249 |
| 192 test("disallows if with no version range", () { | |
| 193 expect(() => _preprocess('//# if barback\n//# end'), | |
| 194 throwsFormatException); | |
| 195 }); | |
| 196 | |
| 197 test("disallows if with no package", () { | 250 test("disallows if with no package", () { |
| 198 expect(() => _preprocess('//# if <=1.0.0\n//# end'), | 251 expect(() => _preprocess('//# if <=1.0.0\n//# end'), |
| 199 throwsFormatException); | 252 throwsFormatException); |
| 200 }); | 253 }); |
| 201 | 254 |
| 202 test("disallows unknown package name", () { | |
| 203 expect(() => _preprocess('//# if polymer <=1.0.0\n//# end'), | |
| 204 throwsFormatException); | |
| 205 }); | |
| 206 | |
| 207 test("disallows invalid version constraint", () { | 255 test("disallows invalid version constraint", () { |
| 208 expect(() => _preprocess('//# if barback >=1.0\n//# end'), | 256 expect(() => _preprocess('//# if barback >=1.0\n//# end'), |
| 209 throwsFormatException); | 257 throwsFormatException); |
| 210 }); | 258 }); |
| 211 | 259 |
| 212 test("disallows dangling end", () { | 260 test("disallows dangling end", () { |
| 213 expect(() => _preprocess('//# end'), | 261 expect(() => _preprocess('//# end'), |
| 214 throwsFormatException); | 262 throwsFormatException); |
| 215 }); | 263 }); |
| 216 | 264 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 245 //# if barback >=1.0.0 | 293 //# if barback >=1.0.0 |
| 246 //# else barback <0.5.0 | 294 //# else barback <0.5.0 |
| 247 //# end | 295 //# end |
| 248 '''), throwsFormatException); | 296 '''), throwsFormatException); |
| 249 }); | 297 }); |
| 250 }); | 298 }); |
| 251 }); | 299 }); |
| 252 } | 300 } |
| 253 | 301 |
| 254 String _preprocess(String input) => | 302 String _preprocess(String input) => |
| 255 preprocess(input, new Version.parse("1.2.3"), 'source/url'); | 303 preprocess(input, {'barback': new Version.parse("1.2.3")}, 'source/url'); |
| OLD | NEW |