Migrate test block 30 + corelib portion of block 31 to Dart 2.0.

Minor changes to uri_path_test and uri_query_test, and status file
updates.

BUG=
R=rnystrom@google.com

Review-Url: https://codereview.chromium.org/2983123002 .
This commit is contained in:
Ben Konyi 2017-07-20 08:07:34 -07:00
parent 239e044874
commit 4d64b9ee37
39 changed files with 19 additions and 2483 deletions

View file

@ -16,7 +16,6 @@ string_from_environment3_test: Skip
string_from_environment_test: Skip
[ $compiler == none || $compiler == precompiler || $compiler == app_jit ]
unicode_test: Fail # Bug 6706
symbol_test/01: Fail, Pass # bug 11669
# With the exception of 'void', new Symbol() should not accept reserved words.

View file

@ -1,96 +0,0 @@
// 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());
}

View file

@ -1,325 +0,0 @@
// Copyright (c) 2012, 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.
import "package:expect/expect.dart";
testFileUri() {
final unsupported = new UnsupportedError("");
var tests = [
["", "", ""],
["relative", "relative", "relative"],
["relative/", "relative/", "relative\\"],
["a%20b", "a b", "a b"],
["a%20b/", "a b/", "a b\\"],
["a/b", "a/b", "a\\b"],
["a/b/", "a/b/", "a\\b\\"],
["a%20b/c%20d", "a b/c d", "a b\\c d"],
["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"],
["file:///absolute", "/absolute", "\\absolute"],
["file:///absolute", "/absolute", "\\absolute"],
["file:///a/b", "/a/b", "\\a\\b"],
["file:///a/b", "/a/b", "\\a\\b"],
["file://server/a/b", unsupported, "\\\\server\\a\\b"],
["file://server/a/b/", unsupported, "\\\\server\\a\\b\\"],
["file:///C:/", "/C:/", "C:\\"],
["file:///C:/a/b", "/C:/a/b", "C:\\a\\b"],
["file:///C:/a/b/", "/C:/a/b/", "C:\\a\\b\\"],
["http:/a/b", unsupported, unsupported],
["https:/a/b", unsupported, unsupported],
["urn:a:b", unsupported, unsupported],
];
void check(String s, filePath, bool windows) {
Uri uri = Uri.parse(s);
if (filePath is Error) {
if (filePath is UnsupportedError) {
Expect.throws(() => uri.toFilePath(windows: windows),
(e) => e is UnsupportedError);
} else {
Expect.throws(() => uri.toFilePath(windows: windows));
}
} else {
Expect.equals(filePath, uri.toFilePath(windows: windows));
Expect.equals(s, new Uri.file(filePath, windows: windows).toString());
}
}
for (var test in tests) {
check(test[0], test[1], false);
check(test[0], test[2], true);
}
Uri uri;
uri = Uri.parse("file:a");
Expect.equals("/a", uri.toFilePath(windows: false));
Expect.equals("\\a", uri.toFilePath(windows: true));
uri = Uri.parse("file:a/");
Expect.equals("/a/", uri.toFilePath(windows: false));
Expect.equals("\\a\\", uri.toFilePath(windows: true));
}
testFileUriWindowsSlash() {
var tests = [
["", "", ""],
["relative", "relative", "relative"],
["relative/", "relative/", "relative\\"],
["a%20b", "a b", "a b"],
["a%20b/", "a b/", "a b\\"],
["a/b", "a/b", "a\\b"],
["a/b/", "a/b/", "a\\b\\"],
["a%20b/c%20d", "a b/c d", "a b\\c d"],
["a%20b/c%20d/", "a b/c d/", "a b\\c d\\"],
["file:///absolute", "/absolute", "\\absolute"],
["file:///absolute", "/absolute", "\\absolute"],
["file:///a/b", "/a/b", "\\a\\b"],
["file:///a/b", "/a/b", "\\a\\b"],
["file://server/a/b", "//server/a/b", "\\\\server\\a\\b"],
["file://server/a/b/", "//server/a/b/", "\\\\server\\a\\b\\"],
["file:///C:/", "C:/", "C:\\"],
["file:///C:/a/b", "C:/a/b", "C:\\a\\b"],
["file:///C:/a/b/", "C:/a/b/", "C:\\a\\b\\"],
["file:///C:/xxx/yyy", "C:\\xxx\\yyy", "C:\\xxx\\yyy"],
];
for (var test in tests) {
Uri uri = new Uri.file(test[1], windows: true);
Expect.equals(test[0], uri.toString());
Expect.equals(test[2], uri.toFilePath(windows: true));
bool couldBeDir = uri.path.isEmpty || uri.path.endsWith('\\');
Uri dirUri = new Uri.directory(test[1], windows: true);
Expect.isTrue(dirUri.path.isEmpty || dirUri.path.endsWith('/'));
if (couldBeDir) {
Expect.equals(uri, dirUri);
}
}
}
testFileUriWindowsWin32Namespace() {
var tests = [
["\\\\?\\C:\\", "file:///C:/", "C:\\"],
["\\\\?\\C:\\", "file:///C:/", "C:\\"],
[
"\\\\?\\UNC\\server\\share\\file",
"file://server/share/file",
"\\\\server\\share\\file"
],
];
for (var test in tests) {
Uri uri = new Uri.file(test[0], windows: true);
Expect.equals(test[1], uri.toString());
Expect.equals(test[2], uri.toFilePath(windows: true));
}
Expect.throws(() => new Uri.file("\\\\?\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("\\\\?\\UNX\\server\\share\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\\\?\\file", windows: true),
(e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("\\\\?\\UNX\\server\\share\\file", windows: true),
(e) => e is ArgumentError);
}
testFileUriDriveLetter() {
check(String s, String nonWindows, String windows) {
Uri uri;
uri = Uri.parse(s);
Expect.equals(nonWindows, uri.toFilePath(windows: false));
if (windows != null) {
Expect.equals(windows, uri.toFilePath(windows: true));
} else {
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
}
}
check("file:///C:", "/C:", "C:\\");
check("file:///C:/", "/C:/", "C:\\");
check("file:///C:a", "/C:a", null);
check("file:///C:a/", "/C:a/", null);
Expect.throws(
() => new Uri.file("C:", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("C:a", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.file("C:a\b", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("C:", windows: true), (e) => e is ArgumentError);
Expect.throws(
() => new Uri.directory("C:a", windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("C:a\b", windows: true),
(e) => e is ArgumentError);
}
testFileUriResolve() {
var tests = [
["file:///a", "/a", "", "\\a", ""],
["file:///a/", "/a/", "", "\\a\\", ""],
["file:///b", "/a", "b", "\\a", "b"],
["file:///b/", "/a", "b/", "\\a", "b\\"],
["file:///a/b", "/a/", "b", "\\a\\", "b"],
["file:///a/b/", "/a/", "b/", "\\a\\", "b\\"],
["file:///a/c/d", "/a/b", "c/d", "\\a\\b", "c\\d"],
["file:///a/c/d/", "/a/b", "c/d/", "\\a\\b", "c\\d\\"],
["file:///a/b/c/d", "/a/b/", "c/d", "\\a\\b\\", "c\\d"],
["file:///a/b/c/d/", "/a/b/", "c/d/", "\\a\\b\\", "c\\d\\"],
];
check(String s, String absolute, String relative, bool windows) {
Uri absoluteUri = new Uri.file(absolute, windows: windows);
Uri relativeUri = new Uri.file(relative, windows: windows);
String relativeString = windows ? relative.replaceAll("\\", "/") : relative;
Expect.equals(s, absoluteUri.resolve(relativeString).toString());
Expect.equals(s, absoluteUri.resolveUri(relativeUri).toString());
}
for (var test in tests) {
check(test[0], test[1], test[2], false);
check(test[0], test[1], test[2], true);
check(test[0], test[1], test[4], true);
check(test[0], test[3], test[2], true);
check(test[0], test[3], test[4], true);
}
}
testFileUriIllegalCharacters() {
// Slash is an invalid character in file names on both non-Windows
// and Windows.
Uri uri = Uri.parse("file:///a%2Fb");
Expect.throws(
() => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
// Illegal characters in windows file names.
var illegalWindowsPaths = [
"a<b",
"a>b",
"a:b",
"a\"b",
"a|b",
"a?b",
"a*b",
"\\\\?\\c:\\a/b"
];
for (var test in illegalWindowsPaths) {
Expect.throws(
() => new Uri.file(test, windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.file("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory(test, windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\$test", windows: true),
(e) => e is ArgumentError);
// It is possible to create non-Windows URIs, but not Windows URIs.
Uri uri = new Uri.file(test, windows: false);
Uri absoluteUri = new Uri.file("/$test", windows: false);
Uri dirUri = new Uri.directory(test, windows: false);
Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
Expect.throws(
() => new Uri.file(test, windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.file("\\$test", windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory(test, windows: true),
(e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("\\$test", windows: true),
(e) => e is ArgumentError);
// It is possible to extract non-Windows file path, but not
// Windows file path.
Expect.equals(test, uri.toFilePath(windows: false));
Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
Expect.equals("$test/", dirUri.toFilePath(windows: false));
Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => absoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
}
// Backslash
illegalWindowsPaths = ["a\\b", "a\\b\\"];
for (var test in illegalWindowsPaths) {
// It is possible to create both non-Windows URIs, and Windows URIs.
Uri uri = new Uri.file(test, windows: false);
Uri absoluteUri = new Uri.file("/$test", windows: false);
Uri dirUri = new Uri.directory(test, windows: false);
Uri dirAbsoluteUri = new Uri.directory("/$test", windows: false);
new Uri.file(test, windows: true);
new Uri.file("\\$test", windows: true);
// It is possible to extract non-Windows file path, but not
// Windows file path from the non-Windows URI (it has a backslash
// in a path segment).
Expect.equals(test, uri.toFilePath(windows: false));
Expect.equals("/$test", absoluteUri.toFilePath(windows: false));
Expect.equals("$test/", dirUri.toFilePath(windows: false));
Expect.equals("/$test/", dirAbsoluteUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => absoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(() => dirAbsoluteUri.toFilePath(windows: true),
(e) => e is UnsupportedError);
}
}
testFileUriIllegalDriveLetter() {
Expect.throws(
() => new Uri.file("1:\\", windows: true), (e) => e is ArgumentError);
Expect.throws(() => new Uri.directory("1:\\", windows: true),
(e) => e is ArgumentError);
Uri uri = new Uri.file("1:\\", windows: false);
Uri dirUri = new Uri.directory("1:\\", windows: false);
Expect.equals("1:\\", uri.toFilePath(windows: false));
Expect.equals("1:\\/", dirUri.toFilePath(windows: false));
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
Expect.throws(
() => dirUri.toFilePath(windows: true), (e) => e is UnsupportedError);
}
testAdditionalComponents() {
check(String s, {bool windowsOk: false}) {
Uri uri = Uri.parse(s);
Expect.throws(
() => uri.toFilePath(windows: false), (e) => e is UnsupportedError);
if (windowsOk) {
Expect.isTrue(uri.toFilePath(windows: true) is String);
} else {
Expect.throws(
() => uri.toFilePath(windows: true), (e) => e is UnsupportedError);
}
}
check("file:///path?query");
check("file:///path#fragment");
check("file:///path?query#fragment");
check("file://host/path", windowsOk: true);
check("file://user:password@host/path", windowsOk: true);
}
main() {
testFileUri();
testFileUriWindowsSlash();
testFileUriDriveLetter();
testFileUriWindowsWin32Namespace();
testFileUriResolve();
testFileUriIllegalCharacters();
testFileUriIllegalDriveLetter();
testAdditionalComponents();
}

View file

@ -1,188 +0,0 @@
// Copyright (c) 2013, 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.
import "dart:collection";
import "package:expect/expect.dart";
void testInvalidArguments() {}
void testPath() {
void test(s, uri) {
Expect.equals(s, uri.toString());
Expect.equals(uri, Uri.parse(s));
}
test("http:", new Uri(scheme: "http"));
test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "xxx"));
test("http://host/xxx", new Uri(scheme: "http", host: "host", path: "/xxx"));
test("http://host/xxx",
new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]));
test("http://host/xxx/yyy",
new Uri(scheme: "http", host: "host", path: "xxx/yyy"));
test("http://host/xxx/yyy",
new Uri(scheme: "http", host: "host", path: "/xxx/yyy"));
test("http://host/xxx/yyy",
new Uri(scheme: "http", host: "host", pathSegments: ["xxx", "yyy"]));
test("urn:", new Uri(scheme: "urn"));
test("urn:xxx", new Uri(scheme: "urn", path: "xxx"));
test("urn:xxx:yyy", new Uri(scheme: "urn", path: "xxx:yyy"));
Expect.equals(3, new Uri(path: "xxx/yyy/zzz").pathSegments.length);
Expect.equals(3, new Uri(path: "/xxx/yyy/zzz").pathSegments.length);
Expect.equals(3, Uri.parse("http://host/xxx/yyy/zzz").pathSegments.length);
Expect.equals(3, Uri.parse("file:///xxx/yyy/zzz").pathSegments.length);
}
void testPathSegments() {
void test(String path, List<String> segments) {
void check(uri) {
Expect.equals(path, uri.path);
Expect.equals(path, uri.toString());
Expect.listEquals(segments, uri.pathSegments);
}
var uri1 = new Uri(pathSegments: segments);
var uri2 = new Uri(path: path);
check(uri1);
check(uri2);
Expect.equals(uri1, uri2);
}
test("", []);
test("%20", [" "]);
test("%20/%20%20", [" ", " "]);
test("A", ["A"]);
test("%C3%B8", ["ø"]);
test("%C3%B8/%C3%A5", ["ø", "å"]);
test("%C8%A4/%E5%B9%B3%E4%BB%AE%E5%90%8D", ["Ȥ", "平仮名"]);
test("A/b", ["A", "b"]);
test("A/%25", ["A", "%"]);
test("%2F/a%2Fb", ["/", "a/b"]);
test("name;v=1.1", ["name;v=1.1"]);
test("name,v=1.1", ["name,v=1.1"]);
test("name;v=1.1/name,v=1.1", ["name;v=1.1", "name,v=1.1"]);
var unreserved = "-._~0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
var subDelimiters = r"!$&'()*+,;=";
var additionalPathChars = ":@";
var pchar = unreserved + subDelimiters + additionalPathChars;
var encoded = new StringBuffer();
var unencoded = new StringBuffer();
for (int i = 32; i < 128; i++) {
if (pchar.indexOf(new String.fromCharCode(i)) != -1) {
encoded.writeCharCode(i);
} else {
encoded.write("%");
encoded.write(i.toRadixString(16).toUpperCase());
}
unencoded.writeCharCode(i);
}
encoded = encoded.toString();
unencoded = unencoded.toString();
test(encoded, [unencoded]);
test(encoded + "/" + encoded, [unencoded, unencoded]);
Uri uri;
List pathSegments = ["xxx", "yyy", "zzz"];
uri = new Uri(pathSegments: pathSegments);
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(pathSegments: pathSegments.where((_) => true));
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(pathSegments: new DoubleLinkedQueue.from(pathSegments));
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(scheme: "http", host: "host", pathSegments: pathSegments);
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(
scheme: "http",
host: "host",
pathSegments: pathSegments.where((_) => true));
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(
scheme: "http",
host: "host",
pathSegments: new DoubleLinkedQueue.from(pathSegments));
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(scheme: "file", pathSegments: pathSegments);
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(scheme: "file", pathSegments: pathSegments.where((_) => true));
Expect.equals(3, uri.pathSegments.length);
uri = new Uri(
scheme: "file", pathSegments: new DoubleLinkedQueue.from(pathSegments));
Expect.equals(3, uri.pathSegments.length);
}
void testPathCompare() {
void test(Uri uri1, Uri uri2) {
Expect.equals(uri1, uri2);
Expect.equals(uri2, uri1);
}
test(new Uri(scheme: "http", host: "host", path: "xxx"),
new Uri(scheme: "http", host: "host", path: "/xxx"));
test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]),
new Uri(scheme: "http", host: "host", path: "/xxx"));
test(new Uri(scheme: "http", host: "host", pathSegments: ["xxx"]),
new Uri(scheme: "http", host: "host", path: "xxx"));
test(new Uri(scheme: "file", path: "xxx"),
new Uri(scheme: "file", path: "/xxx"));
test(new Uri(scheme: "file", pathSegments: ["xxx"]),
new Uri(scheme: "file", path: "/xxx"));
test(new Uri(scheme: "file", pathSegments: ["xxx"]),
new Uri(scheme: "file", path: "xxx"));
}
testPathSegmentsUnmodifiableList() {
void test(list) {
bool isUnsupported(e) => e is UnsupportedError;
Expect.equals("a", list[0]);
Expect.throws(() => list[0] = "c", isUnsupported);
Expect.equals(2, list.length);
Expect.throws(() => list.length = 1, isUnsupported);
Expect.throws(() => list.add("c"), isUnsupported);
Expect.throws(() => list.addAll(["c", "d"]), isUnsupported);
Expect.listEquals(["b", "a"], list.reversed.toList());
Expect.throws(() => list.sort(), isUnsupported);
Expect.equals(0, list.indexOf("a"));
Expect.equals(0, list.lastIndexOf("a"));
Expect.throws(() => list.clear(), isUnsupported);
Expect.throws(() => list.insert(1, "c"), isUnsupported);
Expect.throws(() => list.insertAll(1, ["c", "d"]), isUnsupported);
Expect.throws(() => list.setAll(1, ["c", "d"]), isUnsupported);
Expect.throws(() => list.remove("a"), isUnsupported);
Expect.throws(() => list.removeAt(0), isUnsupported);
Expect.throws(() => list.removeLast(), isUnsupported);
Expect.throws(() => list.removeWhere((e) => true), isUnsupported);
Expect.throws(() => list.retainWhere((e) => false), isUnsupported);
Expect.listEquals(["a"], list.sublist(0, 1));
Expect.listEquals(["a"], list.getRange(0, 1).toList());
Expect.throws(() => list.setRange(0, 1, ["c"]), isUnsupported);
Expect.throws(() => list.removeRange(0, 1), isUnsupported);
Expect.throws(() => list.fillRange(0, 1, "c"), isUnsupported);
Expect.throws(() => list.replaceRange(0, 1, ["c"]), isUnsupported);
Map map = new Map();
map[0] = "a";
map[1] = "b";
Expect.mapEquals(list.asMap(), map);
}
test(Uri.parse("a/b").pathSegments);
test(new Uri(pathSegments: ["a", "b"]).pathSegments);
}
main() {
testInvalidArguments();
testPath();
testPathSegments();
testPathCompare();
testPathSegmentsUnmodifiableList();
}

View file

@ -1,182 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
void testInvalidArguments() {}
void testEncodeQueryComponent() {
// This exact data is from posting a form in Chrome 26 with the one
// exception that * is encoded as %30 and ~ is not encoded as %7E.
Expect.equals(
"%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F%"
"3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~",
Uri.encodeQueryComponent("!\"#\$%&'()*+,-./:;<=>?@[\\]^_`{|}~"));
Expect.equals("+%2B+", Uri.encodeQueryComponent(" + "));
Expect.equals("%2B+%2B", Uri.encodeQueryComponent("+ +"));
}
void testQueryParameters() {
test(String query, Map<String, String> parameters, [String normalizedQuery]) {
if (normalizedQuery == null) normalizedQuery = query;
check(uri) {
Expect.isTrue(uri.hasQuery);
Expect.equals(normalizedQuery, uri.query);
Expect.equals("?$normalizedQuery", uri.toString());
if (parameters.containsValue(null)) {
var map = new Map.from(parameters);
map.forEach((k, v) {
if (v == null) map[k] = "";
});
Expect.mapEquals(map, uri.queryParameters);
} else {
Expect.mapEquals(parameters, uri.queryParameters);
}
}
var uri1 = new Uri(queryParameters: parameters);
var uri2 = new Uri(query: query);
var uri3 = Uri.parse("?$query");
check(uri1);
if (query != "") {
check(uri2);
} else {
Expect.isFalse(uri2.hasQuery);
}
check(uri3);
Expect.equals(uri1, uri3);
if (query != "") Expect.equals(uri2, uri3);
if (parameters.containsValue(null)) {
var map = new Map.from(parameters);
map.forEach((k, v) {
if (v == null) map[k] = "";
});
Expect.mapEquals(map, Uri.splitQueryString(query));
} else {
Expect.mapEquals(parameters, Uri.splitQueryString(query));
}
}
test("", {});
test("A", {"A": null});
test("%25", {"%": null});
test("%41", {"A": null}, "A");
test("%41A", {"AA": null}, "AA");
test("A", {"A": ""});
test("%25", {"%": ""});
test("%41", {"A": ""}, "A");
test("%41A", {"AA": ""}, "AA");
test("A=a", {"A": "a"});
test("%25=a", {"%": "a"});
test("%41=%61", {"A": "a"}, "A=a");
test("A=+", {"A": " "});
test("A=%2B", {"A": "+"});
test("A=a&B", {"A": "a", "B": null});
test("A=a&B", {"A": "a", "B": ""});
test("A=a&B=b", {"A": "a", "B": "b"});
test("%41=%61&%42=%62", {"A": "a", "B": "b"}, "A=a&B=b");
var unreserved = "-._~0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
var encoded = new StringBuffer();
var allEncoded = new StringBuffer();
var unencoded = new StringBuffer();
for (int i = 32; i < 128; i++) {
if (i == 32) {
encoded.write("+");
} else if (unreserved.indexOf(new String.fromCharCode(i)) != -1) {
encoded.writeCharCode(i);
} else {
encoded.write("%");
encoded.write(i.toRadixString(16).toUpperCase());
}
if (i == 32) {
allEncoded.write("+");
} else {
allEncoded.write("%");
allEncoded.write(i.toRadixString(16).toUpperCase());
}
unencoded.writeCharCode(i);
}
encoded = encoded.toString();
unencoded = unencoded.toString();
test("a=$encoded", {"a": unencoded});
test("a=$encoded&b=$encoded", {"a": unencoded, "b": unencoded});
var map = new Map();
map[unencoded] = unencoded;
test("$encoded=$encoded", map);
test("$encoded=$allEncoded", map, "$encoded=$encoded");
test("$allEncoded=$encoded", map, "$encoded=$encoded");
test("$allEncoded=$allEncoded", map, "$encoded=$encoded");
map[unencoded] = null;
test("$encoded", map);
map[unencoded] = "";
test("$encoded", map);
}
testInvalidQueryParameters() {
test(String query, Map<String, String> parameters) {
check(uri) {
Expect.equals(query, uri.query);
if (query.isEmpty) {
Expect.equals(query, uri.toString());
} else {
Expect.equals("?$query", uri.toString());
}
if (parameters.containsValue(null)) {} else {
Expect.mapEquals(parameters, uri.queryParameters);
}
}
var uri1 = new Uri(query: query);
var uri2 = Uri.parse("?$query");
check(uri1);
check(uri2);
Expect.equals(uri1, uri2);
}
test("=", {});
test("=xxx", {});
test("===", {});
test("=xxx=yyy=zzz", {});
test("=&=&=", {});
test("=xxx&=yyy&=zzz", {});
test("&=&=&", {});
test("&=xxx&=xxx&", {});
}
testQueryParametersImmutableMap() {
test(map) {
bool isUnsupported(e) => e is UnsupportedError;
Expect.isTrue(map.containsValue("b"));
Expect.isTrue(map.containsKey("a"));
Expect.equals("b", map["a"]);
Expect.throws(() => map["a"] = "c", isUnsupported);
Expect.throws(() => map.putIfAbsent("b", () => "e"), isUnsupported);
Expect.throws(() => map.remove("a"), isUnsupported);
Expect.throws(() => map.clear(), isUnsupported);
var count = 0;
map.forEach((key, value) => count++);
Expect.equals(2, count);
Expect.equals(2, map.keys.length);
Expect.equals(2, map.values.length);
Expect.equals(2, map.length);
Expect.isFalse(map.isEmpty);
Expect.isTrue(map.isNotEmpty);
}
test(Uri.parse("?a=b&c=d").queryParameters);
test(new Uri(queryParameters: {"a": "b", "c": "d"}).queryParameters);
}
main() {
testInvalidArguments();
testEncodeQueryComponent();
testQueryParameters();
testInvalidQueryParameters();
testQueryParametersImmutableMap();
}

View file

@ -1,975 +0,0 @@
// Copyright (c) 2012, 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 uriTest;
import "package:expect/expect.dart";
import 'dart:convert';
testUri(String uriText, bool isAbsolute) {
var uri = Uri.parse(uriText);
// Test that parsing a substring works the same as parsing the string.
String wrapper = "://@[]:/%?#";
var embeddedUri = Uri.parse(
"$wrapper$uri$wrapper", wrapper.length, uriText.length + wrapper.length);
Expect.equals(uri, embeddedUri);
Expect.equals(isAbsolute, uri.isAbsolute);
Expect.stringEquals(uriText, uri.toString());
// Test equals and hashCode members.
var uri2 = Uri.parse(uriText);
Expect.equals(uri, uri2);
Expect.equals(uri.hashCode, uri2.hashCode);
// Test that removeFragment doesn't change anything else.
if (uri.hasFragment) {
Expect.equals(Uri.parse(uriText.substring(0, uriText.indexOf('#'))),
uri.removeFragment());
} else {
Expect.equals(uri, Uri.parse(uriText + "#fragment").removeFragment());
}
Expect.isTrue(uri.isScheme(uri.scheme));
Expect.isTrue(uri.isScheme(uri.scheme.toLowerCase()));
Expect.isTrue(uri.isScheme(uri.scheme.toUpperCase()));
if (uri.hasScheme) {
// Capitalize
Expect.isTrue(
uri.isScheme(uri.scheme[0].toUpperCase() + uri.scheme.substring(1)));
Expect
.isFalse(uri.isScheme(uri.scheme.substring(0, uri.scheme.length - 1)));
Expect.isFalse(uri.isScheme(uri.scheme + ":"));
Expect.isFalse(uri.isScheme(uri.scheme + "\x00"));
} else {
Expect.isTrue(uri.isScheme(null));
Expect.isFalse(uri.isScheme(":"));
}
}
testEncodeDecode(String orig, String encoded) {
var e = Uri.encodeFull(orig);
Expect.stringEquals(encoded, e);
var d = Uri.decodeFull(encoded);
Expect.stringEquals(orig, d);
}
testEncodeDecodeComponent(String orig, String encoded) {
var e = Uri.encodeComponent(orig);
Expect.stringEquals(encoded, e);
var d = Uri.decodeComponent(encoded);
Expect.stringEquals(orig, d);
}
testEncodeDecodeQueryComponent(String orig, String encodedUTF8,
String encodedLatin1, String encodedAscii) {
var e, d;
e = Uri.encodeQueryComponent(orig);
Expect.stringEquals(encodedUTF8, e);
d = Uri.decodeQueryComponent(encodedUTF8);
Expect.stringEquals(orig, d);
e = Uri.encodeQueryComponent(orig, encoding: UTF8);
Expect.stringEquals(encodedUTF8, e);
d = Uri.decodeQueryComponent(encodedUTF8, encoding: UTF8);
Expect.stringEquals(orig, d);
e = Uri.encodeQueryComponent(orig, encoding: LATIN1);
Expect.stringEquals(encodedLatin1, e);
d = Uri.decodeQueryComponent(encodedLatin1, encoding: LATIN1);
Expect.stringEquals(orig, d);
if (encodedAscii != null) {
e = Uri.encodeQueryComponent(orig, encoding: ASCII);
Expect.stringEquals(encodedAscii, e);
d = Uri.decodeQueryComponent(encodedAscii, encoding: ASCII);
Expect.stringEquals(orig, d);
} else {
Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII),
(e) => e is ArgumentError);
}
}
testUriPerRFCs() {
// Convert a Uri to a guaranteed "non simple" URI with the same content.
toComplex(Uri uri) {
Uri complex = new Uri(
scheme: uri.scheme,
userInfo: uri.hasAuthority ? uri.userInfo : null,
host: uri.hasAuthority ? uri.host : null,
port: uri.hasAuthority ? uri.port : null,
path: uri.path,
query: uri.hasQuery ? uri.query : null,
fragment: uri.hasFragment ? uri.fragment : null,
);
assert(complex.toString() == uri.toString());
return complex;
}
Uri base;
Uri complexBase;
// Sets the [base] and [complexBase] to the parse of the URI and a
// guaranteed non-simple version of the same URI.
setBase(String uri) {
base = Uri.parse(uri);
complexBase = toComplex(base);
}
testResolve(expect, relative) {
String name = "$base << $relative";
Expect.stringEquals(expect, base.resolve(relative).toString(), name);
Expect.stringEquals(expect, complexBase.resolve(relative).toString(),
name + " (complex base)");
}
// From RFC 3986.
final urisSample = "http://a/b/c/d;p?q";
setBase(urisSample);
testResolve("g:h", "g:h");
testResolve("http://a/b/c/g", "g");
testResolve("http://a/b/c/g", "./g");
testResolve("http://a/b/c/g/", "g/");
testResolve("http://a/g", "/g");
testResolve("http://g", "//g");
testResolve("http://a/b/c/d;p?y", "?y");
testResolve("http://a/b/c/g?y", "g?y");
testResolve("http://a/b/c/d;p?q#s", "#s");
testResolve("http://a/b/c/g#s", "g#s");
testResolve("http://a/b/c/g?y#s", "g?y#s");
testResolve("http://a/b/c/;x", ";x");
testResolve("http://a/b/c/g;x", "g;x");
testResolve("http://a/b/c/g;x?y#s", "g;x?y#s");
testResolve("http://a/b/c/d;p?q", "");
testResolve("http://a/b/c/", ".");
testResolve("http://a/b/c/", "./");
testResolve("http://a/b/", "..");
testResolve("http://a/b/", "../");
testResolve("http://a/b/g", "../g");
testResolve("http://a/", "../..");
testResolve("http://a/", "../../");
testResolve("http://a/g", "../../g");
testResolve("http://a/g", "../../../g");
testResolve("http://a/g", "../../../../g");
testResolve("http://a/g", "/./g");
testResolve("http://a/g", "/../g");
testResolve("http://a/b/c/g.", "g.");
testResolve("http://a/b/c/.g", ".g");
testResolve("http://a/b/c/g..", "g..");
testResolve("http://a/b/c/..g", "..g");
testResolve("http://a/b/g", "./../g");
testResolve("http://a/b/c/g/", "./g/.");
testResolve("http://a/b/c/g/h", "g/./h");
testResolve("http://a/b/c/h", "g/../h");
testResolve("http://a/b/c/g;x=1/y", "g;x=1/./y");
testResolve("http://a/b/c/y", "g;x=1/../y");
testResolve("http://a/b/c/g?y/./x", "g?y/./x");
testResolve("http://a/b/c/g?y/../x", "g?y/../x");
testResolve("http://a/b/c/g#s/./x", "g#s/./x");
testResolve("http://a/b/c/g#s/../x", "g#s/../x");
testResolve("http:g", "http:g");
// Additional tests (not from RFC 3986).
testResolve("http://a/b/g;p/h;s", "../g;p/h;s");
setBase("s:a/b");
testResolve("s:a/c", "c");
testResolve("s:/c", "../c");
setBase("S:a/b");
testResolve("s:a/c", "c");
testResolve("s:/c", "../c");
setBase("s:foo");
testResolve("s:bar", "bar");
testResolve("s:bar", "../bar");
setBase("S:foo");
testResolve("s:bar", "bar");
testResolve("s:bar", "../bar");
// Special-case (deliberate non-RFC behavior).
setBase("foo/bar");
testResolve("foo/baz", "baz");
testResolve("baz", "../baz");
setBase("s:/foo");
testResolve("s:/bar", "bar");
testResolve("s:/bar", "../bar");
setBase("S:/foo");
testResolve("s:/bar", "bar");
testResolve("s:/bar", "../bar");
// Test non-URI base (no scheme, no authority, relative path).
setBase("a/b/c?_#_");
testResolve("a/b/g?q#f", "g?q#f");
testResolve("./", "../..");
testResolve("../", "../../..");
testResolve("a/b/", ".");
testResolve("c", "../../c"); // Deliberate non-RFC behavior.
setBase("../../a/b/c?_#_"); // Initial ".." in base url.
testResolve("../../a/d", "../d");
testResolve("../../d", "../../d");
testResolve("../../../d", "../../../d");
setBase("../../a/b");
testResolve("../../a/d", "d");
testResolve("../../d", "../d");
testResolve("../../../d", "../../d");
setBase("../../a");
testResolve("../../d", "d");
testResolve("../../../d", "../d");
testResolve("../../../../d", "../../d");
// Absolute path, not scheme or authority.
setBase("/a");
testResolve("/b", "b");
testResolve("/b", "../b");
testResolve("/b", "../../b");
setBase("/a/b");
testResolve("/a/c", "c");
testResolve("/c", "../c");
testResolve("/c", "../../c");
setBase("s://h/p?q#f"); // A simple base.
// Simple references:
testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F");
testResolve("s://h2/P?Q#F", "//h2/P?Q#F");
testResolve("s://h/P?Q#F", "/P?Q#F");
testResolve("s://h/p?Q#F", "?Q#F");
testResolve("s://h/p?q#F", "#F");
testResolve("s://h/p?q", "");
// Non-simple references:
testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20");
testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20");
testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20");
testResolve("s://h/P?Q#F%20", "/P?Q#F%20");
testResolve("s://h/p?Q#F%20", "?Q#F%20");
testResolve("s://h/p?q#F%20", "#F%20");
setBase("s://h/p1/p2/p3"); // A simple base with a path.
testResolve("s://h/p1/p2/", ".");
testResolve("s://h/p1/p2/", "./");
testResolve("s://h/p1/", "..");
testResolve("s://h/p1/", "../");
testResolve("s://h/", "../..");
testResolve("s://h/", "../../");
testResolve("s://h/p1/%20", "../%20");
testResolve("s://h/", "../../../..");
testResolve("s://h/", "../../../../");
setBase("s://h/p?q#f%20"); // A non-simpe base.
// Simple references:
testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F");
testResolve("s://h2/P?Q#F", "//h2/P?Q#F");
testResolve("s://h/P?Q#F", "/P?Q#F");
testResolve("s://h/p?Q#F", "?Q#F");
testResolve("s://h/p?q#F", "#F");
testResolve("s://h/p?q", "");
// Non-simple references:
testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20");
testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20");
testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20");
testResolve("s://h/P?Q#F%20", "/P?Q#F%20");
testResolve("s://h/p?Q#F%20", "?Q#F%20");
testResolve("s://h/p?q#F%20", "#F%20");
setBase("S://h/p1/p2/p3"); // A non-simple base with a path.
testResolve("s://h/p1/p2/", ".");
testResolve("s://h/p1/p2/", "./");
testResolve("s://h/p1/", "..");
testResolve("s://h/p1/", "../");
testResolve("s://h/", "../..");
testResolve("s://h/", "../../");
testResolve("s://h/p1/%20", "../%20");
testResolve("s://h/", "../../../..");
testResolve("s://h/", "../../../../");
setBase("../../../"); // A simple relative path.
testResolve("../../../a", "a");
testResolve("../../../../a", "../a");
testResolve("../../../a%20", "a%20");
testResolve("../../../../a%20", "../a%20");
// Tests covering the branches of the merge algorithm in RFC 3986
// with both simple and complex base URIs.
for (var b in ["s://a/pa/pb?q#f", "s://a/pa/pb?q#f%20"]) {
setBase(b);
// if defined(R.scheme) then ...
testResolve("s2://a2/p2?q2#f2", "s2://a2/p2?q2#f2");
// else, if defined(R.authority) then ...
testResolve("s://a2/p2?q2#f2", "//a2/p2?q2#f2");
testResolve("s://a2/?q2#f2", "//a2/../?q2#f2");
testResolve("s://a2?q2#f2", "//a2?q2#f2");
testResolve("s://a2#f2", "//a2#f2");
testResolve("s://a2", "//a2");
// else, if (R.path == "") then ...
// if defined(R.query) then
testResolve("s://a/pa/pb?q2#f2", "?q2#f2");
testResolve("s://a/pa/pb?q2", "?q2");
// else
testResolve("s://a/pa/pb?q#f2", "#f2");
testResolve("s://a/pa/pb?q", "");
// else, if (R.path starts-with "/") then ...
testResolve("s://a/p2?q2#f2", "/p2?q2#f2");
testResolve("s://a/?q2#f2", "/?q2#f2");
testResolve("s://a/#f2", "/#f2");
testResolve("s://a/", "/");
testResolve("s://a/", "/../");
// else ... T.path = merge(Base.path, R.path)
// ... remove-dot-fragments(T.path) ...
// (Cover the merge function and the remove-dot-fragments functions too).
// If base has authority and empty path ...
var emptyPathBase = b.replaceFirst("/pa/pb", "");
setBase(emptyPathBase);
testResolve("s://a/p2?q2#f2", "p2?q2#f2");
testResolve("s://a/p2#f2", "p2#f2");
testResolve("s://a/p2", "p2");
setBase(b);
// otherwise
// (Cover both no authority and non-empty path and both).
var noAuthEmptyPathBase = b.replaceFirst("//a/pa/pb", "");
var noAuthAbsPathBase = b.replaceFirst("//a", "");
var noAuthRelPathBase = b.replaceFirst("//a/", "");
var noAuthRelSinglePathBase = b.replaceFirst("//a/pa/", "");
testResolve("s://a/pa/p2?q2#f2", "p2?q2#f2");
testResolve("s://a/pa/p2#f2", "p2#f2");
testResolve("s://a/pa/p2", "p2");
setBase(noAuthEmptyPathBase);
testResolve("s:p2?q2#f2", "p2?q2#f2");
testResolve("s:p2#f2", "p2#f2");
testResolve("s:p2", "p2");
setBase(noAuthAbsPathBase);
testResolve("s:/pa/p2?q2#f2", "p2?q2#f2");
testResolve("s:/pa/p2#f2", "p2#f2");
testResolve("s:/pa/p2", "p2");
setBase(noAuthRelPathBase);
testResolve("s:pa/p2?q2#f2", "p2?q2#f2");
testResolve("s:pa/p2#f2", "p2#f2");
testResolve("s:pa/p2", "p2");
setBase(noAuthRelSinglePathBase);
testResolve("s:p2?q2#f2", "p2?q2#f2");
testResolve("s:p2#f2", "p2#f2");
testResolve("s:p2", "p2");
// Then remove dot segments.
// A. if input buffer starts with "../" or "./".
// This only happens if base has only a single (may be empty) segment and
// no slash.
setBase(emptyPathBase);
testResolve("s://a/p2", "../p2");
testResolve("s://a/", "../");
testResolve("s://a/", "..");
testResolve("s://a/p2", "./p2");
testResolve("s://a/", "./");
testResolve("s://a/", ".");
testResolve("s://a/p2", "../../p2");
testResolve("s://a/p2", "../../././p2");
setBase(noAuthRelSinglePathBase);
testResolve("s:p2", "../p2");
testResolve("s:", "../");
testResolve("s:", "..");
testResolve("s:p2", "./p2");
testResolve("s:", "./");
testResolve("s:", ".");
testResolve("s:p2", "../../p2");
testResolve("s:p2", "../../././p2");
// B. if input buffer starts with "/./" or is "/.". replace with "/".
// (The URI implementation removes the "." path segments when parsing,
// so this case isn't handled by merge).
setBase(b);
testResolve("s://a/pa/p2", "./p2");
// C. if input buffer starts with "/../" or is "/..", replace with "/"
// and remove preceeding segment.
testResolve("s://a/p2", "../p2");
var longPathBase = b.replaceFirst("/pb", "/pb/pc/pd");
setBase(longPathBase);
testResolve("s://a/pa/pb/p2", "../p2");
testResolve("s://a/pa/p2", "../../p2");
testResolve("s://a/p2", "../../../p2");
testResolve("s://a/p2", "../../../../p2");
var noAuthRelLongPathBase = b.replaceFirst("//a/pa/pb", "pa/pb/pc/pd");
setBase(noAuthRelLongPathBase);
testResolve("s:pa/pb/p2", "../p2");
testResolve("s:pa/p2", "../../p2");
testResolve("s:/p2", "../../../p2");
testResolve("s:/p2", "../../../../p2");
// D. if the input buffer contains only ".." or ".", remove it.
setBase(noAuthEmptyPathBase);
testResolve("s:", "..");
testResolve("s:", ".");
setBase(noAuthRelSinglePathBase);
testResolve("s:", "..");
testResolve("s:", ".");
}
}
void testResolvePath(String expected, String path) {
Expect.equals(
expected, new Uri(path: '/').resolveUri(new Uri(path: path)).path);
Expect.equals("http://localhost$expected",
Uri.parse("http://localhost").resolveUri(new Uri(path: path)).toString());
}
const ALPHA = r"abcdefghijklmnopqrstuvwxuzABCDEFGHIJKLMNOPQRSTUVWXUZ";
const DIGIT = r"0123456789";
const PERCENT_ENCODED = "%00%ff";
const SUBDELIM = r"!$&'()*+,;=";
const SCHEMECHAR = "$ALPHA$DIGIT+-.";
const UNRESERVED = "$ALPHA$DIGIT-._~";
const REGNAMECHAR = "$UNRESERVED$SUBDELIM$PERCENT_ENCODED";
const USERINFOCHAR = "$REGNAMECHAR:";
const PCHAR_NC = "$UNRESERVED$SUBDELIM$PERCENT_ENCODED@";
const PCHAR = "$PCHAR_NC:";
const QUERYCHAR = "$PCHAR/?";
void testValidCharacters() {
// test that all valid characters are accepted.
for (var scheme in ["", "$SCHEMECHAR$SCHEMECHAR:"]) {
for (var userinfo in [
"",
"@",
"$USERINFOCHAR$USERINFOCHAR@",
"$USERINFOCHAR:$DIGIT@"
]) {
for (var host in [
"", "$REGNAMECHAR$REGNAMECHAR",
"255.255.255.256", // valid reg-name.
"[ffff::ffff:ffff]", "[ffff::255.255.255.255]"
]) {
for (var port in ["", ":", ":$DIGIT$DIGIT"]) {
var auth = "$userinfo$host$port";
if (auth.isNotEmpty) auth = "//$auth";
var paths = ["", "/", "/$PCHAR", "/$PCHAR/"]; // Absolute or empty.
if (auth.isNotEmpty) {
// Initial segment may be empty.
paths..add("//$PCHAR");
} else {
// Path may begin with non-slash.
if (scheme.isEmpty) {
// Initial segment must not contain colon.
paths
..add(PCHAR_NC)
..add("$PCHAR_NC/$PCHAR")
..add("$PCHAR_NC/$PCHAR/");
} else {
paths..add(PCHAR)..add("$PCHAR/$PCHAR")..add("$PCHAR/$PCHAR/");
}
}
for (var path in paths) {
for (var query in ["", "?", "?$QUERYCHAR"]) {
for (var fragment in ["", "#", "#$QUERYCHAR"]) {
var uri = "$scheme$auth$path$query$fragment";
// Should not throw.
var result = Uri.parse(uri);
}
}
}
}
}
}
}
}
void testInvalidUrls() {
void checkInvalid(uri) {
try {
var result = Uri.parse(uri);
Expect.fail("Invalid URI `$uri` parsed to $result\n" + dump(result));
} on FormatException {
// Success.
}
}
checkInvalid("s%41://x.x/"); // No escapes in scheme,
// and no colon before slash in path.
checkInvalid("1a://x.x/"); // Scheme must start with letter,
// and no colon before slash in path.
checkInvalid(".a://x.x/"); // Scheme must start with letter,
// and no colon before slash in path.
checkInvalid("_:"); // Character not valid in scheme,
// and no colon before slash in path.
checkInvalid(":"); // Scheme must start with letter,
// and no colon before slash in path.
void checkInvalidReplaced(uri, invalid, replacement) {
var source = uri.replaceAll('{}', invalid);
var expected = uri.replaceAll('{}', replacement);
var result = Uri.parse(source);
Expect.equals(expected, "$result", "Source: $source\n${dump(result)}");
}
// Regression test for http://dartbug.com/16081
checkInvalidReplaced(
"http://www.example.org/red%09ros{}#red)", "\u00e9", "%C3%A9");
checkInvalidReplaced("http://r{}sum\{}.example.org", "\u00E9", "%C3%A9");
// Invalid characters. The characters must be rejected, even if normalizing
// the input would cause them to be valid (normalization happens after
// validation).
var invalidCharsAndReplacements = [
"\xe7", "%C3%A7", // Arbitrary non-ASCII letter
" ", "%20", // Space, not allowed anywhere.
'"', "%22", // Quote, not allowed anywhere
"<>", "%3C%3E", // Less/greater-than, not allowed anywhere.
"\x7f", "%7F", // DEL, not allowed anywhere
"\xdf", "%C3%9F", // German lower-case scharf-S.
// Becomes ASCII when upper-cased.
"\u0130", "%C4%B0", // Latin capital dotted I,
// becomes ASCII lower-case in Turkish.
"%\uFB03", "%25%EF%AC%83", // % + Ligature ffi,
// becomes ASCII when upper-cased,
// should not be read as "%FFI".
"\u212a", "%E2%84%AA", // Kelvin sign. Becomes ASCII when lower-cased.
"%1g", "%251g", // Invalid escape.
"\u{10000}", "%F0%90%80%80", // Non-BMP character as surrogate pair.
];
for (int i = 0; i < invalidCharsAndReplacements.length; i += 2) {
var invalid = invalidCharsAndReplacements[i];
var valid = invalidCharsAndReplacements[i + 1];
checkInvalid("A{}b:///".replaceAll('{}', invalid));
checkInvalid("{}b:///".replaceAll('{}', invalid));
checkInvalidReplaced("s://user{}info@x.x/", invalid, valid);
checkInvalidReplaced("s://reg{}name/", invalid, valid);
checkInvalid("s://regname:12{}45/".replaceAll("{}", invalid));
checkInvalidReplaced("s://regname/p{}ath/", invalid, valid);
checkInvalidReplaced("/p{}ath/", invalid, valid);
checkInvalidReplaced("p{}ath/", invalid, valid);
checkInvalidReplaced("s://regname/path/?x{}x", invalid, valid);
checkInvalidReplaced("s://regname/path/#x{}x", invalid, valid);
checkInvalidReplaced("s://regname/path/??#x{}x", invalid, valid);
}
// At most one @ in userinfo.
checkInvalid("s://x@x@x.x/");
// No colon in host except before a port.
checkInvalid("s://x@x:x/");
// At most one port.
checkInvalid("s://x@x:9:9/");
// At most one #.
checkInvalid("s://x/x#foo#bar");
// @ not allowed in scheme.
checkInvalid("s@://x:9/x?x#x");
// ] not allowed alone in host.
checkInvalid("s://xx]/");
// ] not allowed anywhere except in host.
checkInvalid("s://xx/]");
checkInvalid("s://xx/?]");
checkInvalid("s://xx/#]");
checkInvalid("s:/]");
checkInvalid("s:/?]");
checkInvalid("s:/#]");
// IPv6 must be enclosed in [ and ] for Uri.parse.
// It is allowed un-enclosed as argument to `Uri(host:...)` because we don't
// need to delimit.
checkInvalid("s://ffff::ffff:1234/");
}
void testNormalization() {
// The Uri constructor and the Uri.parse function performs RFC-3986
// syntax based normalization.
var uri;
// Scheme: Only case normalization. Schemes cannot contain escapes.
uri = Uri.parse("A:");
Expect.equals("a", uri.scheme);
uri = Uri.parse("Z:");
Expect.equals("z", uri.scheme);
uri = Uri.parse("$SCHEMECHAR:");
Expect.equals(SCHEMECHAR.toLowerCase(), uri.scheme);
// Percent escape normalization.
// Escapes of unreserved characters are converted to the character,
// subject to case normalization in reg-name.
for (var i = 0; i < UNRESERVED.length; i++) {
var char = UNRESERVED[i];
var escape = "%" + char.codeUnitAt(0).toRadixString(16); // all > 0xf.
uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ"
"?vV${escape}vV#wW${escape}wW");
Expect.equals("xX${char}xX", uri.userInfo);
Expect.equals("yY${char}yY".toLowerCase(), uri.host);
Expect.equals("/zZ${char}zZ", uri.path);
Expect.equals("vV${char}vV", uri.query);
Expect.equals("wW${char}wW", uri.fragment);
uri = Uri.parse("s://yY${escape}yY/zZ${escape}zZ"
"?vV${escape}vV#wW${escape}wW");
Expect.equals("yY${char}yY".toLowerCase(), uri.host);
Expect.equals("/zZ${char}zZ", uri.path);
Expect.equals("vV${char}vV", uri.query);
Expect.equals("wW${char}wW", uri.fragment);
}
// Escapes of reserved characters are kept, but upper-cased.
for (var escape in ["%00", "%1f", "%7F", "%fF"]) {
uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ"
"?vV${escape}vV#wW${escape}wW");
var normalizedEscape = escape.toUpperCase();
Expect.equals("xX${normalizedEscape}xX", uri.userInfo);
Expect.equals("yy${normalizedEscape}yy", uri.host);
Expect.equals("/zZ${normalizedEscape}zZ", uri.path);
Expect.equals("vV${normalizedEscape}vV", uri.query);
Expect.equals("wW${normalizedEscape}wW", uri.fragment);
}
// Some host normalization edge cases.
uri = Uri.parse("x://x%61X%41x%41X%61x/");
Expect.equals("xaxaxaxax", uri.host);
uri = Uri.parse("x://Xxxxxxxx/");
Expect.equals("xxxxxxxx", uri.host);
uri = Uri.parse("x://xxxxxxxX/");
Expect.equals("xxxxxxxx", uri.host);
uri = Uri.parse("x://xxxxxxxx%61/");
Expect.equals("xxxxxxxxa", uri.host);
uri = Uri.parse("x://%61xxxxxxxx/");
Expect.equals("axxxxxxxx", uri.host);
uri = Uri.parse("x://X/");
Expect.equals("x", uri.host);
uri = Uri.parse("x://%61/");
Expect.equals("a", uri.host);
uri = new Uri(scheme: "x", path: "//y");
Expect.equals("//y", uri.path);
Expect.equals("x:////y", uri.toString());
uri = new Uri(scheme: "file", path: "//y");
Expect.equals("//y", uri.path);
Expect.equals("file:////y", uri.toString());
// File scheme noralizes to always showing authority, even if empty.
uri = new Uri(scheme: "file", path: "/y");
Expect.equals("file:///y", uri.toString());
uri = new Uri(scheme: "file", path: "y");
Expect.equals("file:///y", uri.toString());
// Empty host/query/fragment ensures the delimiter is there.
// Different from not being there.
Expect.equals("scheme:/", Uri.parse("scheme:/").toString());
Expect.equals("scheme:/", new Uri(scheme: "scheme", path: "/").toString());
Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString());
Expect.equals(
"scheme:///#",
new Uri(scheme: "scheme", host: "", path: "/", query: "", fragment: "")
.toString());
}
void testReplace() {
var uris = [
Uri.parse(""),
Uri.parse("a://@:/?#"),
Uri.parse("a://:/?#"), // Parsed as simple URI.
Uri.parse("a://b@c:4/e/f?g#h"),
Uri.parse("a://c:4/e/f?g#h"), // Parsed as simple URI.
Uri.parse("$SCHEMECHAR://$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR"
"?$QUERYCHAR#$QUERYCHAR"), // Parsed as simple URI.
Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR"
"?$QUERYCHAR#$QUERYCHAR"),
];
for (var uri1 in uris) {
for (var uri2 in uris) {
if (identical(uri1, uri2)) continue;
var scheme = uri1.scheme;
var userInfo = uri1.hasAuthority ? uri1.userInfo : "";
var host = uri1.hasAuthority ? uri1.host : null;
var port = uri1.hasAuthority ? uri1.port : 0;
var path = uri1.path;
var query = uri1.hasQuery ? uri1.query : null;
var fragment = uri1.hasFragment ? uri1.fragment : null;
var tmp1 = uri1;
void test() {
var tmp2 = new Uri(
scheme: scheme,
userInfo: userInfo,
host: host,
port: port,
path: path,
query: query == "" ? null : query,
queryParameters: query == "" ? {} : null,
fragment: fragment);
Expect.equals(tmp1, tmp2);
}
test();
scheme = uri2.scheme;
tmp1 = tmp1.replace(scheme: scheme);
test();
if (uri2.hasAuthority) {
userInfo = uri2.userInfo;
host = uri2.host;
port = uri2.port;
tmp1 = tmp1.replace(userInfo: userInfo, host: host, port: port);
test();
}
path = uri2.path;
tmp1 = tmp1.replace(path: path);
test();
if (uri2.hasQuery) {
query = uri2.query;
tmp1 = tmp1.replace(query: query);
test();
}
if (uri2.hasFragment) {
fragment = uri2.fragment;
tmp1 = tmp1.replace(fragment: fragment);
test();
}
}
}
// Regression test, http://dartbug.com/20814
var uri = Uri.parse("/no-authorty/");
uri = uri.replace(fragment: "fragment");
Expect.isFalse(uri.hasAuthority);
uri = new Uri(scheme: "foo", path: "bar");
uri = uri.replace(queryParameters: {
"x": ["42", "37"],
"y": ["43", "38"]
});
var params = uri.queryParametersAll;
Expect.equals(2, params.length);
Expect.listEquals(["42", "37"], params["x"]);
Expect.listEquals(["43", "38"], params["y"]);
// Test replacing with empty strings.
uri = Uri.parse("s://a:1/b/c?d#e");
Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString());
Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString());
Expect.equals("s://a:1?d#e", uri.replace(path: "").toString());
Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString());
// Test uri.replace on uri with fragment
uri = Uri.parse('http://hello.com/fake#fragment');
uri = uri.replace(path: "D/E/E");
Expect.stringEquals('http://hello.com/D/E/E#fragment', uri.toString());
}
void testRegression28359() {
var uri = new Uri(path: "//");
// This is an invalid path for a URI reference with no authority
// since it looks like an authority.
// Normalized to have an authority.
Expect.equals("////", "$uri");
Expect.equals("//", uri.path);
Expect.isTrue(uri.hasAuthority, "$uri has authority");
uri = new Uri(path: "file:///wat");
// This is an invalid path for a URI reference with no authority or scheme
// since the path looks like it starts with a scheme.
// Normalized by escaping the ":".
Expect.equals("file%3A///wat", uri.path);
Expect.equals("file%3A///wat", "$uri");
Expect.isFalse(uri.hasAuthority);
Expect.isFalse(uri.hasScheme);
}
main() {
testUri("http:", true);
testUri("file:///", true);
testUri("file", false);
testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true);
testUri(
"http://user@example.com:8080/fisk?query=89&hest=silas#fragment", false);
Expect.stringEquals(
"http://user@example.com/a/b/c?query#fragment",
new Uri(
scheme: "http",
userInfo: "user",
host: "example.com",
port: 80,
path: "/a/b/c",
query: "query",
fragment: "fragment")
.toString());
Expect.stringEquals(
"/a/b/c/",
new Uri(
scheme: null,
userInfo: null,
host: null,
port: 0,
path: "/a/b/c/",
query: null,
fragment: null)
.toString());
Expect.stringEquals("file:///", Uri.parse("file:").toString());
Expect.stringEquals("file:///", Uri.parse("file:/").toString());
Expect.stringEquals("file:///", Uri.parse("file:").toString());
Expect.stringEquals("file:///foo", Uri.parse("file:foo").toString());
Expect.stringEquals("file:///foo", Uri.parse("file:/foo").toString());
Expect.stringEquals("file://foo/", Uri.parse("file://foo").toString());
testResolvePath("/a/g", "/a/b/c/./../../g");
testResolvePath("/a/g", "/a/b/c/./../../g");
testResolvePath("/mid/6", "mid/content=5/../6");
testResolvePath("/a/b/e", "a/b/c/d/../../e");
testResolvePath("/a/b/e", "../a/b/c/d/../../e");
testResolvePath("/a/b/e", "./a/b/c/d/../../e");
testResolvePath("/a/b/e", "../a/b/./c/d/../../e");
testResolvePath("/a/b/e", "./a/b/./c/d/../../e");
testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/.");
testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/./.");
testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/././.");
testUriPerRFCs();
Expect.stringEquals(
"http://example.com", Uri.parse("http://example.com/a/b/c").origin);
Expect.stringEquals(
"https://example.com", Uri.parse("https://example.com/a/b/c").origin);
Expect.stringEquals("http://example.com:1234",
Uri.parse("http://example.com:1234/a/b/c").origin);
Expect.stringEquals("https://example.com:1234",
Uri.parse("https://example.com:1234/a/b/c").origin);
Expect.throws(() => Uri.parse("http:").origin, (e) {
return e is StateError;
}, "origin for URI with empty host should fail");
Expect.throws(
() => new Uri(
scheme: "http",
userInfo: null,
host: "",
port: 80,
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for URI with empty host should fail");
Expect.throws(
() => new Uri(
scheme: null,
userInfo: null,
host: "",
port: 80,
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for URI with empty scheme should fail");
Expect.throws(
() => new Uri(
scheme: "http",
userInfo: null,
host: null,
port: 80,
path: "/a/b/c",
query: "query",
fragment: "fragment")
.origin, (e) {
return e is StateError;
}, "origin for URI with empty host should fail");
Expect.throws(() => Uri.parse("http://:80").origin, (e) {
return e is StateError;
}, "origin for URI with empty host should fail");
Expect.throws(() => Uri.parse("file://localhost/test.txt").origin, (e) {
return e is StateError;
}, "origin for non-http/https uri should fail");
// URI encode tests
// Create a string with code point 0x10000 encoded as a surrogate pair.
var s = UTF8.decode([0xf0, 0x90, 0x80, 0x80]);
Expect.stringEquals("\u{10000}", s);
testEncodeDecode("A + B", "A%20+%20B");
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");
// All characters not escaped by encodeFull.
var unescapedFull = r"abcdefghijklmnopqrstuvwxyz"
r"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
r"0123456789!#$&'()*+,-./:;=?@_~";
// ASCII characters escaped by encodeFull:
var escapedFull =
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
r' "%<>[\]^`{|}'
"\x7f";
var escapedTo = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"
"%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"
"%20%22%25%3C%3E%5B%5C%5D%5E%60%7B%7C%7D%7F";
testEncodeDecode(unescapedFull, unescapedFull);
testEncodeDecode(escapedFull, escapedTo);
var nonAscii =
"\x80-\xff-\u{100}-\u{7ff}-\u{800}-\u{ffff}-\u{10000}-\u{10ffff}";
var nonAsciiEncoding = "%C2%80-%C3%BF-%C4%80-%DF%BF-%E0%A0%80-%EF%BF%BF-"
"%F0%90%80%80-%F4%8F%BF%BF";
testEncodeDecode(nonAscii, nonAsciiEncoding);
testEncodeDecode(s, "%F0%90%80%80");
testEncodeDecodeComponent("A + B", "A%20%2B%20B");
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");
testEncodeDecodeQueryComponent("A + B", "A+%2B+B", "A+%2B+B", "A+%2B+B");
testEncodeDecodeQueryComponent(
"æ ø å", "%C3%A6+%C3%B8+%C3%A5", "%E6+%F8+%E5", null);
testEncodeDecodeComponent(nonAscii, nonAsciiEncoding);
// Invalid URI - : and @ is swapped, port ("host") should be numeric.
Expect.throws(() => Uri.parse("file://user@password:host/path"),
(e) => e is FormatException);
testValidCharacters();
testInvalidUrls();
testNormalization();
testReplace();
testRegression28359();
}
String dump(Uri uri) {
return "URI: $uri\n"
" Scheme: ${uri.scheme} #${uri.scheme.length}\n"
" User-info: ${uri.userInfo} #${uri.userInfo.length}\n"
" Host: ${uri.host} #${uri.host.length}\n"
" Port: ${uri.port}\n"
" Path: ${uri.path} #${uri.path.length}\n"
" Query: ${uri.query} #${uri.query.length}\n"
" Fragment: ${uri.fragment} #${uri.fragment.length}\n";
}

View file

@ -31,6 +31,7 @@ big_integer_huge_mul_vm_test: Pass, Slow # Slow
[ $compiler == none || $compiler == precompiler || $compiler == app_jit ]
compare_to2_test: Fail # Issue 4018
unicode_test: Fail # Issue 6706
[ ($compiler == dartk || $compiler == dartkp) && ($runtime == vm || $runtime == dart_precompiled) ]
bool_from_environment2_test/01: MissingCompileTimeError

View file

@ -83,13 +83,13 @@ void testPathSegments() {
}
unencoded.writeCharCode(i);
}
encoded = encoded.toString();
unencoded = unencoded.toString();
test(encoded, [unencoded]);
test(encoded + "/" + encoded, [unencoded, unencoded]);
var encodedStr = encoded.toString();
var unencodedStr = unencoded.toString();
test(encodedStr, [unencodedStr]);
test(encodedStr + "/" + encodedStr, [unencodedStr, unencodedStr]);
Uri uri;
List pathSegments = ["xxx", "yyy", "zzz"];
var pathSegments = ["xxx", "yyy", "zzz"];
uri = new Uri(pathSegments: pathSegments);
Expect.equals(3, uri.pathSegments.length);

View file

@ -100,21 +100,21 @@ void testQueryParameters() {
}
unencoded.writeCharCode(i);
}
encoded = encoded.toString();
unencoded = unencoded.toString();
test("a=$encoded", {"a": unencoded});
test("a=$encoded&b=$encoded", {"a": unencoded, "b": unencoded});
var encodedStr = encoded.toString();
var unencodedStr = unencoded.toString();
test("a=$encodedStr", {"a": unencodedStr});
test("a=$encodedStr&b=$encodedStr", {"a": unencodedStr, "b": unencodedStr});
var map = new Map();
map[unencoded] = unencoded;
test("$encoded=$encoded", map);
test("$encoded=$allEncoded", map, "$encoded=$encoded");
test("$allEncoded=$encoded", map, "$encoded=$encoded");
test("$allEncoded=$allEncoded", map, "$encoded=$encoded");
map[unencoded] = null;
test("$encoded", map);
map[unencoded] = "";
test("$encoded", map);
map[unencodedStr] = unencodedStr;
test("$encodedStr=$encodedStr", map);
test("$encodedStr=$allEncoded", map, "$encodedStr=$encodedStr");
test("$allEncoded=$encodedStr", map, "$encodedStr=$encodedStr");
test("$allEncoded=$allEncoded", map, "$encodedStr=$encodedStr");
map[unencodedStr] = null;
test("$encodedStr", map);
map[unencodedStr] = "";
test("$encodedStr", map);
}
testInvalidQueryParameters() {

View file

@ -51,8 +51,6 @@ string_test: Skip
symbol_operator_test: Skip
symbol_reserved_word_test: Skip
symbol_test: Skip
uri_path_test: Skip
uri_query_test: Skip
[ $compiler == dartdevc ]
big_integer_parsed_div_rem_vm_test: RuntimeError # Issue 29921

View file

@ -1,12 +0,0 @@
// Copyright (c) 2014, 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.
main() {
var trebleClef = "\u{1D11E}";
if (trebleClef.length != 2) throw "String should be a surrogate pair";
// These uncaught exceptions should not cause the VM to crash attempting to
// print a malformed string.
throw trebleClef[0]; // //# 01: runtime error
throw trebleClef[1]; // //# 02: runtime error
}

View file

@ -1,20 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
main() {
Expect.equals(-0x80000001, (-0x80000001).toInt());
Expect.equals(-0x80000000, (-0x80000000 - 0.7).toInt());
Expect.equals(-0x80000000, (-0x80000000 - 0.3).toInt());
Expect.equals(-0x7FFFFFFF, (-0x80000000 + 0.3).toInt());
Expect.equals(-0x7FFFFFFF, (-0x80000000 + 0.7).toInt());
Expect.equals(-0x7FFFFFFF, (-0x7FFFFFFF).toInt());
Expect.equals(0x7FFFFFFE, (0x7FFFFFFE).toInt());
Expect.equals(0x7FFFFFFE, (0x7FFFFFFF - 0.7).toInt());
Expect.equals(0x7FFFFFFE, (0x7FFFFFFF - 0.3).toInt());
Expect.equals(0x7FFFFFFF, (0x7FFFFFFF + 0.3).toInt());
Expect.equals(0x7FFFFFFF, (0x7FFFFFFF + 0.7).toInt());
Expect.equals(0x80000000, 0x80000000.toInt());
}

View file

@ -1,77 +0,0 @@
// Copyright (c) 2012, 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.
import 'package:expect/expect.dart';
const String testPhrase = "The quick brown fox jumps over the lazy dog.";
const List<int> testCodepoints = const <int>[
84,
104,
101,
32,
113,
117,
105,
99,
107,
32,
98,
114,
111,
119,
110,
32,
102,
111,
120,
32,
106,
117,
109,
112,
115,
32,
111,
118,
101,
114,
32,
116,
104,
101,
32,
108,
97,
122,
121,
32,
100,
111,
103,
46
];
main() {
testCodepointsToString();
testStringCharCodes();
testEmptyStringFromCharCodes();
testEmptyStringCharCodes();
}
void testStringCharCodes() {
Expect.listEquals(testCodepoints, testPhrase.codeUnits);
}
void testCodepointsToString() {
Expect.stringEquals(testPhrase, new String.fromCharCodes(testCodepoints));
}
void testEmptyStringFromCharCodes() {
Expect.stringEquals("", new String.fromCharCodes(<int>[]));
}
void testEmptyStringCharCodes() {
Expect.listEquals([], "".codeUnits);
}

View file

@ -1,16 +0,0 @@
// Copyright (c) 2011, 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.
import "package:expect/expect.dart";
class UnicodeTest {
static testMain() {
var lowerStrasse = new String.fromCharCodes([115, 116, 114, 97, 223, 101]);
Expect.equals("STRASSE", lowerStrasse.toUpperCase());
}
}
main() {
UnicodeTest.testMain();
}

View file

@ -1,14 +0,0 @@
// Copyright (c) 2012, 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.
import "package:expect/expect.dart";
main() {
try {
Uri base = Uri.base;
Expect.isTrue(Uri.base.scheme == "file" || Uri.base.scheme == "http");
} on UnsupportedError catch (e) {
Expect.isTrue(e.toString().contains("'Uri.base' is not supported"));
}
}

View file

@ -1,82 +0,0 @@
// Copyright (c) 2012, 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.
import "package:expect/expect.dart";
testHttpUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
check(new Uri.http("", ""), "http:");
check(new Uri.http("@:", ""), "http://");
check(new Uri.http("@:8080", ""), "http://:8080");
check(new Uri.http("@host:", ""), "http://host");
check(new Uri.http("@host:", ""), "http://host");
check(new Uri.http("xxx:yyy@host:8080", ""), "http://xxx:yyy@host:8080");
check(new Uri.http("host", "a"), "http://host/a");
check(new Uri.http("host", "/a"), "http://host/a");
check(new Uri.http("host", "a/"), "http://host/a/");
check(new Uri.http("host", "/a/"), "http://host/a/");
check(new Uri.http("host", "a/b"), "http://host/a/b");
check(new Uri.http("host", "/a/b"), "http://host/a/b");
check(new Uri.http("host", "a/b/"), "http://host/a/b/");
check(new Uri.http("host", "/a/b/"), "http://host/a/b/");
check(new Uri.http("host", "a b"), "http://host/a%20b");
check(new Uri.http("host", "/a b"), "http://host/a%20b");
check(new Uri.http("host", "/a b/"), "http://host/a%20b/");
check(new Uri.http("host", "/a%2F"), "http://host/a%252F");
check(new Uri.http("host", "/a%2F/"), "http://host/a%252F/");
check(new Uri.http("host", "/a/b", {"c": "d"}), "http://host/a/b?c=d");
check(
new Uri.http("host", "/a/b", {"c=": "&d"}), "http://host/a/b?c%3D=%26d");
check(new Uri.http("[::]", "a"), "http://[::]/a");
check(new Uri.http("[::127.0.0.1]", "a"), "http://[::127.0.0.1]/a");
}
testHttpsUri() {
void check(Uri uri, String expected) {
Expect.equals(expected, uri.toString());
}
check(new Uri.https("", ""), "https:");
check(new Uri.https("@:", ""), "https://");
check(new Uri.https("@:8080", ""), "https://:8080");
check(new Uri.https("@host:", ""), "https://host");
check(new Uri.https("@host:", ""), "https://host");
check(new Uri.https("xxx:yyy@host:8080", ""), "https://xxx:yyy@host:8080");
check(new Uri.https("host", "a"), "https://host/a");
check(new Uri.https("host", "/a"), "https://host/a");
check(new Uri.https("host", "a/"), "https://host/a/");
check(new Uri.https("host", "/a/"), "https://host/a/");
check(new Uri.https("host", "a/b"), "https://host/a/b");
check(new Uri.https("host", "/a/b"), "https://host/a/b");
check(new Uri.https("host", "a/b/"), "https://host/a/b/");
check(new Uri.https("host", "/a/b/"), "https://host/a/b/");
check(new Uri.https("host", "a b"), "https://host/a%20b");
check(new Uri.https("host", "/a b"), "https://host/a%20b");
check(new Uri.https("host", "/a b/"), "https://host/a%20b/");
check(new Uri.https("host", "/a%2F"), "https://host/a%252F");
check(new Uri.https("host", "/a%2F/"), "https://host/a%252F/");
check(new Uri.https("host", "/a/b", {"c": "d"}), "https://host/a/b?c=d");
check(new Uri.https("host", "/a/b", {"c=": "&d"}),
"https://host/a/b?c%3D=%26d");
check(new Uri.https("[::]", "a"), "https://[::]/a");
check(new Uri.https("[::127.0.0.1]", "a"), "https://[::127.0.0.1]/a");
}
testResolveHttpScheme() {
String s = "//myserver:1234/path/some/thing";
Uri uri = Uri.parse(s);
Uri http = new Uri(scheme: "http");
Uri https = new Uri(scheme: "https");
Expect.equals("http:$s", http.resolveUri(uri).toString());
Expect.equals("https:$s", https.resolveUri(uri).toString());
}
main() {
testHttpUri();
testHttpsUri();
testResolveHttpScheme();
}

View file

@ -1,31 +0,0 @@
// Copyright (c) 2012, 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.
import 'package:expect/expect.dart';
void testParseIPv4Address() {
void pass(String host, List<int> out) {
Expect.listEquals(Uri.parseIPv4Address(host), out);
}
void fail(String host) {
Expect.throws(
() => Uri.parseIPv4Address(host), (e) => e is FormatException);
}
pass('127.0.0.1', [127, 0, 0, 1]);
pass('128.0.0.1', [128, 0, 0, 1]);
pass('255.255.255.255', [255, 255, 255, 255]);
pass('0.0.0.0', [0, 0, 0, 0]);
fail('127.0.0.-1');
fail('255.255.255.256');
fail('0.0.0.0.');
fail('0.0.0.0.0');
fail('a.0.0.0');
fail('0.0..0');
}
void main() {
testParseIPv4Address();
}

View file

@ -1,148 +0,0 @@
// Copyright (c) 2012, 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.
import 'package:expect/expect.dart';
void testValidIpv6Uri() {
var path = 'http://[::1]:1234/path?query=5#now';
var uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('::1', uri.host);
Expect.equals(1234, uri.port);
Expect.equals('/path', uri.path);
Expect.equals('query=5', uri.query);
Expect.equals('now', uri.fragment);
Expect.equals(path, uri.toString());
path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8080/index.html';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
Expect.equals(8080, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals(path.toLowerCase(), uri.toString());
path = 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
Expect.equals(80, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
uri.toString());
path = 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/index.html';
uri = Uri.parse(path);
Expect.equals('https', uri.scheme);
Expect.equals('fedc:ba98:7654:3210:fedc:ba98:7654:3210', uri.host);
Expect.equals(443, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals('https://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html',
uri.toString());
path = 'http://[1080:0:0:0:8:800:200C:417A]/index.html';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('1080:0:0:0:8:800:200c:417a', uri.host);
Expect.equals(80, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals(path.toLowerCase(), uri.toString());
path = 'http://[3ffe:2a00:100:7031::1]';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('3ffe:2a00:100:7031::1', uri.host);
Expect.equals(80, uri.port);
Expect.equals('', uri.path);
Expect.equals(path, uri.toString());
path = 'http://[1080::8:800:200C:417A]/foo';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('1080::8:800:200c:417a', uri.host);
Expect.equals(80, uri.port);
Expect.equals('/foo', uri.path);
Expect.equals(path.toLowerCase(), uri.toString());
path = 'http://[::192.9.5.5]/ipng';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('::192.9.5.5', uri.host);
Expect.equals(80, uri.port);
Expect.equals('/ipng', uri.path);
Expect.equals(path, uri.toString());
path = 'http://[::FFFF:129.144.52.38]:8080/index.html';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('::ffff:129.144.52.38', uri.host);
Expect.equals(8080, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals(path.toLowerCase(), uri.toString());
path = 'http://[::FFFF:129.144.52.38]:80/index.html';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('::ffff:129.144.52.38', uri.host);
Expect.equals(80, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals('http://[::ffff:129.144.52.38]/index.html', uri.toString());
path = 'https://[::FFFF:129.144.52.38]:443/index.html';
uri = Uri.parse(path);
Expect.equals('https', uri.scheme);
Expect.equals('::ffff:129.144.52.38', uri.host);
Expect.equals(443, uri.port);
Expect.equals('/index.html', uri.path);
Expect.equals('https://[::ffff:129.144.52.38]/index.html', uri.toString());
path = 'http://[2010:836B:4179::836B:4179]';
uri = Uri.parse(path);
Expect.equals('http', uri.scheme);
Expect.equals('2010:836b:4179::836b:4179', uri.host);
Expect.equals(80, uri.port);
Expect.equals('', uri.path);
Expect.equals(path.toLowerCase(), uri.toString());
}
void testParseIPv6Address() {
void pass(String host, List<int> expected) {
Expect.listEquals(expected, Uri.parseIPv6Address(host));
}
void fail(String host) {
Expect.throws(
() => Uri.parseIPv6Address(host), (e) => e is FormatException);
}
pass('::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
pass('0::127.0.0.1', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
pass('::', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
pass('0::', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
fail(':0::127.0.0.1');
fail('0:::');
fail(':::');
fail('::0:');
fail('::0::');
fail('::0::0');
fail('00000::0');
fail('-1::0');
fail('-AAA::0');
fail('0::127.0.0.1:0');
fail('0::127.0.0');
pass('0::1111', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17]);
pass('2010:836B:4179::836B:4179',
[32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 131, 107, 65, 121]);
fail('2010:836B:4179:0000:127.0.0.1');
fail('2010:836B:4179:0000:0000:127.0.0.1');
fail('2010:836B:4179:0000:0000:0000::127.0.0.1');
fail('2010:836B:4179:0000:0000:0000:0000:127.0.0.1');
pass('2010:836B:4179:0000:0000:0000:127.0.0.1',
[32, 16, 131, 107, 65, 121, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]);
}
void main() {
testValidIpv6Uri();
testParseIPv6Address();
}

View file

@ -1,59 +0,0 @@
// Copyright (c) 2012, 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 uriNormalizePathTest;
import "package:expect/expect.dart";
test(String path, String normalizedPath) {
for (var scheme in ["http", "file", "unknown"]) {
for (var auth in [
[null, "hostname", null],
["userinfo", "hostname", 1234],
[null, null, null]
]) {
for (var query in [null, "query"]) {
for (var fragment in [null, "fragment"]) {
var base = new Uri(
scheme: scheme,
userInfo: auth[0],
host: auth[1],
port: auth[2],
path: path,
query: query,
fragment: fragment);
var expected = base.replace(
path: (base.hasAuthority && normalizedPath.isEmpty)
? "/"
: normalizedPath);
var actual = base.normalizePath();
Expect.equals(expected, actual, "$base");
}
}
}
}
}
testNoChange(String path) {
test(path, path);
}
main() {
testNoChange("foo/bar/baz");
testNoChange("/foo/bar/baz");
testNoChange("foo/bar/baz/");
test("foo/bar/..", "foo/");
test("foo/bar/.", "foo/bar/");
test("foo/./bar/../baz", "foo/baz");
test("../../foo", "foo");
test("./../foo", "foo");
test("./../", "");
test("./../.", "");
test("foo/bar/baz/../../../../qux", "/qux");
test("/foo/bar/baz/../../../../qux", "/qux");
test(".", "");
test("..", "");
test("/.", "/");
test("/..", "/");
}

View file

@ -1,77 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
testNormalizePath() {
test(String expected, String path, {String scheme, String host}) {
var uri = new Uri(scheme: scheme, host: host, path: path);
Expect.equals(expected, uri.toString());
if (scheme == null && host == null) {
Expect.equals(expected, uri.path);
}
}
var unreserved = "-._~0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
test("A", "%41");
test("AB", "%41%42");
test("%40AB", "%40%41%42");
test("a", "%61");
test("ab", "%61%62");
test("%60ab", "%60%61%62");
test(unreserved, unreserved);
var x = new StringBuffer();
for (int i = 32; i < 128; i++) {
if (unreserved.indexOf(new String.fromCharCode(i)) != -1) {
x.writeCharCode(i);
} else {
x.write("%");
x.write(i.toRadixString(16));
}
}
Expect.equals(x.toString().toUpperCase(),
new Uri(path: x.toString()).toString().toUpperCase());
// Normalized paths.
// Full absolute path normalization for absolute paths.
test("/a/b/c/", "/../a/./b/z/../c/d/..");
test("/a/b/c/", "/./a/b/c/");
test("/a/b/c/", "/./../a/b/c/");
test("/a/b/c/", "/./../a/b/c/.");
test("/a/b/c/", "/./../a/b/c/z/./..");
test("/", "/a/..");
// Full absolute path normalization for URIs with scheme.
test("s:a/b/c/", "../a/./b/z/../c/d/..", scheme: "s");
test("s:a/b/c/", "./a/b/c/", scheme: "s");
test("s:a/b/c/", "./../a/b/c/", scheme: "s");
test("s:a/b/c/", "./../a/b/c/.", scheme: "s");
test("s:a/b/c/", "./../a/b/c/z/./..", scheme: "s");
test("s:/", "/a/..", scheme: "s");
test("s:/", "a/..", scheme: "s");
// Full absolute path normalization for URIs with authority.
test("//h/a/b/c/", "../a/./b/z/../c/d/..", host: "h");
test("//h/a/b/c/", "./a/b/c/", host: "h");
test("//h/a/b/c/", "./../a/b/c/", host: "h");
test("//h/a/b/c/", "./../a/b/c/.", host: "h");
test("//h/a/b/c/", "./../a/b/c/z/./..", host: "h");
test("//h/", "/a/..", host: "h");
test("//h/", "a/..", host: "h");
// Partial relative normalization (allowing leading .. or ./ for current dir).
test("../a/b/c/", "../a/./b/z/../c/d/..");
test("a/b/c/", "./a/b/c/");
test("../a/b/c/", "./../a/b/c/");
test("../a/b/c/", "./../a/b/c/.");
test("../a/b/c/", "./../a/b/c/z/./..");
test("/", "/a/..");
test("./", "a/..");
}
main() {
testNormalizePath();
}

View file

@ -1,51 +0,0 @@
// Copyright (c) 2015, 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.
import "package:expect/expect.dart";
import 'dart:convert';
main() {
testAll(["a", "b", "c"]);
testAll([""]);
testAll(["a"]);
testAll(["", ""]);
testAll(["baz"]);
testParse("z&y&w&z", {
"z": ["", ""],
"y": [""],
"w": [""]
});
testParse("x=42&y=42&x=37&y=37", {
"x": ["42", "37"],
"y": ["42", "37"]
});
testParse("x&x&x&x&x", {
"x": ["", "", "", "", ""]
});
testParse("x=&&y", {
"x": [""],
"y": [""]
});
}
testAll(List values) {
var uri =
new Uri(scheme: "foo", path: "bar", queryParameters: {"baz": values});
var list = uri.queryParametersAll["baz"];
Expect.listEquals(values, list);
}
testParse(query, results) {
var uri = new Uri(scheme: "foo", path: "bar", query: query);
var params = uri.queryParametersAll;
for (var k in results.keys) {
Expect.listEquals(results[k], params[k]);
}
uri = new Uri(scheme: "foo", path: "bar", queryParameters: results);
params = uri.queryParametersAll;
for (var k in results.keys) {
Expect.listEquals(results[k], params[k]);
}
}

View file

@ -1,72 +0,0 @@
// Copyright (c) 2012, 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.
import "package:expect/expect.dart";
void testUriCombi() {
var schemes = ["", "file", "ws", "ftp"];
var fragments = ["", "#", "#f", "#fragment", "#l:?/"];
var queries = ["", "?", "?q", "?query", "?q:/"];
var paths = ["/", "/x", "/x/y", "/x/y/", "/x:y", "x", "x/y", "x/y/"];
var userInfos = ["", "x", "xxx", "x:4", "xxx:444", "x:4:x"];
var hosts = ["", "h", "hhh", "h:4", "hhh:444", "[::1.2.3.4]"];
void check(uriString, scheme, fragment, query, path, user, host) {
for (var uri in [
Uri.parse(uriString),
Uri.parse(">\u{10000}>$uriString<\u{10000}<", 4, uriString.length + 4),
Uri.parse(
"http://example.com/$uriString#?:/[]\"", 19, uriString.length + 19),
Uri.parse(uriString * 3, uriString.length, uriString.length * 2)
]) {
String name = "$uriString -> $uri";
Expect.equals(scheme, uri.scheme, name);
var uriFragment = uri.fragment;
if (fragment.startsWith('#')) uriFragment = "#$uriFragment";
Expect.equals(fragment, uriFragment, name);
var uriQuery = uri.query;
if (query.startsWith('?')) uriQuery = "?$uriQuery";
Expect.equals(query, uriQuery, name);
Expect.equals(path, uri.path, name);
Expect.equals(user, uri.userInfo, name);
var uriHost = uri.host;
if (host.startsWith("[")) uriHost = "[$uriHost]";
if (uri.port != 0) uriHost += ":${uri.port}";
Expect.equals(host, uriHost, name);
}
}
for (var scheme in schemes) {
for (var fragment in fragments) {
for (var query in queries) {
for (var path in paths) {
// File scheme URIs always get a leading slash.
if (scheme == "file" && !path.startsWith('/')) continue;
for (var user in userInfos) {
for (var host in hosts) {
var auth = host;
var s = scheme;
if (user.isNotEmpty) auth = "$user@$auth";
if (auth.isNotEmpty) auth = "//$auth";
if (auth.isNotEmpty && !path.startsWith('/')) continue;
check(
"$scheme${scheme.isEmpty ? "" : ":"}"
"$auth$path$query$fragment",
scheme,
fragment,
query,
path,
user,
host);
}
}
}
}
}
}
}
void main() {
testUriCombi();
}

View file

@ -1,37 +0,0 @@
// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
void testInvalidArguments() {
Expect.throws(() => new Uri(scheme: "_"), (e) => e is FormatException);
Expect.throws(() => new Uri(scheme: "http_s"), (e) => e is FormatException);
Expect.throws(
() => new Uri(scheme: "127.0.0.1:80"), (e) => e is FormatException);
}
void testScheme() {
test(String expectedScheme, String expectedUri, String scheme) {
var uri = new Uri(scheme: scheme);
Expect.equals(expectedScheme, uri.scheme);
Expect.equals(expectedUri, uri.toString());
uri = Uri.parse("$scheme:");
Expect.equals(expectedScheme, uri.scheme);
Expect.equals(expectedUri, uri.toString());
}
test("http", "http:", "http");
test("http", "http:", "HTTP");
test("http", "http:", "hTTP");
test("http", "http:", "Http");
test("http+ssl", "http+ssl:", "HTTP+ssl");
test("urn", "urn:", "urn");
test("urn", "urn:", "UrN");
test("a123.432", "a123.432:", "a123.432");
}
main() {
testInvalidArguments();
testScheme();
}