Convert Foundation Extension Testst o Swift Testing

This commit is contained in:
Otavio Cordeiro 2025-12-22 07:40:39 +01:00 committed by Otávio
parent d4aa1f066f
commit a52511547c
3 changed files with 201 additions and 161 deletions

View file

@ -1,9 +1,11 @@
import XCTest
import Testing
@testable import FoundationExtensions
final class ArrayContainsTests: XCTestCase {
@Suite("ArrayContains Tests")
struct ArrayContainsTests {
func test_containsPartial_withMatchingSubstring_returnsTrue() {
@Test("It should return true when array contains element with matching substring")
func containsPartial_withMatchingSubstring_returnsTrue() {
// Given
let array = ["apple", "banana", "orange"]
let partial = "app"
@ -12,13 +14,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when array contains element with matching substring"
)
}
func test_containsPartial_withMultipleMatches_returnsTrue() {
@Test("It should return true when multiple elements contain the partial string")
func containsPartial_withMultipleMatches_returnsTrue() {
// Given
let array = ["application", "approach", "apple", "banana"]
let partial = "app"
@ -27,13 +30,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when multiple elements contain the partial string"
)
}
func test_containsPartial_withNoMatches_returnsFalse() {
@Test("It should return false when no elements contain the partial string")
func containsPartial_withNoMatches_returnsFalse() {
// Given
let array = ["banana", "orange", "grape"]
let partial = "app"
@ -42,13 +46,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when no elements contain the partial string"
)
}
func test_containsPartial_withUppercasePartial_returnsTrue() {
@Test("It should return true when partial string matches case-insensitively")
func containsPartial_withUppercasePartial_returnsTrue() {
// Given
let array = ["apple", "banana", "orange"]
let partial = "APP"
@ -57,13 +62,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial string matches case-insensitively"
)
}
func test_containsPartial_withMixedCasePartial_returnsTrue() {
@Test("It should return true with mixed case partial string")
func containsPartial_withMixedCasePartial_returnsTrue() {
// Given
let array = ["application", "BANANA", "OrAnGe"]
let partial = "aPp"
@ -72,13 +78,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true with mixed case partial string"
)
}
func test_containsPartial_withUppercaseArrayElements_returnsTrue() {
@Test("It should return true when array elements are uppercase but partial is lowercase")
func containsPartial_withUppercaseArrayElements_returnsTrue() {
// Given
let array = ["APPLE", "BANANA", "ORANGE"]
let partial = "app"
@ -87,13 +94,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when array elements are uppercase but partial is lowercase"
)
}
func test_containsPartial_withEmptyArray_returnsFalse() {
@Test("It should return false when array is empty")
func containsPartial_withEmptyArray_returnsFalse() {
// Given
let array: [String] = []
let partial = "app"
@ -102,13 +110,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when array is empty"
)
}
func test_containsPartial_withEmptyPartialString_returnsFalse() {
@Test("It should return false when partial string is empty (empty string matches nothing)")
func containsPartial_withEmptyPartialString_returnsFalse() {
// Given
let array = ["apple", "banana", "orange"]
let partial = ""
@ -117,13 +126,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when partial string is empty (empty string matches nothing)"
)
}
func test_containsPartial_withEmptyArrayAndEmptyPartial_returnsFalse() {
@Test("It should return false when both array and partial string are empty")
func containsPartial_withEmptyArrayAndEmptyPartial_returnsFalse() {
// Given
let array: [String] = []
let partial = ""
@ -132,13 +142,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when both array and partial string are empty"
)
}
func test_containsPartial_withEmptyStringInArray_returnsFalse() {
@Test("It should return false when array contains empty string and partial is empty (empty string matches nothing)")
func containsPartial_withEmptyStringInArray_returnsFalse() {
// Given
let array = ["apple", "", "banana"]
let partial = ""
@ -147,13 +158,16 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when array contains empty string and partial is empty (empty string matches nothing)"
)
}
func test_containsPartial_withSearchingInEmptyString_returnsFalse() {
@Test(
"It should return true when searching for non-empty partial in array with empty string (should match 'apple')"
)
func containsPartial_withSearchingInEmptyString_returnsFalse() {
// Given
let array = ["apple", "", "banana"]
let partial = "app"
@ -162,13 +176,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when searching for non-empty partial in array with empty string (should match 'apple')"
)
}
func test_containsPartial_withWhitespacePartial_returnsTrue() {
@Test("It should return true when partial is whitespace and array contains strings with spaces")
func containsPartial_withWhitespacePartial_returnsTrue() {
// Given
let array = ["hello world", "banana", "orange"]
let partial = " "
@ -177,13 +192,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial is whitespace and array contains strings with spaces"
)
}
func test_containsPartial_withWhitespaceInPartial_returnsTrue() {
@Test("It should return true when partial contains whitespace and matches substring with spaces")
func containsPartial_withWhitespaceInPartial_returnsTrue() {
// Given
let array = ["hello world", "banana split", "orange juice"]
let partial = "lo wo"
@ -192,13 +208,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial contains whitespace and matches substring with spaces"
)
}
func test_containsPartial_withTrailingWhitespace_returnsTrue() {
@Test("It should return true when array element has trailing whitespace")
func containsPartial_withTrailingWhitespace_returnsTrue() {
// Given
let array = ["apple ", "banana", "orange"]
let partial = "apple"
@ -207,13 +224,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when array element has trailing whitespace"
)
}
func test_containsPartial_withLeadingWhitespace_returnsTrue() {
@Test("It should return true when array element has leading whitespace")
func containsPartial_withLeadingWhitespace_returnsTrue() {
// Given
let array = [" apple", "banana", "orange"]
let partial = "apple"
@ -222,13 +240,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when array element has leading whitespace"
)
}
func test_containsPartial_withSpecialCharacters_returnsTrue() {
@Test("It should return true when partial contains special characters and matches")
func containsPartial_withSpecialCharacters_returnsTrue() {
// Given
let array = ["test@email.com", "user123", "hello-world"]
let partial = "@email"
@ -237,13 +256,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial contains special characters and matches"
)
}
func test_containsPartial_withNumbersInPartial_returnsTrue() {
@Test("It should return true when partial contains numbers and matches")
func containsPartial_withNumbersInPartial_returnsTrue() {
// Given
let array = ["user123", "test456", "admin"]
let partial = "123"
@ -252,13 +272,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial contains numbers and matches"
)
}
func test_containsPartial_withUnicodeCharacters_returnsTrue() {
@Test("It should return true when partial contains unicode characters and matches")
func containsPartial_withUnicodeCharacters_returnsTrue() {
// Given
let array = ["café", "naïve", "résumé"]
let partial = "café"
@ -267,13 +288,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial contains unicode characters and matches"
)
}
func test_containsPartial_withEmojiCharacters_returnsTrue() {
@Test("It should return true when partial contains emoji and matches")
func containsPartial_withEmojiCharacters_returnsTrue() {
// Given
let array = ["Hello 👋", "Good morning", "Have a nice day"]
let partial = "👋"
@ -282,13 +304,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial contains emoji and matches"
)
}
func test_containsPartial_withSingleCharacterPartial_returnsTrue() {
@Test("It should return true when partial is single character and matches")
func containsPartial_withSingleCharacterPartial_returnsTrue() {
// Given
let array = ["apple", "banana", "orange"]
let partial = "a"
@ -297,13 +320,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial is single character and matches"
)
}
func test_containsPartial_withSingleCharacterNoMatch_returnsFalse() {
@Test("It should return false when single character partial doesn't match any element")
func containsPartial_withSingleCharacterNoMatch_returnsFalse() {
// Given
let array = ["apple", "banana", "orange"]
let partial = "z"
@ -312,13 +336,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when single character partial doesn't match any element"
)
}
func test_containsPartial_withSingleCharacterArray_returnsTrue() {
@Test("It should return true when array contains single characters and partial matches")
func containsPartial_withSingleCharacterArray_returnsTrue() {
// Given
let array = ["a", "b", "c"]
let partial = "a"
@ -327,13 +352,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when array contains single characters and partial matches"
)
}
func test_containsPartial_withExactMatch_returnsTrue() {
@Test("It should return true when partial exactly matches an array element")
func containsPartial_withExactMatch_returnsTrue() {
// Given
let array = ["apple", "banana", "orange"]
let partial = "apple"
@ -342,13 +368,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial exactly matches an array element"
)
}
func test_containsPartial_withExactMatchDifferentCase_returnsTrue() {
@Test("It should return true when partial exactly matches with different case")
func containsPartial_withExactMatchDifferentCase_returnsTrue() {
// Given
let array = ["Apple", "Banana", "Orange"]
let partial = "APPLE"
@ -357,13 +384,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial exactly matches with different case"
)
}
func test_containsPartial_withAccentedCharacters_returnsFalse() {
@Test("It should return false when plain text doesn't match accented characters exactly")
func containsPartial_withAccentedCharacters_returnsFalse() {
// Given
let array = ["café", "résumé", "naïve"]
let partial = "cafe"
@ -372,13 +400,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when plain text doesn't match accented characters exactly"
)
}
func test_containsPartial_withMatchingAccentedCharacters_returnsTrue() {
@Test("It should return true when accented characters match exactly")
func containsPartial_withMatchingAccentedCharacters_returnsTrue() {
// Given
let array = ["café", "résumé", "naïve"]
let partial = "café"
@ -387,13 +416,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when accented characters match exactly"
)
}
func test_containsPartial_withGermanUmlaut_returnsFalse() {
@Test("It should return false when plain text doesn't match umlauts exactly")
func containsPartial_withGermanUmlaut_returnsFalse() {
// Given
let array = ["Müller", "Straße", "Käse"]
let partial = "muller"
@ -402,13 +432,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when plain text doesn't match umlauts exactly"
)
}
func test_containsPartial_withMatchingUmlaut_returnsTrue() {
@Test("It should return true when umlauts match exactly")
func containsPartial_withMatchingUmlaut_returnsTrue() {
// Given
let array = ["Müller", "Straße", "Käse"]
let partial = "Müller"
@ -417,13 +448,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when umlauts match exactly"
)
}
func test_containsPartial_withCaseInsensitiveUmlaut_returnsTrue() {
@Test("It should return true when case-insensitive matching works with umlauts")
func containsPartial_withCaseInsensitiveUmlaut_returnsTrue() {
// Given
let array = ["Müller", "Straße", "Käse"]
let partial = "müller"
@ -432,13 +464,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when case-insensitive matching works with umlauts"
)
}
func test_containsPartial_withVeryLongString_returnsTrue() {
@Test("It should return true when searching in very long strings")
func containsPartial_withVeryLongString_returnsTrue() {
// Given
let longString = String(repeating: "a", count: 1000) + "target" + String(repeating: "b", count: 1000)
let array = [longString, "short", "medium"]
@ -448,13 +481,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when searching in very long strings"
)
}
func test_containsPartial_withPartialLongerThanElements_returnsFalse() {
@Test("It should return false when partial string is longer than all array elements")
func containsPartial_withPartialLongerThanElements_returnsFalse() {
// Given
let array = ["a", "bb", "ccc"]
let partial = "longpartialstring"
@ -463,13 +497,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertFalse(
result,
#expect(
!result,
"It should return false when partial string is longer than all array elements"
)
}
func test_containsPartial_withSubstringAtEnd_returnsTrue() {
@Test("It should return true when partial matches at the end of an element")
func containsPartial_withSubstringAtEnd_returnsTrue() {
// Given
let array = ["something", "another", "endapp"]
let partial = "app"
@ -478,13 +513,14 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial matches at the end of an element"
)
}
func test_containsPartial_withSubstringInMiddle_returnsTrue() {
@Test("It should return true when partial matches in the middle of an element")
func containsPartial_withSubstringInMiddle_returnsTrue() {
// Given
let array = ["something", "mapplication", "other"]
let partial = "app"
@ -493,7 +529,7 @@ final class ArrayContainsTests: XCTestCase {
let result = array.containsPartial(partial)
// Then
XCTAssertTrue(
#expect(
result,
"It should return true when partial matches in the middle of an element"
)

View file

@ -1,9 +1,12 @@
import XCTest
import Foundation
import Testing
@testable import FoundationExtensions
final class URLImagePreviewTests: XCTestCase {
@Suite("URLImagePreview Tests")
struct URLImagePreviewTests {
func test_imagePreviewURL_withStandardImageURL_insertsPreviewBeforeExtension() {
@Test("It should replace the file extension with .preview.jpg")
func imagePreviewURL_withStandardImageURL_insertsPreviewBeforeExtension() {
// Given
let url = URL(string: "https://cdn.some.pics/user/image.jpg")!
@ -11,14 +14,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://cdn.some.pics/user/image.preview.jpg",
#expect(
result.absoluteString == "https://cdn.some.pics/user/image.preview.jpg",
"It should replace the file extension with .preview.jpg"
)
}
func test_imagePreviewURL_withPNGImage_insertsPreviewBeforeExtension() {
@Test("It should replace PNG extension with .preview.jpg")
func imagePreviewURL_withPNGImage_insertsPreviewBeforeExtension() {
// Given
let url = URL(string: "https://example.com/photos/sunset.png")!
@ -26,14 +29,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://example.com/photos/sunset.preview.jpg",
#expect(
result.absoluteString == "https://example.com/photos/sunset.preview.jpg",
"It should replace PNG extension with .preview.jpg"
)
}
func test_imagePreviewURL_withNoExtension_appendsPreview() {
@Test("It should append .preview.jpg when there is no file extension")
func imagePreviewURL_withNoExtension_appendsPreview() {
// Given
let url = URL(string: "https://example.com/images/photo")!
@ -41,14 +44,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://example.com/images/photo.preview.jpg",
#expect(
result.absoluteString == "https://example.com/images/photo.preview.jpg",
"It should append .preview.jpg when there is no file extension"
)
}
func test_imagePreviewURL_withComplexFilename_insertsPreviewCorrectly() {
@Test("It should replace the extension with .preview.jpg for complex filenames")
func imagePreviewURL_withComplexFilename_insertsPreviewCorrectly() {
// Given
let url = URL(string: "https://cdn.example.com/user-uploads/my-vacation-photo.jpeg")!
@ -56,14 +59,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://cdn.example.com/user-uploads/my-vacation-photo.preview.jpg",
#expect(
result.absoluteString == "https://cdn.example.com/user-uploads/my-vacation-photo.preview.jpg",
"It should replace the extension with .preview.jpg for complex filenames"
)
}
func test_imagePreviewURL_withQueryParameters_preservesQuery() {
@Test("It should preserve query parameters and use .preview.jpg extension")
func imagePreviewURL_withQueryParameters_preservesQuery() {
// Given
let url = URL(string: "https://api.example.com/images/photo.jpg?size=large&quality=high")!
@ -71,14 +74,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://api.example.com/images/photo.preview.jpg?size=large&quality=high",
#expect(
result.absoluteString == "https://api.example.com/images/photo.preview.jpg?size=large&quality=high",
"It should preserve query parameters and use .preview.jpg extension"
)
}
func test_imagePreviewURL_withNestedDirectories_maintainsDirectoryStructure() {
@Test("It should maintain the full directory structure and use .preview.jpg extension")
func imagePreviewURL_withNestedDirectories_maintainsDirectoryStructure() {
// Given
let url = URL(string: "https://storage.example.com/users/123/albums/vacation/beach.gif")!
@ -86,14 +89,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://storage.example.com/users/123/albums/vacation/beach.preview.jpg",
#expect(
result.absoluteString == "https://storage.example.com/users/123/albums/vacation/beach.preview.jpg",
"It should maintain the full directory structure and use .preview.jpg extension"
)
}
func test_imagePreviewURL_withLocalFileURL_insertsPreviewCorrectly() {
@Test("It should work with local file URLs and use .preview.jpg extension")
func imagePreviewURL_withLocalFileURL_insertsPreviewCorrectly() {
// Given
let url = URL(fileURLWithPath: "/Users/test/Documents/screenshot.png")
@ -101,14 +104,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.path,
"/Users/test/Documents/screenshot.preview.jpg",
#expect(
result.path == "/Users/test/Documents/screenshot.preview.jpg",
"It should work with local file URLs and use .preview.jpg extension"
)
}
func test_imagePreviewURL_withMultipleDots_insertsPreviewBeforeLastExtension() {
@Test("It should replace the last extension with .preview.jpg when multiple dots exist")
func imagePreviewURL_withMultipleDots_insertsPreviewBeforeLastExtension() {
// Given
let url = URL(string: "https://example.com/files/image.backup.jpg")!
@ -116,14 +119,14 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://example.com/files/image.backup.preview.jpg",
#expect(
result.absoluteString == "https://example.com/files/image.backup.preview.jpg",
"It should replace the last extension with .preview.jpg when multiple dots exist"
)
}
func test_imagePreviewURL_withSingleCharacterFilename_insertsPreviewCorrectly() {
@Test("It should handle single character filenames and use .preview.jpg extension")
func imagePreviewURL_withSingleCharacterFilename_insertsPreviewCorrectly() {
// Given
let url = URL(string: "https://example.com/a.jpg")!
@ -131,9 +134,8 @@ final class URLImagePreviewTests: XCTestCase {
let result = url.imagePreviewURL
// Then
XCTAssertEqual(
result.absoluteString,
"https://example.com/a.preview.jpg",
#expect(
result.absoluteString == "https://example.com/a.preview.jpg",
"It should handle single character filenames and use .preview.jpg extension"
)
}

View file

@ -1,9 +1,12 @@
import XCTest
import Foundation
import Testing
@testable import FoundationExtensions
final class URLMarkdownTests: XCTestCase {
@Suite("URLMarkdown Tests")
struct URLMarkdownTests {
func test_markdownFormatted_withTitleAndDefaultIsImage_returnsMarkdownLink() {
@Test("It should return a markdown link with custom title")
func markdownFormatted_withTitleAndDefaultIsImage_returnsMarkdownLink() {
// Given
let url = URL(string: "https://example.com")!
let title = "Example Website"
@ -12,14 +15,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title)
// Then
XCTAssertEqual(
result,
"[Example Website](https://example.com)",
#expect(
result == "[Example Website](https://example.com)",
"It should return a markdown link with custom title"
)
}
func test_markdownFormatted_withTitleAndIsImageFalse_returnsMarkdownLink() {
@Test("It should return a markdown link when isImage is explicitly false")
func markdownFormatted_withTitleAndIsImageFalse_returnsMarkdownLink() {
// Given
let url = URL(string: "https://example.com")!
let title = "Example Website"
@ -28,14 +31,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title, isImage: false)
// Then
XCTAssertEqual(
result,
"[Example Website](https://example.com)",
#expect(
result == "[Example Website](https://example.com)",
"It should return a markdown link when isImage is explicitly false"
)
}
func test_markdownFormatted_withTitleAndIsImageTrue_returnsMarkdownImage() {
@Test("It should return a markdown image with custom alt text")
func markdownFormatted_withTitleAndIsImageTrue_returnsMarkdownImage() {
// Given
let url = URL(string: "https://example.com/image.jpg")!
let title = "My Image"
@ -44,14 +47,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title, isImage: true)
// Then
XCTAssertEqual(
result,
"![My Image](https://example.com/image.jpg)",
#expect(
result == "![My Image](https://example.com/image.jpg)",
"It should return a markdown image with custom alt text"
)
}
func test_markdownFormatted_withNoTitleAndDefaultIsImage_returnsMarkdownLinkWithURL() {
@Test("It should return a markdown link using URL as both title and link when no title provided")
func markdownFormatted_withNoTitleAndDefaultIsImage_returnsMarkdownLinkWithURL() {
// Given
let url = URL(string: "https://example.com")!
@ -59,14 +62,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted()
// Then
XCTAssertEqual(
result,
"[https://example.com](https://example.com)",
#expect(
result == "[https://example.com](https://example.com)",
"It should return a markdown link using URL as both title and link when no title provided"
)
}
func test_markdownFormatted_withNoTitleAndIsImageTrue_returnsMarkdownImageWithURL() {
@Test("It should return a markdown image using URL as both alt text and source when no title provided")
func markdownFormatted_withNoTitleAndIsImageTrue_returnsMarkdownImageWithURL() {
// Given
let url = URL(string: "https://example.com/photo.png")!
@ -74,14 +77,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(isImage: true)
// Then
XCTAssertEqual(
result,
"![https://example.com/photo.png](https://example.com/photo.png)",
#expect(
result == "![https://example.com/photo.png](https://example.com/photo.png)",
"It should return a markdown image using URL as both alt text and source when no title provided"
)
}
func test_markdownFormatted_withEmptyTitle_returnsMarkdownLinkWithURL() {
@Test("It should return a markdown link with empty title text when empty string provided")
func markdownFormatted_withEmptyTitle_returnsMarkdownLinkWithURL() {
// Given
let url = URL(string: "https://example.com")!
let title = ""
@ -90,14 +93,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title)
// Then
XCTAssertEqual(
result,
"[](https://example.com)",
#expect(
result == "[](https://example.com)",
"It should return a markdown link with empty title text when empty string provided"
)
}
func test_markdownFormatted_withEmptyTitleAndIsImageTrue_returnsMarkdownImageWithEmptyAlt() {
@Test("It should return a markdown image with empty alt text when empty string provided")
func markdownFormatted_withEmptyTitleAndIsImageTrue_returnsMarkdownImageWithEmptyAlt() {
// Given
let url = URL(string: "https://example.com/image.gif")!
let title = ""
@ -106,14 +109,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title, isImage: true)
// Then
XCTAssertEqual(
result,
"![](https://example.com/image.gif)",
#expect(
result == "![](https://example.com/image.gif)",
"It should return a markdown image with empty alt text when empty string provided"
)
}
func test_markdownFormatted_withComplexURL_returnsCorrectMarkdownLink() {
@Test("It should handle complex URLs with paths, queries, and fragments")
func markdownFormatted_withComplexURL_returnsCorrectMarkdownLink() {
// Given
let url = URL(string: "https://example.com/path/to/resource?query=value&other=param#section")!
let title = "Complex URL"
@ -122,14 +125,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title)
// Then
XCTAssertEqual(
result,
"[Complex URL](https://example.com/path/to/resource?query=value&other=param#section)",
#expect(
result == "[Complex URL](https://example.com/path/to/resource?query=value&other=param#section)",
"It should handle complex URLs with paths, queries, and fragments"
)
}
func test_markdownFormatted_withLocalFileURL_returnsCorrectMarkdownLink() {
@Test("It should handle local file URLs correctly")
func markdownFormatted_withLocalFileURL_returnsCorrectMarkdownLink() {
// Given
let url = URL(fileURLWithPath: "/Users/test/document.pdf")
let title = "Local Document"
@ -138,14 +141,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title)
// Then
XCTAssertEqual(
result,
"[Local Document](file:///Users/test/document.pdf)",
#expect(
result == "[Local Document](file:///Users/test/document.pdf)",
"It should handle local file URLs correctly"
)
}
func test_markdownFormatted_withSpecialCharactersInTitle_returnsMarkdownLinkWithSpecialChars() {
@Test("It should preserve special characters in title without escaping")
func markdownFormatted_withSpecialCharactersInTitle_returnsMarkdownLinkWithSpecialChars() {
// Given
let url = URL(string: "https://example.com")!
let title = "Special [Characters] & Symbols"
@ -154,14 +157,14 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title)
// Then
XCTAssertEqual(
result,
"[Special [Characters] & Symbols](https://example.com)",
#expect(
result == "[Special [Characters] & Symbols](https://example.com)",
"It should preserve special characters in title without escaping"
)
}
func test_markdownFormatted_withUnicodeInTitle_returnsMarkdownLinkWithUnicode() {
@Test("It should handle unicode characters and emojis in title correctly")
func markdownFormatted_withUnicodeInTitle_returnsMarkdownLinkWithUnicode() {
// Given
let url = URL(string: "https://example.com")!
let title = "Café & Naïve résumé 🌟"
@ -170,9 +173,8 @@ final class URLMarkdownTests: XCTestCase {
let result = url.markdownFormatted(title: title, isImage: true)
// Then
XCTAssertEqual(
result,
"![Café & Naïve résumé 🌟](https://example.com)",
#expect(
result == "![Café & Naïve résumé 🌟](https://example.com)",
"It should handle unicode characters and emojis in title correctly"
)
}