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

Unified Diff: third_party/pkg/route_hierarchical/test/url_template_test.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 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
Index: third_party/pkg/route_hierarchical/test/url_template_test.dart
diff --git a/third_party/pkg/route_hierarchical/test/url_template_test.dart b/third_party/pkg/route_hierarchical/test/url_template_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..37d1cd4bb29f1b01a279d6f7d0dc6ba744b2768b
--- /dev/null
+++ b/third_party/pkg/route_hierarchical/test/url_template_test.dart
@@ -0,0 +1,89 @@
+library url_template_test;
+
+import 'package:unittest/unittest.dart';
+import 'package:route_hierarchical/url_template.dart';
+import 'package:route_hierarchical/url_matcher.dart';
+
+main() {
+ group('UrlTemplate', () {
+ test('should work with simple templates', () {
+ var tmpl = new UrlTemplate('/foo/bar:baz/aux');
+ expect(tmpl.match('/foo/bar123/aux'),
+ new UrlMatch('/foo/bar123/aux', '', {
+ 'baz': '123'
+ }));
+
+ tmpl = new UrlTemplate('/foo/:bar');
+ expect(tmpl.match('/foo/123'), new UrlMatch('/foo/123', '', {
+ 'bar': '123'
+ }));
+
+ tmpl = new UrlTemplate('/:foo/bar');
+ expect(tmpl.match('/123/bar'), new UrlMatch('/123/bar', '', {
+ 'foo': '123'
+ }));
+
+ tmpl = new UrlTemplate('/user/:userId/article/:articleId/view');
+ UrlMatch params =
+ tmpl.match('/user/jsmith/article/1234/view/someotherstuff');
+ expect(params, new UrlMatch('/user/jsmith/article/1234/view',
+ '/someotherstuff', {
+ 'userId': 'jsmith',
+ 'articleId': '1234'
+ }));
+
+ params = tmpl.match('/user/jsmith/article/1234/edit');
+ expect(params, isNull);
+
+ tmpl = new UrlTemplate(r'/foo/:bar$123/aux');
+ expect(tmpl.match(r'/foo/123$123/aux'),
+ new UrlMatch(r'/foo/123$123/aux', '', {
+ 'bar': '123'
+ }));
+ });
+
+ test('should work with special characters', () {
+ var tmpl = new UrlTemplate(r'\^\|+[]{}()');
+ expect(tmpl.match(r'\^\|+[]{}()'), new UrlMatch(r'\^\|+[]{}()', '', {}));
+
+ tmpl = new UrlTemplate(r'/:foo/^\|+[]{}()');
+ expect(tmpl.match(r'/123/^\|+[]{}()'),
+ new UrlMatch(r'/123/^\|+[]{}()', '', {
+ 'foo': '123'
+ }));
+ });
+
+ test('should only match prefix', () {
+ var tmpl = new UrlTemplate(r'/foo');
+ expect(tmpl.match(r'/foo/foo/bar'),
+ new UrlMatch(r'/foo', '/foo/bar', {}));
+ });
+
+ test('should reverse', () {
+ var tmpl = new UrlTemplate('/:a/:b/:c');
+ expect(tmpl.reverse(), '/null/null/null');
+ expect(tmpl.reverse(parameters: {
+ 'a': 'foo',
+ 'b': 'bar',
+ 'c': 'baz'
+ }), '/foo/bar/baz');
+
+ tmpl = new UrlTemplate(':a/bar/baz');
+ expect(tmpl.reverse(), 'null/bar/baz');
+ expect(tmpl.reverse(parameters: {
+ 'a': '/foo',
+ }), '/foo/bar/baz');
+
+ tmpl = new UrlTemplate('/foo/bar/:c');
+ expect(tmpl.reverse(), '/foo/bar/null');
+ expect(tmpl.reverse(parameters: {
+ 'c': 'baz',
+ }), '/foo/bar/baz');
+
+ tmpl = new UrlTemplate('/foo/bar/:c');
+ expect(tmpl.reverse(tail: '/tail', parameters: {
+ 'c': 'baz',
+ }), '/foo/bar/baz/tail');
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698