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

Unified Diff: tests/utils/uri_test.dart

Issue 10399077: URI encoder/decoder - copied from other repo. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « runtime/bin/uri_sources.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/utils/uri_test.dart
===================================================================
--- tests/utils/uri_test.dart (revision 7727)
+++ tests/utils/uri_test.dart (working copy)
@@ -4,6 +4,7 @@
#library('uriTest');
+#import('../../lib/utf/utf.dart');
#import('../../lib/uri/uri.dart');
testUri(String uri, bool isAbsolute) {
@@ -11,6 +12,20 @@
Expect.stringEquals(uri, new Uri.fromString(uri).toString());
}
+testEncodeDecode(String orig, String encoded) {
+ var e = encodeUri(orig);
+ Expect.stringEquals(encoded, e);
+ var d = decodeUri(encoded);
+ Expect.stringEquals(orig, d);
+}
+
+testEncodeDecodeComponent(String orig, String encoded) {
+ var e = encodeUriComponent(orig);
+ Expect.stringEquals(encoded, e);
+ var d = decodeUriComponent(encoded);
+ Expect.stringEquals(orig, d);
+}
+
main() {
testUri("http:", true);
testUri("file://", true);
@@ -90,4 +105,28 @@
// Additional tests (not from RFC 3986).
Expect.stringEquals("http://a/b/g;p/h;s",
base.resolve("../g;p/h;s").toString());
+
+ // URI encode tests
+ // Note: dart2js won't handle '\ud800\udc00' and frog
+ // won't handle '\u{10000}'. So we cons this up synthetically...
+ var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]);
+
+ testEncodeDecode("\uFFFE", "%EF%BF%BE");
+ testEncodeDecode("\uFFFF", "%EF%BF%BF");
+ testEncodeDecode("\uFFFE", "%EF%BF%BE");
+ testEncodeDecode("\uFFFF", "%EF%BF%BF");
+ testEncodeDecode("\x7f", "%7F");
+ testEncodeDecode("\x80", "%C2%80");
+ testEncodeDecode("\u0800", "%E0%A0%80");
+ testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$");
+ testEncodeDecode(s, "%F0%90%80%80");
+ testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE");
+ testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF");
+ testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE");
+ testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF");
+ testEncodeDecodeComponent("\x7f", "%7F");
+ testEncodeDecodeComponent("\x80", "%C2%80");
+ testEncodeDecodeComponent("\u0800", "%E0%A0%80");
+ testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24");
+ testEncodeDecodeComponent(s, "%F0%90%80%80");
}
« no previous file with comments | « runtime/bin/uri_sources.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698