Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: sdk/lib/_internal/pub/test/preprocess_test.dart

Issue 300843007: Run a simple preprocessor on the sources pub loads in barback isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/preprocess.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/test/preprocess_test.dart
diff --git a/sdk/lib/_internal/pub/test/preprocess_test.dart b/sdk/lib/_internal/pub/test/preprocess_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d908f1fdd4df21ad0942b76ee0886f8c4640bbb5
--- /dev/null
+++ b/sdk/lib/_internal/pub/test/preprocess_test.dart
@@ -0,0 +1,255 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library pub.test.preprocess_test;
+
+import 'package:unittest/unittest.dart';
+
+import '../lib/src/preprocess.dart';
+import '../lib/src/version.dart';
+import 'test_pub.dart';
+
+main() {
+ initConfig();
+
+ test("does nothing on a file without preprocessor directives", () {
+ var text = '''
+some text
+// normal comment
+// #
+ //# not beginning of line
+''';
+
+ expect(_preprocess(text), equals(text));
+ });
+
+ test("allows bare insert directive", () {
+ expect(_preprocess('//> foo'), equals('foo'));
+ });
+
+ test("allows empty insert directive", () {
+ expect(_preprocess('''
+//> foo
+//>
+//> bar
+'''), equals('foo\n\nbar\n'));
+ });
+
+ group("if", () {
+ test("removes sections with non-matching versions", () {
+ expect(_preprocess('''
+before
+//# if barback <1.0.0
+inside
+//# end
+after
+'''), equals('''
+before
+after
+'''));
+ });
+
+ test("doesn't insert section with non-matching versions", () {
+ expect(_preprocess('''
+before
+//# if barback <1.0.0
+//> inside
+//# end
+after
+'''), equals('''
+before
+after
+'''));
+ });
+
+ test("doesn't remove sections with matching versions", () {
+ expect(_preprocess('''
+before
+//# if barback >1.0.0
+inside
+//# end
+after
+'''), equals('''
+before
+inside
+after
+'''));
+ });
+
+ test("inserts sections with matching versions", () {
+ expect(_preprocess('''
+before
+//# if barback >1.0.0
+//> inside
+//# end
+after
+'''), equals('''
+before
+inside
+after
+'''));
+ });
+
+ test("allows version ranges", () {
+ expect(_preprocess('''
+before
+//# if barback >=1.0.0 <2.0.0
+inside 1
+//# end
+//# if barback >=0.9.0 <1.0.0
+inside 2
+//# end
+after
+'''), equals('''
+before
+inside 1
+after
+'''));
+ });
+ });
+
+ group("else", () {
+ test("removes non-matching sections", () {
+ expect(_preprocess('''
+before
+//# if barback >1.0.0
+inside 1
+//# else
+inside 2
+//# end
+after
+'''), equals('''
+before
+inside 1
+after
+'''));
+ });
+
+ test("doesn't insert non-matching sections", () {
+ expect(_preprocess('''
+before
+//# if barback >1.0.0
+inside 1
+//# else
+//> inside 2
+//# end
+after
+'''), equals('''
+before
+inside 1
+after
+'''));
+ });
+
+ test("doesn't remove matching sections", () {
+ expect(_preprocess('''
+before
+//# if barback <1.0.0
+inside 1
+//# else
+inside 2
+//# end
+after
+'''), equals('''
+before
+inside 2
+after
+'''));
+ });
+
+ test("inserts matching sections", () {
+ expect(_preprocess('''
+before
+//# if barback <1.0.0
+inside 1
+//# else
+//> inside 2
+//# end
+after
+'''), equals('''
+before
+inside 2
+after
+'''));
+ });
+ });
+
+ group("errors", () {
+ test("disallows unknown statements", () {
+ expect(() => _preprocess('//# foo bar\n//# end'), throwsFormatException);
+ });
+
+ test("disallows insert directive without space", () {
+ expect(() => _preprocess('//>foo'), throwsFormatException);
+ });
+
+ group("if", () {
+ test("disallows if with no arguments", () {
+ expect(() => _preprocess('//# if\n//# end'), throwsFormatException);
+ });
+
+ test("disallows if with no version range", () {
+ expect(() => _preprocess('//# if barback\n//# end'),
+ throwsFormatException);
+ });
+
+ test("disallows if with no package", () {
+ expect(() => _preprocess('//# if <=1.0.0\n//# end'),
+ throwsFormatException);
+ });
+
+ test("disallows unknown package name", () {
+ expect(() => _preprocess('//# if polymer <=1.0.0\n//# end'),
+ throwsFormatException);
+ });
+
+ test("disallows invalid version constraint", () {
+ expect(() => _preprocess('//# if barback >=1.0\n//# end'),
+ throwsFormatException);
+ });
+
+ test("disallows dangling end", () {
+ expect(() => _preprocess('//# end'),
+ throwsFormatException);
+ });
+
+ test("disallows if without end", () {
+ expect(() => _preprocess('//# if barback >=1.0.0'),
+ throwsFormatException);
+ });
+
+ test("disallows nested if", () {
+ expect(() => _preprocess('''
+//# if barback >=1.0.0
+//# if barback >= 1.5.0
+//# end
+//# end
+'''),
+ throwsFormatException);
+ });
+ });
+
+ group("else", () {
+ test("disallows else without if", () {
+ expect(() => _preprocess('//# else\n//# end'), throwsFormatException);
+ });
+
+ test("disallows else without end", () {
+ expect(() => _preprocess('//# if barback >=1.0.0\n//# else'),
+ throwsFormatException);
+ });
+
+ test("disallows else with an argument", () {
+ expect(() => _preprocess('''
+//# if barback >=1.0.0
+//# else barback <0.5.0
+//# end
+'''), throwsFormatException);
+ });
+ });
+ });
+}
+
+String _preprocess(String input) =>
+ preprocess(input, new Version.parse("1.2.3"), 'source/url');
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/preprocess.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698