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

Unified Diff: test/version_constraint_test.dart

Issue 607663002: Harvest from pub. Mostly a straight copy, except: (Closed) Base URL: https://github.com/dart-lang/pub_semver.git@master
Patch Set: Revise! Created 6 years, 3 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 | « test/utils.dart ('k') | test/version_range_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/version_constraint_test.dart
diff --git a/test/version_constraint_test.dart b/test/version_constraint_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..df8c099096f85dae1c76ef1476202ad3caef2af8
--- /dev/null
+++ b/test/version_constraint_test.dart
@@ -0,0 +1,143 @@
+// 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_semver.test.version_constraint_test;
+
+import 'package:unittest/unittest.dart';
+
+import 'package:pub_semver/pub_semver.dart';
+
+import 'utils.dart';
+
+main() {
+ test('any', () {
+ expect(VersionConstraint.any.isAny, isTrue);
+ expect(VersionConstraint.any, allows(
+ new Version.parse('0.0.0-blah'),
+ new Version.parse('1.2.3'),
+ new Version.parse('12345.678.90')));
+ });
+
+ test('empty', () {
+ expect(VersionConstraint.empty.isEmpty, isTrue);
+ expect(VersionConstraint.empty.isAny, isFalse);
+ expect(VersionConstraint.empty, doesNotAllow(
+ new Version.parse('0.0.0-blah'),
+ new Version.parse('1.2.3'),
+ new Version.parse('12345.678.90')));
+ });
+
+ group('parse()', () {
+ test('parses an exact version', () {
+ var constraint = new VersionConstraint.parse('1.2.3-alpha');
+
+ expect(constraint is Version, isTrue);
+ expect(constraint, equals(new Version(1, 2, 3, pre: 'alpha')));
+ });
+
+ test('parses "any"', () {
+ var constraint = new VersionConstraint.parse('any');
+
+ expect(constraint is VersionConstraint, isTrue);
+ expect(constraint, allows(
+ new Version.parse('0.0.0'),
+ new Version.parse('1.2.3'),
+ new Version.parse('12345.678.90')));
+ });
+
+ test('parses a ">" minimum version', () {
+ var constraint = new VersionConstraint.parse('>1.2.3');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.3+foo'),
+ new Version.parse('1.2.4')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.1'),
+ new Version.parse('1.2.3-build'),
+ new Version.parse('1.2.3')));
+ });
+
+ test('parses a ">=" minimum version', () {
+ var constraint = new VersionConstraint.parse('>=1.2.3');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.3'),
+ new Version.parse('1.2.3+foo'),
+ new Version.parse('1.2.4')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.1'),
+ new Version.parse('1.2.3-build')));
+ });
+
+ test('parses a "<" maximum version', () {
+ var constraint = new VersionConstraint.parse('<1.2.3');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.1'),
+ new Version.parse('1.2.2+foo')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.3'),
+ new Version.parse('1.2.3+foo'),
+ new Version.parse('1.2.4')));
+ });
+
+ test('parses a "<=" maximum version', () {
+ var constraint = new VersionConstraint.parse('<=1.2.3');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.1'),
+ new Version.parse('1.2.3-build'),
+ new Version.parse('1.2.3')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.3+foo'),
+ new Version.parse('1.2.4')));
+ });
+
+ test('parses a series of space-separated constraints', () {
+ var constraint = new VersionConstraint.parse('>1.0.0 >=1.2.3 <1.3.0');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.3'),
+ new Version.parse('1.2.5')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.3-pre'),
+ new Version.parse('1.3.0'),
+ new Version.parse('3.4.5')));
+ });
+
+ test('ignores whitespace around operators', () {
+ var constraint = new VersionConstraint.parse(' >1.0.0>=1.2.3 < 1.3.0');
+
+ expect(constraint, allows(
+ new Version.parse('1.2.3'),
+ new Version.parse('1.2.5')));
+ expect(constraint, doesNotAllow(
+ new Version.parse('1.2.3-pre'),
+ new Version.parse('1.3.0'),
+ new Version.parse('3.4.5')));
+ });
+
+ test('does not allow "any" to be mixed with other constraints', () {
+ expect(() => new VersionConstraint.parse('any 1.0.0'),
+ throwsFormatException);
+ });
+
+ test('throws FormatException on a bad string', () {
+ var bad = [
+ "", " ", // Empty string.
+ "foo", // Bad text.
+ ">foo", // Bad text after operator.
+ "1.0.0 foo", "1.0.0foo", // Bad text after version.
+ "anything", // Bad text after "any".
+ "<>1.0.0", // Multiple operators.
+ "1.0.0<" // Trailing operator.
+ ];
+
+ for (var text in bad) {
+ expect(() => new VersionConstraint.parse(text),
+ throwsFormatException);
+ }
+ });
+ });
+}
« no previous file with comments | « test/utils.dart ('k') | test/version_range_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698