mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 15:21:54 +00:00
b998b10f3e
Change-Id: I3a31632ce28fb87a410b759d092c7ebc9393574d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128306 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
78 lines
2.5 KiB
Dart
78 lines
2.5 KiB
Dart
// 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();
|
|
}
|