From a5b6f5cfb6559eead9c20267aaef9a4d6c8d01fc Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Wed, 6 Nov 2024 15:00:27 +0100 Subject: [PATCH] Add more extensive test for AutoRenamer (#101) * Add more extensive test Signed-off-by: Milen Pivchev * Force check Signed-off-by: Milen Pivchev * Revert "Force check" This reverts commit b7fadf683cb15be6f92ac6d9de6436db5bd4eb9e. * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev * WIP Signed-off-by: Milen Pivchev --------- Signed-off-by: Milen Pivchev Co-authored-by: Marino Faggiana --- .github/workflows/xcode.xxx | 71 ---- .github/workflows/xcode.yml | 96 +++++ .../BaseIntegrationXCTestCase.swift | 7 +- .../Common/BaseXCTestCase.swift | 33 ++ .../Common/TestConstants.swift | 14 + .../FilesIntegrationTests.swift | 34 +- .../ShareIntegrationTests.swift | 30 +- .../FileAutoRenamerUnitTests.swift | 353 ++++++++++++------ 8 files changed, 409 insertions(+), 229 deletions(-) delete mode 100644 .github/workflows/xcode.xxx create mode 100644 .github/workflows/xcode.yml create mode 100644 Tests/NextcloudKitIntegrationTests/Common/BaseXCTestCase.swift create mode 100644 Tests/NextcloudKitIntegrationTests/Common/TestConstants.swift diff --git a/.github/workflows/xcode.xxx b/.github/workflows/xcode.xxx deleted file mode 100644 index b0ace30..0000000 --- a/.github/workflows/xcode.xxx +++ /dev/null @@ -1,71 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors -# SPDX-License-Identifier: GPL-3.0-or-later -name: Build and test - -on: - push: - branches: - - master - - develop - pull_request: - types: [synchronize, opened, reopened, ready_for_review] - branches: - - master - - develop - -env: - DESTINATION_IOS: platform=iOS Simulator,name=iPhone 14 - DESTINATION_MACOS: platform=macOS,arch=x86_64 - SCHEME: NextcloudKit - -jobs: - build-and-test: - name: Build and Test - runs-on: macOS-latest - if: github.event.pull_request.draft == false - steps: - - name: Set env var - run: echo "DEVELOPER_DIR=$(xcode-select --print-path)" >> $GITHUB_ENV - - uses: actions/checkout@v3 - - name: Setup Bundler and Install Gems - run: | - gem install bundler - bundle install - bundle update - - name: Install docker - run: | - # Workaround for https://github.com/actions/runner-images/issues/8104 - brew remove --ignore-dependencies qemu - curl -o ./qemu.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/dc0669eca9479e9eeb495397ba3a7480aaa45c2e/Formula/qemu.rb - brew install ./qemu.rb - - brew install docker - colima start - - name: Create docker test server and export enviroment variables - run: | - source ./create-docker-test-server.sh - if [ ! -f ".env-vars" ]; then - touch .env-vars - echo "export TEST_SERVER_URL=$TEST_SERVER_URL" >> .env-vars - echo "export TEST_USER=$TEST_USER" >> .env-vars - echo "export TEST_APP_PASSWORD=$TEST_APP_PASSWORD" >> .env-vars - fi - - name: Generate EnvVars file - run: | - ./generate-env-vars.sh - - name: Build & Test NextcloudKit - run: | - set -o pipefail && xcodebuild test -scheme "$SCHEME" \ - -destination "$DESTINATION_IOS" \ - -destination "$DESTINATION_MACOS" \ - -enableCodeCoverage YES \ - -test-iterations 3 \ - -retry-tests-on-failure \ - | xcpretty -# Covecov does not yet support pure swift packages. Check here: https://github.com/SlatherOrg/slather/issues/466 -# - name: Upload coverage to codecov -# run: | -# bundle exec slather -# bash <(curl -s https://codecov.io/bash) -f ./cobertura.xml -X coveragepy -X gcov -X xcode -t ${{ secrets.CODECOV_TOKEN }} - - diff --git a/.github/workflows/xcode.yml b/.github/workflows/xcode.yml new file mode 100644 index 0000000..01a0ee6 --- /dev/null +++ b/.github/workflows/xcode.yml @@ -0,0 +1,96 @@ +# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: GPL-3.0-or-later +name: Build and test + +on: + push: + branches: + - master + - develop + pull_request: + types: [synchronize, opened, reopened, ready_for_review] + branches: + - master + - develop + +env: + DESTINATION_IOS: platform=iOS Simulator,name=iPhone 16,OS=18.1 + DESTINATION_MACOS: platform=macOS,arch=x86_64 + SCHEME: NextcloudKit + SERVER_BRANCH: stable28 + PHP_VERSION: 8.2 + +jobs: + build-and-test: + name: Build and Test + runs-on: macos-15 + if: github.event.pull_request.draft == false + steps: + - name: Set env var + run: echo "DEVELOPER_DIR=$(xcode-select --print-path)" >> $GITHUB_ENV + - uses: actions/checkout@v4 + + - name: Set up php ${{ env.PHP_VERSION }} + uses: shivammathur/setup-php@8872c784b04a1420e81191df5d64fbd59d3d3033 # v2.30.0 + with: + php-version: ${{ env.PHP_VERSION }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: apcu, bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql + coverage: none + ini-file: development + # Temporary workaround for missing pcntl_* in PHP 8.3: ini-values: apc.enable_cli=on + ini-values: apc.enable_cli=on, disable_functions= + + - name: Checkout server + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + submodules: true + repository: nextcloud/server + path: server + ref: ${{ env.SERVER_BRANCH }} + + - name: Set up Nextcloud + run: | + mkdir server/data + ./server/occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./server/occ config:system:set hashing_default_password --value=true --type=boolean + ./server/occ config:system:set auth.bruteforce.protection.enabled --value false --type bool + ./server/occ config:system:set ratelimit.protection.enabled --value false --type bool + ./server/occ config:system:set memcache.local --value="\\OC\\Memcache\\APCu" + ./server/occ config:system:set memcache.distributed --value="\\OC\\Memcache\\APCu" + ./server/occ background:cron + PHP_CLI_SERVER_WORKERS=5 php -S localhost:8080 -t server/ & +# - name: Setup Bundler and Install Gems +# run: | +# gem install bundler +# bundle install +# bundle update +# - name: Install docker +# run: | +# # Workaround for https://github.com/actions/runner-images/issues/8104 +# brew remove --ignore-dependencies qemu +# curl -o ./qemu.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/dc0669eca9479e9eeb495397ba3a7480aaa45c2e/Formula/qemu.rb +# brew install ./qemu.rb +# +# brew install docker +# colima start +# - name: Create docker test server and export enviroment variables +# run: | +# source ./create-docker-test-server.sh +# if [ ! -f ".env-vars" ]; then +# touch .env-vars +# echo "export TEST_SERVER_URL=$TEST_SERVER_URL" >> .env-vars +# echo "export TEST_USER=$TEST_USER" >> .env-vars +# echo "export TEST_APP_PASSWORD=$TEST_APP_PASSWORD" >> .env-vars +# fi +# - name: Generate EnvVars file +# run: | +# ./generate-env-vars.sh + - name: Build & Test NextcloudKit + run: | + set -o pipefail && xcodebuild test -scheme "$SCHEME" \ + -destination "$DESTINATION_IOS" \ + -test-iterations 3 \ + -retry-tests-on-failure \ + | xcpretty + diff --git a/Tests/NextcloudKitIntegrationTests/BaseIntegrationXCTestCase.swift b/Tests/NextcloudKitIntegrationTests/BaseIntegrationXCTestCase.swift index 1c29b75..f1841ed 100644 --- a/Tests/NextcloudKitIntegrationTests/BaseIntegrationXCTestCase.swift +++ b/Tests/NextcloudKitIntegrationTests/BaseIntegrationXCTestCase.swift @@ -5,12 +5,7 @@ import XCTest @testable import NextcloudKit -class BaseIntegrationXCTestCase: XCTestCase { - internal let baseUrl = EnvVars.testServerUrl - internal let user = EnvVars.testUser - internal let userId = EnvVars.testUser - internal let password = EnvVars.testAppPassword - internal lazy var account = "\(userId) \(baseUrl)" +class BaseIntegrationXCTestCase: BaseXCTestCase { internal var randomInt: Int { get { return Int.random(in: 1000...Int.max) diff --git a/Tests/NextcloudKitIntegrationTests/Common/BaseXCTestCase.swift b/Tests/NextcloudKitIntegrationTests/Common/BaseXCTestCase.swift new file mode 100644 index 0000000..393d2e7 --- /dev/null +++ b/Tests/NextcloudKitIntegrationTests/Common/BaseXCTestCase.swift @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2024 Milen Pivchev +// SPDX-License-Identifier: GPL-3.0-or-later + +import XCTest +import Foundation +import UIKit +import Alamofire +import NextcloudKit + +class BaseXCTestCase: XCTestCase { + var appToken = "" + + func setupAppToken() { + let expectation = expectation(description: "Should get app token") + + NextcloudKit.shared.getAppPassword(url: TestConstants.server, user: TestConstants.username, password: TestConstants.password) { token, _, error in + XCTAssertEqual(error.errorCode, 0) + XCTAssertNotNil(token) + + guard let token else { return XCTFail() } + + self.appToken = token + expectation.fulfill() + } + + waitForExpectations(timeout: TestConstants.timeoutLong) + } + + override func setUpWithError() throws { + setupAppToken() + } +} diff --git a/Tests/NextcloudKitIntegrationTests/Common/TestConstants.swift b/Tests/NextcloudKitIntegrationTests/Common/TestConstants.swift new file mode 100644 index 0000000..13baf80 --- /dev/null +++ b/Tests/NextcloudKitIntegrationTests/Common/TestConstants.swift @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2024 Milen Pivchev +// SPDX-License-Identifier: GPL-3.0-or-later + +import Foundation +import UIKit + +public class TestConstants { + static let timeoutLong: Double = 400 + static let server = "http://localhost:8080" + static let username = "admin" + static let password = "admin" + static let account = "\(username) \(server)" +} diff --git a/Tests/NextcloudKitIntegrationTests/FilesIntegrationTests.swift b/Tests/NextcloudKitIntegrationTests/FilesIntegrationTests.swift index 9607a6e..c9c3a1b 100644 --- a/Tests/NextcloudKitIntegrationTests/FilesIntegrationTests.swift +++ b/Tests/NextcloudKitIntegrationTests/FilesIntegrationTests.swift @@ -6,17 +6,17 @@ import XCTest @testable import NextcloudKit final class FilesIntegrationTests: BaseIntegrationXCTestCase { - func test_createReadDeleteFolder_withProperParams_shouldCreateReadDeleteFolder() throws { - let expectation = expectation(description: "Should finish last callback") - let folderName = "TestFolder\(randomInt)" - let serverUrl = "\(baseUrl)/remote.php/dav/files/\(userId)" - let serverUrlFileName = "\(serverUrl)/\(folderName)" - - NextcloudKit.shared.appendSession(account: account, urlBase: baseUrl, user: user, userId: userId, password: password, userAgent: "", nextcloudVersion: 0, groupIdentifier: "") - +// func test_createReadDeleteFolder_withProperParams_shouldCreateReadDeleteFolder() throws { +// let expectation = expectation(description: "Should finish last callback") +// let folderName = "TestFolder\(randomInt)" +// let serverUrl = "\(TestConstants.server)/remote.php/dav/files/\(TestConstants.username)" +// let serverUrlFileName = "\(serverUrl)/\(folderName)" +// +// NextcloudKit.shared.appendSession(account: TestConstants.account, urlBase: TestConstants.server, user: TestConstants.username, userId: TestConstants.username, password: TestConstants.password, userAgent: "", nextcloudVersion: 0, groupIdentifier: "") +// // // Test creating folder -// NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName, account: account) { account, ocId, date, error in -// XCTAssertEqual(self.account, account) +// NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName, account: TestConstants.account) { account, ocId, date, _, error in +// XCTAssertEqual(TestConstants.account, account) // // XCTAssertEqual(NKError.success.errorCode, error.errorCode) // XCTAssertEqual(NKError.success.errorDescription, error.errorDescription) @@ -25,7 +25,7 @@ final class FilesIntegrationTests: BaseIntegrationXCTestCase { // // // Test reading folder, should exist // NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", account: account) { account, files, data, error in -// XCTAssertEqual(self.account, account) +// XCTAssertEqual(TestConstants.account, account) // XCTAssertEqual(NKError.success.errorCode, error.errorCode) // XCTAssertEqual(NKError.success.errorDescription, error.errorDescription) // XCTAssertEqual(files?[0].fileName, folderName) @@ -33,8 +33,8 @@ final class FilesIntegrationTests: BaseIntegrationXCTestCase { // Thread.sleep(forTimeInterval: 0.2) // // // Test deleting folder -// NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName, account: account) { account, error in -// XCTAssertEqual(self.account, account) +// NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName, account: account) { account, _, error in +// XCTAssertEqual(TestConstants.account, account) // XCTAssertEqual(NKError.success.errorCode, error.errorCode) // XCTAssertEqual(NKError.success.errorDescription, error.errorDescription) // @@ -45,13 +45,13 @@ final class FilesIntegrationTests: BaseIntegrationXCTestCase { // defer { expectation.fulfill() } // // XCTAssertEqual(404, error.errorCode) -// XCTAssertEqual(self.account, account) +// XCTAssertEqual(TestConstants.account, account) // XCTAssertTrue(files?.isEmpty ?? false) // } // } // } // } - - waitForExpectations(timeout: 100) - } +// +// waitForExpectations(timeout: 100) +// } } diff --git a/Tests/NextcloudKitIntegrationTests/ShareIntegrationTests.swift b/Tests/NextcloudKitIntegrationTests/ShareIntegrationTests.swift index 98b5572..3f52d07 100644 --- a/Tests/NextcloudKitIntegrationTests/ShareIntegrationTests.swift +++ b/Tests/NextcloudKitIntegrationTests/ShareIntegrationTests.swift @@ -7,17 +7,17 @@ import Alamofire @testable import NextcloudKit final class ShareIntegrationTests: BaseIntegrationXCTestCase { - func test_createShare_withNote_shouldCreateShare() throws { - let expectation = expectation(description: "Should finish last callback") - - let folderName = "Share\(randomInt)" - let serverUrl = "\(baseUrl)/remote.php/dav/files/\(userId)" - let serverUrlFileName = "\(serverUrl)/\(folderName)" - - NextcloudKit.shared.appendSession(account: account, urlBase: baseUrl, user: user, userId: userId, password: password, userAgent: "", nextcloudVersion: 0, groupIdentifier: "") - -// NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName, account: account) { account, ocId, date, error in -// XCTAssertEqual(self.account, account) +// func test_createShare_withNote_shouldCreateShare() throws { +// let expectation = expectation(description: "Should finish last callback") +// +// let folderName = "Share\(randomInt)" +// let serverUrl = "\(TestConstants.server)/remote.php/dav/files/\(TestConstants.username)" +// let serverUrlFileName = "\(serverUrl)/\(folderName)" +// +// NextcloudKit.shared.appendSession(account: TestConstants.account, urlBase: TestConstants.server, user: TestConstants.username, userId: TestConstants.username, password: TestConstants.password, userAgent: "", nextcloudVersion: 0, groupIdentifier: "") +// +// NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName, account: TestConstants.account) { account, ocId, date, _, error in +// XCTAssertEqual(TestConstants.account, account) // // XCTAssertEqual(NKError.success.errorCode, error.errorCode) // XCTAssertEqual(NKError.success.errorDescription, error.errorDescription) @@ -29,13 +29,13 @@ final class ShareIntegrationTests: BaseIntegrationXCTestCase { // NextcloudKit.shared.createShare(path: folderName, shareType: 0, shareWith: "nextcloud", note: note, account: "") { account, share, data, error in // defer { expectation.fulfill() } // -// XCTAssertEqual(self.account, account) +// XCTAssertEqual(TestConstants.account, account) // XCTAssertEqual(NKError.success.errorCode, error.errorCode) // XCTAssertEqual(NKError.success.errorDescription, error.errorDescription) // XCTAssertEqual(note, share?.note) // } // } - - waitForExpectations(timeout: 100) - } +// +// waitForExpectations(timeout: 100) +// } } diff --git a/Tests/NextcloudKitUnitTests/FileAutoRenamerUnitTests.swift b/Tests/NextcloudKitUnitTests/FileAutoRenamerUnitTests.swift index 27ba55c..d82ae67 100644 --- a/Tests/NextcloudKitUnitTests/FileAutoRenamerUnitTests.swift +++ b/Tests/NextcloudKitUnitTests/FileAutoRenamerUnitTests.swift @@ -2,174 +2,287 @@ // SPDX-FileCopyrightText: 2024 Milen Pivchev // SPDX-License-Identifier: GPL-3.0-or-later -import XCTest +import Testing @testable import NextcloudKit -final class FileAutoRenamerUnitTests: XCTestCase { +@Suite(.serialized) struct FileAutoRenamerUnitTests { let fileAutoRenamer = FileAutoRenamer.shared let forbiddenFilenameCharacter = ">" let forbiddenFilenameExtension = "." - let initialCharacters = ["<", ">", ":", "\\\\", "/", "|", "?", "*", "&"] - let initialExtensions = [" ", ",", ".", ".filepart", ".part"] + let characterArrays = [ + ["\\\\", "*", ">", "&", "/", "|", ":", "<", "?"], + [">", ":", "?", "&", "*", "\\\\", "|", "<", "/"], + ["<", "|", "?", ":", "&", "*", "\\\\", "/", ">"], + ["?", "/", ":", "&", "<", "|", ">", "\\\\", "*"], + ["&", "<", "|", "*", "/", "?", ">", ":", "\\\\"] + ] - override func setUp() { - fileAutoRenamer.setup( - forbiddenFileNameCharacters: initialCharacters, - forbiddenFileNameExtensions: initialExtensions - ) - super.setUp() - } + let extensionArrays = [ + [" ", ",", ".", ".filepart", ".part"], + [".filepart", ".part", " ", ".", ","], + [".PART", ".", ",", " ", ".filepart"], + [",", " ", ".FILEPART", ".part", "."], + [".", ".PART", ",", " ", ".FILEPART"] + ] - func testInvalidChar() { - let filename = "File\(forbiddenFilenameCharacter)File.txt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "File_File.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") - } + let combinedTuples: [([String], [String])] - func testInvalidExtension() { - let filename = "File\(forbiddenFilenameExtension)" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "File_" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + init() { + combinedTuples = zip(characterArrays, extensionArrays).map { ($0, $1) } } - func testMultipleInvalidChars() { - let filename = "File|name?<>.txt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "File_name___.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testInvalidChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "File\(forbiddenFilenameCharacter)File.txt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "File_File.txt" + #expect(result == expectedFilename) + } } - func testStartEndInvalidExtensions() { - let filename = " .File.part " - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_File_part" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testInvalidExtension() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "File\(forbiddenFilenameExtension)" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "File_" + #expect(result == expectedFilename) + } } - func testStartEndInvalidExtensions2() { - fileAutoRenamer.setup( - forbiddenFileNameCharacters: initialCharacters, - forbiddenFileNameExtensions: [",", ".", ".filepart", ".part", " "] - ) + @Test func testMultipleInvalidChars() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) - let filename = " .File.part " - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_File_part" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + let filename = "File|name?<>.txt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "File_name___.txt" + #expect(result == expectedFilename) + } } - func testStartEndInvalidExtensions3() { - fileAutoRenamer.setup( - forbiddenFileNameCharacters: initialCharacters, - forbiddenFileNameExtensions: [".FILEPART", ".PART", " ", ",", "."] - ) + @Test func testStartEndInvalidExtensions() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) - let filename = " .File.part " - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_File_part" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + let filename = " .File.part " + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "_File_part" + #expect(result == expectedFilename) + } } - func testStartInvalidExtension() { - let filename = " .File.part" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_File_part" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testStartInvalidExtension() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = " .File.part" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "_File_part" + #expect(result == expectedFilename) + } } - func testEndInvalidExtension() { - let filename = ".File.part " - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_File_part" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testEndInvalidExtension() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = ".File.part " + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "_File_part" + #expect(result == expectedFilename) + } } - func testHiddenFile() { - let filename = ".Filename.txt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testHiddenFile() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = ".Filename.txt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "_Filename.txt" + #expect(result == expectedFilename) + } } - func testUppercaseExtension() { - let filename = ".Filename.TXT" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "_Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testUppercaseExtension() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = ".Filename.TXT" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "_Filename.txt" + #expect(result == expectedFilename) + } } - func testMiddleNonPrintableChar() { - let filename = "File\u{0001}name.txt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testMiddleNonPrintableChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "File\u{0001}name.txt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "Filename.txt" + #expect(result == expectedFilename) + } } - func testStartNonPrintableChar() { - let filename = "\u{0001}Filename.txt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testStartNonPrintableChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "\u{0001}Filename.txt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "Filename.txt" + #expect(result == expectedFilename) + } } - func testEndNonPrintableChar() { - let filename = "Filename.txt\u{0001}" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testEndNonPrintableChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "Filename.txt\u{0001}" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "Filename.txt" + #expect(result == expectedFilename) + } } - func testExtensionNonPrintableChar() { - let filename = "Filename.t\u{0001}xt" - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "Filename.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testExtensionNonPrintableChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = "Filename.t\u{0001}xt" + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "Filename.txt" + #expect(result == expectedFilename) + } } - func testMiddleInvalidFolderChar() { - let folderPath = "Abc/Def/kg\(forbiddenFilenameCharacter)/lmo/pp" - let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) - let expectedFolderName = "Abc/Def/kg_/lmo/pp" - XCTAssertEqual(result, expectedFolderName, "Expected \(expectedFolderName) but got \(result)") + @Test func testMiddleInvalidFolderChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let folderPath = "Abc/Def/kg\(forbiddenFilenameCharacter)/lmo/pp" + let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) + let expectedFolderName = "Abc/Def/kg_/lmo/pp" + #expect(result == expectedFolderName) + } } - func testEndInvalidFolderChar() { - let folderPath = "Abc/Def/kg/lmo/pp\(forbiddenFilenameCharacter)" - let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) - let expectedFolderName = "Abc/Def/kg/lmo/pp_" - XCTAssertEqual(result, expectedFolderName, "Expected \(expectedFolderName) but got \(result)") + @Test func testEndInvalidFolderChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let folderPath = "Abc/Def/kg/lmo/pp\(forbiddenFilenameCharacter)" + let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) + let expectedFolderName = "Abc/Def/kg/lmo/pp_" + #expect(result == expectedFolderName) + } } - func testStartInvalidFolderChar() { - let folderPath = "\(forbiddenFilenameCharacter)Abc/Def/kg/lmo/pp" - let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) - let expectedFolderName = "_Abc/Def/kg/lmo/pp" - XCTAssertEqual(result, expectedFolderName, "Expected \(expectedFolderName) but got \(result)") + @Test func testStartInvalidFolderChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let folderPath = "\(forbiddenFilenameCharacter)Abc/Def/kg/lmo/pp" + let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) + let expectedFolderName = "_Abc/Def/kg/lmo/pp" + #expect(result == expectedFolderName) + } } - func testMixedInvalidChar() { - let filename = " File\u{0001}na\(forbiddenFilenameCharacter)me.txt " - let result = fileAutoRenamer.rename(filename: filename) - let expectedFilename = "Filena_me.txt" - XCTAssertEqual(result, expectedFilename, "Expected \(expectedFilename) but got \(result)") + @Test func testMixedInvalidChar() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let filename = " File\u{0001}na\(forbiddenFilenameCharacter)me.txt " + let result = fileAutoRenamer.rename(filename: filename) + let expectedFilename = "Filena_me.txt" + #expect(result == expectedFilename) + } } - func testStartsWithPathSeparator() { - let folderPath = "/Abc/Def/kg/lmo/pp\(forbiddenFilenameCharacter)/File.txt/" - let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) - let expectedFolderName = "/Abc/Def/kg/lmo/pp_/File.txt/" - XCTAssertEqual(result, expectedFolderName, "Expected \(expectedFolderName) but got \(result)") + @Test func testStartsWithPathSeparator() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let folderPath = "/Abc/Def/kg/lmo/pp\(forbiddenFilenameCharacter)/File.txt/" + let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) + let expectedFolderName = "/Abc/Def/kg/lmo/pp_/File.txt/" + #expect(result == expectedFolderName) + } } - func testStartsWithPathSeparatorAndValidFilepath() { - let folderPath = "/COm02/2569.webp" - let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) - let expectedFolderName = "/COm02/2569.webp" - XCTAssertEqual(result, expectedFolderName, "Expected \(expectedFolderName) but got \(result)") + @Test func testStartsWithPathSeparatorAndValidFilepath() { + for (characterArray, extensionArray) in combinedTuples { + fileAutoRenamer.setup( + forbiddenFileNameCharacters: characterArray, + forbiddenFileNameExtensions: extensionArray + ) + + let folderPath = "/COm02/2569.webp" + let result = fileAutoRenamer.rename(filename: folderPath, isFolderPath: true) + let expectedFolderName = "/COm02/2569.webp" + #expect(result == expectedFolderName) + } } }