|
| 1 | +// This source file is part of the Swift.org open source project |
| 2 | +// |
| 3 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 4 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 5 | +// |
| 6 | +// See https://swift.org/LICENSE.txt for license information |
| 7 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 8 | +// |
| 9 | + |
| 10 | +class TestNSURL: XCTestCase { |
| 11 | + |
| 12 | + func test_absoluteString() { |
| 13 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder", isDirectory: true).absoluteString, "file:///path/to/folder/") |
| 14 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder/", isDirectory: true).absoluteString, "file:///path/to/folder/") |
| 15 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).absoluteString, "file:///path/../folder/") |
| 16 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./folder/..", isDirectory: true).absoluteString, "file:///path/to/./folder/../") |
| 17 | + |
| 18 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/.file", isDirectory: false).absoluteString, "file:///path/to/.file") |
| 19 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/file/", isDirectory: false).absoluteString, "file:///path/to/file") |
| 20 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../file", isDirectory: false).absoluteString, "file:///path/../file") |
| 21 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./file/..", isDirectory: false).absoluteString, "file:///path/to/./file/..") |
| 22 | + } |
| 23 | + |
| 24 | + func test_pathComponents() { |
| 25 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder", isDirectory: true).pathComponents, ["/", "path", "to", "folder"]) |
| 26 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder/", isDirectory: true).pathComponents, ["/", "path", "to", "folder"]) |
| 27 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).pathComponents, ["/", "path", "..", "folder"]) |
| 28 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).standardized?.pathComponents, ["/", "folder"]) |
| 29 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./folder/..", isDirectory: true).pathComponents, ["/", "path", "to", ".", "folder", ".."]) |
| 30 | + |
| 31 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/.file", isDirectory: false).pathComponents, ["/", "path", "to", ".file"]) |
| 32 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/file/", isDirectory: false).pathComponents, ["/", "path", "to", "file"]) |
| 33 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../file", isDirectory: false).pathComponents, ["/", "path", "..", "file"]) |
| 34 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./file/..", isDirectory: false).pathComponents, ["/", "path", "to", ".", "file", ".."]) |
| 35 | + } |
| 36 | + |
| 37 | + func test_standardized() { |
| 38 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder", isDirectory: true).standardized?.absoluteString, "file:///path/to/folder/") |
| 39 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder/", isDirectory: true).standardized?.absoluteString, "file:///path/to/folder/") |
| 40 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).standardized?.absoluteString, "file:///folder/") |
| 41 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./folder/..", isDirectory: true).standardized?.absoluteString, "file:///path/to/") |
| 42 | + |
| 43 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/.file", isDirectory: false).standardized?.absoluteString, "file:///path/to/.file") |
| 44 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/file/", isDirectory: false).standardized?.absoluteString, "file:///path/to/file") |
| 45 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../file", isDirectory: false).standardized?.absoluteString, "file:///file") |
| 46 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./file/..", isDirectory: false).standardized?.absoluteString, "file:///path/to") |
| 47 | + } |
| 48 | + |
| 49 | + func test_standardizingPath() { |
| 50 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder", isDirectory: true).standardizingPath?.absoluteString, "file:///path/to/folder/") |
| 51 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder/", isDirectory: true).standardizingPath?.absoluteString, "file:///path/to/folder/") |
| 52 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).standardizingPath?.absoluteString, "file:///folder/") |
| 53 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./folder/..", isDirectory: true).standardizingPath?.absoluteString, "file:///path/to/") |
| 54 | + |
| 55 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/.file", isDirectory: false).standardizingPath?.absoluteString, "file:///path/to/.file") |
| 56 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/file/", isDirectory: false).standardizingPath?.absoluteString, "file:///path/to/file") |
| 57 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../file", isDirectory: false).standardizingPath?.absoluteString, "file:///file") |
| 58 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./file/..", isDirectory: false).standardizingPath?.absoluteString, "file:///path/to") |
| 59 | + } |
| 60 | + |
| 61 | + func test_resolvingSymlinksInPath() { |
| 62 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder", isDirectory: true).resolvingSymlinksInPath?.absoluteString, "file:///path/to/folder") |
| 63 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/folder/", isDirectory: true).resolvingSymlinksInPath?.absoluteString, "file:///path/to/folder") |
| 64 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../folder", isDirectory: true).resolvingSymlinksInPath?.absoluteString, "file:///folder") |
| 65 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./folder/..", isDirectory: true).resolvingSymlinksInPath?.absoluteString, "file:///path/to") |
| 66 | + |
| 67 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/.file", isDirectory: false).resolvingSymlinksInPath?.absoluteString, "file:///path/to/.file") |
| 68 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/file/", isDirectory: false).resolvingSymlinksInPath?.absoluteString, "file:///path/to/file") |
| 69 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/../file", isDirectory: false).resolvingSymlinksInPath?.absoluteString, "file:///file") |
| 70 | + XCTAssertEqual(NSURL(fileURLWithPath: "/path/to/./file/..", isDirectory: false).resolvingSymlinksInPath?.absoluteString, "file:///path/to") |
| 71 | + } |
| 72 | + |
| 73 | + static var allTests: [(String, (TestNSURL) -> () throws -> Void)] { |
| 74 | + let tests: [(String, (TestNSURL) -> () throws -> Void)] = [ |
| 75 | + ("test_absoluteString", test_absoluteString), |
| 76 | + ("test_pathComponents", test_pathComponents), |
| 77 | + ("test_standardized", test_standardized), |
| 78 | + ("test_standardizingPath", test_standardizingPath), |
| 79 | + ("test_resolvingSymlinksInPath", test_resolvingSymlinksInPath), |
| 80 | + ] |
| 81 | + |
| 82 | + return tests |
| 83 | + } |
| 84 | +} |
0 commit comments