Permalink
Browse files

Added new test suite based on examples in RFC 3986 and fixed parser f…

…ailure

from a token trying to backtrack in IPv6.pm.
  • Loading branch information...
1 parent 9e4deeb commit e2fb82ddc526b2551ea2e5449e63a0805fabf90f U-ron-PC\ron committed May 21, 2009
Showing with 55 additions and 6 deletions.
  1. +9 −6 lib/IETF/RFC_Grammar/IPv6.pm
  2. +46 −0 t/rfc-3986-examples.t
View
15 lib/IETF/RFC_Grammar/IPv6.pm
@@ -8,14 +8,17 @@ grammar IETF::RFC_Grammar::IPv6 {
[ <.h16> ':' ] ** 6 <.ls32> |
'::' [ <.h16> ':' ] ** 5 <.ls32> |
[ <.h16> ]? '::' [ <.h16> ':' ] ** 4 <.ls32> |
- [ [ <.h16> ':' ]? <.h16> ]? '::' [ <.h16> ':' ] ** 3 <.ls32> |
- [ [ <.h16> ':' ] ** 0..2 <.h16> ]? '::' [ <.h16> ':' ] ** 2 <.ls32> |
- [ [ <.h16> ':' ] ** 0..3 <.h16> ]? '::' <.h16> ':' <.ls32> |
- [ [ <.h16> ':' ] ** 0..4 <.h16> ]? '::' <.ls32> |
- [ [ <.h16> ':' ] ** 0..5 <.h16> ]? '::' <.h16> |
- [ [ <.h16> ':' ] ** 0..6 <.h16> ]? '::'
+ [ [ <.sep_h16> ]? <.h16> ]? '::' [ <.h16> ':' ] ** 3 <.ls32> |
+ [ [ <.sep_h16> ] ** 0..2 <.h16> ]? '::' [ <.h16> ':' ] ** 2 <.ls32> |
+ [ [ <.sep_h16> ] ** 0..3 <.h16> ]? '::' <.h16> ':' <.ls32> |
+ [ [ <.sep_h16> ] ** 0..4 <.h16> ]? '::' <.ls32> |
+ [ [ <.sep_h16> ] ** 0..5 <.h16> ]? '::' <.h16> |
+ [ [ <.sep_h16> ] ** 0..6 <.h16> ]? '::'
};
+ # token avoiding backtracking happiness
+ token sep_h16 { [ <.h16> ':' <!before ':'>] }
+
token ls32 { [<.h16> ':' <.h16>] | <.IPv4address> };
token h16 { <.xdigit> ** 1..4 };
View
46 t/rfc-3986-examples.t
@@ -0,0 +1,46 @@
+use v6;
+use Test;
+plan 12;
+
+use URI;
+my $u = URI.new;
+
+$u.init('ftp://ftp.is.co.za/rfc/rfc1808.txt');
+is($u.scheme, 'ftp', 'ftp scheme');
+is($u.host, 'ftp.is.co.za', 'ftp host');
+is($u.path, '/rfc/rfc1808.txt', 'ftp path');
+
+$u.init('http://www.ietf.org/rfc/rfc2396.txt');
+is($u.scheme, 'http', 'http scheme');
+is($u.host, 'www.ietf.org', 'http host');
+is($u.path, '/rfc/rfc2396.txt', 'http path');
+
+$u.init('ldap://[2001:db8::7]/c=GB?objectClass?one');
+is($u.scheme, 'ldap', 'ldap scheme');
+is($u.host, '[2001:db8::7]', 'ldap host');
+is($u.path, '/c=gb', 'ldap path');
+is($u.query, 'objectClass?one', 'ldap query');
+
+$u.init('mailto:John.Doe@example.com');
+is($u.scheme, 'mailto', 'mailto scheme');
+is($u.path, 'john.doe@example.com', 'news path');
+
+$u.init('news:comp.infosystems.www.servers.unix');
+is($u.scheme, 'news', 'news scheme');
+is($u.path, 'comp.infosystems.www.servers.unix', 'news path');
+
+$u.init('tel:+1-816-555-1212');
+is($u.scheme, 'tel', 'telephone scheme');
+is($u.path, '+1-816-555-1212', 'telephone path');
+
+$u.init('telnet://192.0.2.16:80/');
+is($u.scheme, 'telnet', 'telnet scheme');
+is($u.authority, '192.0.2.16:80', 'telnet authority');
+is($u.host, '192.0.2.16', 'telnet host');
+is($u.port, '80', 'telnet port');
+
+$u.init('urn:oasis:names:specification:docbook:dtd:xml:4.1.2');
+is($u.scheme, 'urn', 'urn scheme');
+is($u.path, 'oasis:names:specification:docbook:dtd:xml:4.1.2', 'urn path');
+
+# vim:ft=perl6

0 comments on commit e2fb82d

Please sign in to comment.