blob: 4f3c35e0767c671763e568981f3afa1d38d05dcc [file] [log] [blame]
// 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.
/// @assertion path, {bool windows})
/// Like Uri.file except that a non-empty URI path ends in a slash.
/// If path is not empty, and it doesn't end in a directory separator, then a
/// slash is added to the returned URI's path. In all other cases, the result is
/// the same as returned by Uri.file
/// @description Checks that forward slash is interpreted as path separator and
/// backward slash is not interpreted as path separator for non-Windows
/// semantics. Also checks that that returned URI is always ends with a slash
/// @author
import "dart:convert";
import "../../../Utils/expect.dart";
import "UriDataEncoder.lib.dart";
check(String path) {
Uri uri = new, windows: false);
Expect.equals(path.startsWith("/") ? "file" : "", uri.scheme);
Expect.equals("", uri.userInfo);
Expect.equals("", uri.query);
Expect.equals(0, uri.port);
Expect.equals("", uri.fragment);
String expected = encodeString(path, encoding: Encoding.getByName("utf-8"));
if (!expected.endsWith("/")) {
expected = expected + "/";
Expect.equals(expected, uri.path);
main() {
check(" ");
check(" a ");
check(r" a / b ");
check(r" a \ b ");
check(r"/ a / b ");
check(r"\ a \ b ");
check(r" й / ф ");
check(r" й \ ф ");
check(r"/ й / ф ");
check(r"\ й \ ф ");