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

Unified Diff: tests/corelib/uri_example_test.dart

Issue 2679933002: Update URI related documentation and examples. (Closed)
Patch Set: Don't escape backslashes in code-quotes. Created 3 years, 10 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 | « sdk/lib/core/uri.dart ('k') | tests/corelib/uri_file_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/uri_example_test.dart
diff --git a/tests/corelib/uri_example_test.dart b/tests/corelib/uri_example_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8868a9a398431f3db33954a1118c57c12f671044
--- /dev/null
+++ b/tests/corelib/uri_example_test.dart
@@ -0,0 +1,96 @@
+// Copyright (c) 2017, 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 uri.examples;
+
+// Examples from the Uri class documentation.
+// Get an error if the documentation starts to be wrong.
+// REMEMBER TO UPDATE BOTH.
+
+import "package:expect/expect.dart";
+import 'dart:convert';
+
+main() {
+ // Uri.http
+ test("http://example.org/path?q=dart",
+ new Uri.http("example.org", "/path", { "q" : "dart" }));
+ test("http://user:pass@localhost:8080",
+ new Uri.http("user:pass@localhost:8080", ""));
+ test("http://example.org/a%20b", new Uri.http("example.org", "a b"));
+ test("http://example.org/a%252F", new Uri.http("example.org", "/a%2F"));
+
+ // Uri.file
+ test("xxx/yyy", new Uri.file("xxx/yyy", windows: false));
+ test("xxx/yyy/", new Uri.file("xxx/yyy/", windows: false));
+ test("file:///xxx/yyy", new Uri.file("/xxx/yyy", windows: false));
+ test("file:///xxx/yyy/", new Uri.file("/xxx/yyy/", windows: false));
+ test("C%3A", new Uri.file("C:", windows: false));
+ test("xxx/yyy", new Uri.file(r"xxx\yyy", windows: true));
+ test("xxx/yyy/", new Uri.file(r"xxx\yyy\", windows: true));
+ test("file:///xxx/yyy", new Uri.file(r"\xxx\yyy", windows: true));
+ test("file:///xxx/yyy/", new Uri.file(r"\xxx\yyy/", windows: true));
+ test("file:///C:/xxx/yyy", new Uri.file(r"C:\xxx\yyy", windows: true));
+ test("file://server/share/file",
+ new Uri.file(r"\\server\share\file", windows: true));
+ Expect.throws(() => new Uri.file(r"C:", windows: true));
+ Expect.throws(() => new Uri.file(r"C:xxx\yyy", windows: true));
+
+ // isScheme.
+ var uri = Uri.parse("http://example.com/");
+ Expect.isTrue(uri.isScheme("HTTP"));
+
+ // toFilePath.
+ Expect.equals(r"xxx/yyy", Uri.parse("xxx/yyy").toFilePath(windows: false));
+ Expect.equals(r"xxx/yyy/", Uri.parse("xxx/yyy/").toFilePath(windows: false));
+ Expect.equals(r"/xxx/yyy",
+ Uri.parse("file:///xxx/yyy").toFilePath(windows: false));
+ Expect.equals(r"/xxx/yyy/",
+ Uri.parse("file:///xxx/yyy/").toFilePath(windows: false));
+ Expect.equals(r"/C:", Uri.parse("file:///C:").toFilePath(windows: false));
+ Expect.equals(r"/C:a", Uri.parse("file:///C:a").toFilePath(windows: false));
+
+ Expect.equals(r"xxx\yyy", Uri.parse("xxx/yyy").toFilePath(windows: true));
+ Expect.equals(r"xxx\yyy\", Uri.parse("xxx/yyy/").toFilePath(windows: true));
+ Expect.equals(r"\xxx\yyy",
+ Uri.parse("file:///xxx/yyy").toFilePath(windows: true));
+ Expect.equals(r"\xxx\yyy\",
+ Uri.parse("file:///xxx/yyy/").toFilePath(windows: true));
+ Expect.equals(r"C:\xxx\yyy",
+ Uri.parse("file:///C:/xxx/yyy").toFilePath(windows: true));
+ Expect.throws(() => Uri.parse("file:C:xxx/yyy").toFilePath(windows: true));
+ Expect.equals(r"\\server\share\file",
+ Uri.parse("file://server/share/file").toFilePath(windows: true)); //
+
+ // replace.
+ Uri uri1 = Uri.parse("a://b@c:4/d/e?f#g");
+ Uri uri2 = uri1.replace(scheme: "A", path: "D/E/E", fragment: "G");
+ Expect.equals("a://b@c:4/D/E/E?f#G", "$uri2");
+ Uri uri3 = new Uri(
+ scheme: "A",
+ userInfo: uri1.userInfo,
+ host: uri1.host,
+ port: uri1.port,
+ path: "D/E/E",
+ query: uri1.query,
+ fragment: "G");
+ Expect.equals("a://b@c:4/D/E/E?f#G", "$uri3");
+ Expect.equals(uri2, uri3);
+
+ // UriData.mimeType
+ var data = UriData.parse("data:text/plain;charset=utf-8,Hello%20World!");
+ Expect.equals("text/plain", data.mimeType);
+ Expect.equals("utf-8", data.charset);
+
+ // Uri.parseIPv6Address - shouldn't throw.
+ Uri.parseIPv6Address("::1");
+ Uri.parseIPv6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210");
+ Uri.parseIPv6Address("3ffe:2a00:100:7031::1");
+ Uri.parseIPv6Address("::FFFF:129.144.52.38");
+ Uri.parseIPv6Address("2010:836B:4179::836B:4179");
+}
+
+test(String result, Uri value) {
+ Expect.equals(Uri.parse(result), value);
+ Expect.equals(result, value.toString());
+}
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | tests/corelib/uri_file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698