|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the swift-libgit2 open source project. |
| 4 | +// |
| 5 | +// Copyright (c) Margins Technologies LLC. |
| 6 | +// Licensed under the Apache License, Version 2.0. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +import CLibgit2 |
| 11 | +import XCTest |
| 12 | +@testable import SwiftLibgit2 |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +final class PathTests: XCTestCaseStopOnFail |
| 17 | +{ |
| 18 | + func testGitPathFS() throws |
| 19 | + { |
| 20 | + XCTAssertEqual(GitPathFS.gitPathFSGeneric.rawValue, GIT_PATH_FS_GENERIC.rawValue) |
| 21 | + XCTAssertEqual(GitPathFS.gitPathFSNTFS.rawValue, GIT_PATH_FS_NTFS.rawValue) |
| 22 | + XCTAssertEqual(GitPathFS.gitPathFSHFS.rawValue, GIT_PATH_FS_HFS.rawValue) |
| 23 | + |
| 24 | + XCTAssertNil(GitPathFS(rawValue: 123)) |
| 25 | + |
| 26 | + XCTAssertEqual(GitPathFS.gitPathFSGeneric.cValue(), GIT_PATH_FS_GENERIC) |
| 27 | + XCTAssertEqual(GitPathFS.gitPathFSNTFS.cValue(), GIT_PATH_FS_NTFS) |
| 28 | + XCTAssertEqual(GitPathFS.gitPathFSHFS.cValue(), GIT_PATH_FS_HFS) |
| 29 | + |
| 30 | + XCTAssertEqual(GitPathFS(cValue: GIT_PATH_FS_GENERIC), .gitPathFSGeneric) |
| 31 | + XCTAssertEqual(GitPathFS(cValue: GIT_PATH_FS_NTFS), .gitPathFSNTFS) |
| 32 | + XCTAssertEqual(GitPathFS(cValue: GIT_PATH_FS_HFS), .gitPathFSHFS) |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + func testGitPathGitFile() throws |
| 38 | + { |
| 39 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitignore.rawValue, GIT_PATH_GITFILE_GITIGNORE.rawValue) |
| 40 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitmodules.rawValue, GIT_PATH_GITFILE_GITMODULES.rawValue) |
| 41 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitattributes.rawValue, GIT_PATH_GITFILE_GITATTRIBUTES.rawValue) |
| 42 | + |
| 43 | + XCTAssertNil(GitPathGitFile(rawValue: 123)) |
| 44 | + |
| 45 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitignore.cValue(), GIT_PATH_GITFILE_GITIGNORE) |
| 46 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitmodules.cValue(), GIT_PATH_GITFILE_GITMODULES) |
| 47 | + XCTAssertEqual(GitPathGitFile.gitPathGitFileGitattributes.cValue(), GIT_PATH_GITFILE_GITATTRIBUTES) |
| 48 | + |
| 49 | + XCTAssertEqual(GitPathGitFile(cValue: GIT_PATH_GITFILE_GITIGNORE), .gitPathGitFileGitignore) |
| 50 | + XCTAssertEqual(GitPathGitFile(cValue: GIT_PATH_GITFILE_GITMODULES), .gitPathGitFileGitmodules) |
| 51 | + XCTAssertEqual(GitPathGitFile(cValue: GIT_PATH_GITFILE_GITATTRIBUTES), .gitPathGitFileGitattributes) |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + func testGitPathIsGitFile() throws |
| 57 | + { |
| 58 | + let pathsTypesAndResults: [(String, GitPathGitFile, Bool)] = |
| 59 | + [ |
| 60 | + (".gitignore" , .gitPathGitFileGitignore, true), |
| 61 | + (".gitmodules", .gitPathGitFileGitmodules, true), |
| 62 | + (".gitattributes", .gitPathGitFileGitattributes, true), |
| 63 | + ("folder/.gitignore", .gitPathGitFileGitignore, false), |
| 64 | + ("folder/.gitmodules", .gitPathGitFileGitmodules, false), |
| 65 | + ("folder/.gitattributes", .gitPathGitFileGitattributes, false), |
| 66 | + ("folder/.gitfile", .gitPathGitFileGitignore, false), |
| 67 | + ("folder/.git", .gitPathGitFileGitignore, false), |
| 68 | + ("gitignore", .gitPathGitFileGitignore, false), |
| 69 | + ("gitmodules" , .gitPathGitFileGitignore, false), |
| 70 | + ("gitattributes", .gitPathGitFileGitignore, false), |
| 71 | + (".git", .gitPathGitFileGitignore, false), |
| 72 | + ("git", .gitPathGitFileGitattributes, false) |
| 73 | + ] |
| 74 | + |
| 75 | + for pathTypeAndResult in pathsTypesAndResults |
| 76 | + { |
| 77 | + let path : String = pathTypeAndResult.0 |
| 78 | + let pathGitFile : GitPathGitFile = pathTypeAndResult.1 |
| 79 | + let expectedResult : Bool = pathTypeAndResult.2 |
| 80 | + |
| 81 | + let isGitfile: Bool? = gitPathIsGitFile( |
| 82 | + path: path, |
| 83 | + pathLen: path.utf8.count, |
| 84 | + gitFile: pathGitFile, |
| 85 | + fs: .gitPathFSGeneric |
| 86 | + ) |
| 87 | + |
| 88 | + XCTAssertNotNil(isGitfile) |
| 89 | + XCTAssertEqual(isGitfile, expectedResult) |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments