Permalink
Browse files

ah, wrong tests

  • Loading branch information...
1 parent 94bd2bc commit 59939cac77d22693f0f2b1766836a43d7f519e6d Ilya Belikin committed Mar 13, 2009
Showing with 41 additions and 113 deletions.
  1. +41 −88 t/01.t
  2. +0 −25 t/02-add_rules.t
View
@@ -1,108 +1,61 @@
use v6;
-
use Test;
-plan 18;
-
-use Dispatcher;
-ok(1,'We use Dispatcher and we are still alive');
-
-use Dispatcher::Rule;
-ok(1,'We use Dispatcher::Rule and we are still alive');
-
-my $d = Dispatcher.new;
-
-dies_ok( { $d.add: Dispatcher::Rule.new },
- 'Dispatch .add adds only complete Rule objects' );
-
-$d.add: Dispatcher::Rule.new( :tokens(''), action => { "Krevedko" } );
-
-is( $d.dispatch(['']),
- 'Krevedko',
- "Dispatch to Rule ['']"
-);
-
-ok( $d.add( ['foo', 'bar'], { "Yay" } ),
- '.add fith @tokens and $action -- shortcut for fast add Rule object' );
-
-nok( $d.dispatch(['foo']),
- 'Dispatcher return False if can`t find match Rule and do not have default' );
-
-
-is( $d.dispatch(['foo', 'bar']),
- "Yay",
- "Dispatch to Rule ['foo', 'bar'])"
-);
-
-$d.default = { "Woow" };
-
-is( $d.dispatch(['foo', 'bar', 'baz']),
- "Woow",
- 'Dispatch to default, when have no matched Rule'
-);
-
-$d.add: ['foo', 'a'|'b'], { "Zzzz" };
-
-is( $d.dispatch(['foo', 'a']),
- 'Zzzz',
- 'Dispatch to Rule with Junction a'
-);
+plan 28;
-is( $d.dispatch(['foo', 'b']),
- 'Zzzz',
- 'Dispatch to Rule with Junction (foo/a|b) b'
-);
+use URI;
+ok(1,'We use URI and we are still alive');
-$d.add: ['foo', /^ \d+ $/], { $^d };
+my $u = URI.new;
+$u.init('http://example.com:80/about/us?foo#bar');
-is( $d.dispatch(['foo', '50']),
- '50',
- "Dispatch to Rule with regexp ['foo', /^ \d+ \$/])"
-);
+is($u.scheme, 'http', 'scheme');
+is($u.host, 'example.com', 'host');
+is($u.port, '80', 'port');
+is($u.path, '/about/us', 'path');
+is($u.query, 'foo', 'query');
+is($u.frag, 'bar', 'frag');
+is($u.chunks, 'about us', 'chunks');
+is($u.chunks[0], 'about', 'first chunk');
+is($u.chunks[1], 'us', 'second chunk');
-$d.add( [/^ \w+ $/], { "Yep!" if $^w.WHAT eq 'Match' } );
+is( ~$u, 'http://example.com:80/about/us?foo#bar',
+ 'Complete path stringification');
-is( $d.dispatch(['so']),
- 'Yep!',
- "Argument is Match"
-);
+$u.init('https://eXAMplE.COM');
-$d.add: ['foo', / \d+ /], { $^d + 10 };
+is($u.scheme, 'https', 'scheme');
+is($u.host, 'example.com', 'host');
+is( "$u", 'https://example.com',
+ 'https://eXAMplE.COM stringifies to https://example.com');
-is( $d.dispatch(['foo', '50']),
- '60',
- "Dispatch ['foo', '50'] to last matched Rule"
-);
+$u.init('/foo/bar/baz');
-is( $d.dispatch(['foo', 'a50z']),
- '60',
- 'Rule that catches the right arg'
-);
+is($u.chunks, 'foo bar baz', 'chunks from absolute path');
+ok($u.absolute, 'absolute path');
+nok($u.relative, 'not relative path');
-$d.add: ['foo', / \d+ /, 'bar' ], { $^d + 1 };
+$u.init('foo/bar/baz');
-is( $d.dispatch(['foo', 'item4', 'bar']),
- '5',
- 'Rule with regexp in the middle (foo/\d+/bar)'
-);
+is($u.chunks, 'foo bar baz', 'chunks from relative path');
+ok( $u.relative, 'relative path');
+nok($u.absolute, 'not absolute path');
-$d.add: ['summ', / \d+ /, / \d+ / ], { $^a + $^b };
+is($u.chunks[0], 'foo', 'first chunk');
+is($u.chunks[1], 'bar', 'second chunk');
+is($u.chunks[*-1], 'baz', 'last chunk');
+$u.init('http://foo.com');
-is( $d.dispatch(['summ', '2', '3']),
- '5',
- 'Dispatch to Rule with two regexps'
-);
+ok($u.chunks.list.perl eq '[""]', ".chunks return [''] for empty path");
+ok($u.absolute, 'http://foo.com has an absolute path');
+nok($u.relative, 'http://foo.com does not have a relative path');
-$d.add: ['summ', / \w+ /, 1|2 ], { $^a ~ "oo" };
+# test URI parsing with <> or "" and spaces
+$u.init("<http://foo.com> ");
+is("$u", 'http://foo.com', '<> removed from str');
-is( $d.dispatch(['summ', 'Z', '2']),
- 'Zoo',
- 'Rule with a regexp and a junction'
-);
+$u.init(' "http://foo.com"');
+is("$u", 'http://foo.com', '"" removed from str');
-is( $d.dispatch(['foo', 'bar']),
- "Yay",
- 'Dispatch to simple Rule, test after adding so many Rules'
-);
# vim:ft=perl6
View
@@ -1,25 +0,0 @@
-use v6;
-
-use Test;
-plan 6;
-
-use Dispatcher;
-
-my $d = Dispatcher.new;
-
-my @rules =
- ['foo'], { "A" },
- [/\d+/], { "B" },
- ['foo', 'bar'], { "C" },
- ['her'|'boo'], { "D" };
-
-is($d.add_rules(@rules), 4, "add list of rules, get the number added back");
-
-dies_ok( { $d.add_rules([1,2,3]) }, "die if you calling .add_rules an odd numbers of elements" );
-
-is($d.dispatch(['foo']), "A", "Dispatch rule ['foo']");
-is($d.dispatch(['123']), "B", "Dispatch rule /\\d+/");
-is($d.dispatch(['foo', 'bar']), "C", "Dispatch ['foo', 'bar']");
-is($d.dispatch(['boo']), "D", "Dispatch ['boo']");
-
-# vim:ft=perl6

0 comments on commit 59939ca

Please sign in to comment.