From c1323eddd6f0a95ec603fb21c193af3a1e69ba15 Mon Sep 17 00:00:00 2001 From: JP Toro Date: Sat, 1 Feb 2025 11:21:11 -0500 Subject: [PATCH] Fix SwiftLint errors. Clean up tests. --- Tests/IgniteTesting/Elements/Code.swift | 2 +- Tests/IgniteTesting/Elements/CodeBlock.swift | 2 +- Tests/IgniteTesting/Elements/Divider.swift | 2 +- Tests/IgniteTesting/Elements/MetaLink.swift | 8 +- .../Extensions/Array-LocalizedContains.swift | 14 +- .../Extensions/Date-ISO8601.swift | 2 +- .../Extensions/Date-RFC822.swift | 10 +- .../Extensions/String-Slug.swift | 4 +- .../Extensions/URL-RemovingWWW.swift | 14 +- .../IgniteTesting/Modifiers/MediaQuery.swift | 16 +- .../Publishing/FeedGenerator.swift | 2 +- Tests/IgniteTesting/Publishing/Site.swift | 32 ++-- .../TestWebsitePackage/Sources/TestSite.swift | 5 +- Tests/IgniteTesting/Types/AnchorPoint.swift | 91 ++-------- Tests/IgniteTesting/Types/InlineStyle.swift | 33 ++-- Tests/IgniteTesting/Types/LengthUnit.swift | 63 ++----- Tests/IgniteTesting/Types/Percentage.swift | 45 ++--- Tests/IgniteTesting/Types/UnitPoint.swift | 157 +++++++----------- 18 files changed, 181 insertions(+), 321 deletions(-) diff --git a/Tests/IgniteTesting/Elements/Code.swift b/Tests/IgniteTesting/Elements/Code.swift index ecdbe0e8..79374b3c 100644 --- a/Tests/IgniteTesting/Elements/Code.swift +++ b/Tests/IgniteTesting/Elements/Code.swift @@ -14,7 +14,7 @@ import Testing @Suite("Code Tests") @MainActor struct CodeTests { - @Test("Test inline code formatting") + @Test("Inline code formatting") func inlineCode() async throws { let element = Code("background-color") let output = element.render() diff --git a/Tests/IgniteTesting/Elements/CodeBlock.swift b/Tests/IgniteTesting/Elements/CodeBlock.swift index 8569b5a3..a6cbd68f 100644 --- a/Tests/IgniteTesting/Elements/CodeBlock.swift +++ b/Tests/IgniteTesting/Elements/CodeBlock.swift @@ -14,7 +14,7 @@ import Testing @Suite("CodeBlock Tests") @MainActor struct CodeBlockTests { - @Test("Test rendering a code block") + @Test("Rendering a code block") func codeBlockTest() { let element = CodeBlock { """ diff --git a/Tests/IgniteTesting/Elements/Divider.swift b/Tests/IgniteTesting/Elements/Divider.swift index 260d37c3..077bcdb6 100644 --- a/Tests/IgniteTesting/Elements/Divider.swift +++ b/Tests/IgniteTesting/Elements/Divider.swift @@ -14,7 +14,7 @@ import Testing @Suite("Divider Tests") @MainActor struct DividerTests { - @Test("Test a single divider") + @Test("A single divider") func singleDivider() async throws { let element = Divider() let output = element.render() diff --git a/Tests/IgniteTesting/Elements/MetaLink.swift b/Tests/IgniteTesting/Elements/MetaLink.swift index 15addb02..1376e2a4 100644 --- a/Tests/IgniteTesting/Elements/MetaLink.swift +++ b/Tests/IgniteTesting/Elements/MetaLink.swift @@ -14,7 +14,7 @@ import Testing @Suite("MetaLink Tests") @MainActor struct MetaLinkTests { - @Test("Test with href string and rel string") + @Test("href string and rel string") func hrefStringAndRelString() async throws { let element = MetaLink(href: "https://www.example.com", rel: "canonical") let output = element.render() @@ -22,7 +22,7 @@ struct MetaLinkTests { #expect(output == "") } - @Test("Test href URL and rel string") + @Test("href URL and rel string") func hrefURLAndRelString() async throws { let url = try #require(URL(string: "https://www.example.com")) let element = MetaLink(href: url, rel: "canonical") @@ -31,7 +31,7 @@ struct MetaLinkTests { #expect(output == "") } - @Test("Test href string and rel Link.Relationship") + @Test("href string and rel Link.Relationship") func hrefStringAndRelRelationship() async throws { let element = MetaLink(href: "https://www.example.com", rel: .external) let output = element.render() @@ -39,7 +39,7 @@ struct MetaLinkTests { #expect(output == "") } - @Test("Test href URL and rel Link.Relationship") + @Test("href URL and rel Link.Relationship") func hrefURLAndRelRelationship() async throws { let url = try #require(URL(string: "https://www.example.com")) let element = MetaLink(href: url, rel: .alternate) diff --git a/Tests/IgniteTesting/Extensions/Array-LocalizedContains.swift b/Tests/IgniteTesting/Extensions/Array-LocalizedContains.swift index 5b5c4918..04cc9ceb 100644 --- a/Tests/IgniteTesting/Extensions/Array-LocalizedContains.swift +++ b/Tests/IgniteTesting/Extensions/Array-LocalizedContains.swift @@ -14,7 +14,7 @@ import Testing @Suite("Array-LocalizedContains Tests") @MainActor struct ArrayLocalizedContainsTests { - @Test("Test case when array contains a matching string") + @Test("Array contains a matching string") func arrayContainsMatchingString() async throws { // Given let testArray = ["Tom", "Jerry", "Nibbles", "Butch"] @@ -34,7 +34,7 @@ struct ArrayLocalizedContainsTests { #expect(result4 == true) } - @Test("Test case when array does NOT contain a matching string") + @Test("Array does NOT contain a matching string") func arrayDoesNotContainMatchingString() async throws { // Given let testArray = ["Tom", "Jerry", "Nibbles", "Butch"] @@ -54,7 +54,7 @@ struct ArrayLocalizedContainsTests { #expect(result4 == false) } - @Test("Test case for strings with diacritics") + @Test("Strings with diacritics") func arrayContainsStringsWithDiacritics() async throws { // Given let testArray = ["über", "jalapeño", "façade", "naïve"] @@ -69,7 +69,7 @@ struct ArrayLocalizedContainsTests { #expect(actualCount == expectedCount) } - @Test("Test case for strings with currently unsupported diacritics") + @Test("Strings with currently unsupported diacritics") func arrayContainsUnsupportedDiacritics() async throws { // Given let testArray = ["łódź", "følg", "zażółć"] @@ -83,7 +83,7 @@ struct ArrayLocalizedContainsTests { #expect(actualCount == 0) } - @Test("Test case for strings with special characters") + @Test("Strings with special characters") func arrayContainsSpecialCharacters() async throws { // Given let testArray = ["!@#$%^", "&*()_+", "-=~`|", "{[}]\\", ":;\"'<", ">?/.,"] @@ -98,7 +98,7 @@ struct ArrayLocalizedContainsTests { #expect(actualCount == expectedCount) } - @Test("Test case for an empty string") + @Test("Empty string") func usingLocalizedContains_forAnEmptyString() async throws { // Given let testArray = [" ", "", "", "empty"] @@ -109,7 +109,7 @@ struct ArrayLocalizedContainsTests { #expect(result == false) } - @Test("Test case when array is empty") + @Test("Array is empty") func callingLocalizedContains_onAnEmptyArray() async throws { // Given let testArray = [String]() diff --git a/Tests/IgniteTesting/Extensions/Date-ISO8601.swift b/Tests/IgniteTesting/Extensions/Date-ISO8601.swift index b09bc915..e6bbd1b0 100644 --- a/Tests/IgniteTesting/Extensions/Date-ISO8601.swift +++ b/Tests/IgniteTesting/Extensions/Date-ISO8601.swift @@ -20,7 +20,7 @@ struct DateISO8601Tests { let expected: String } - @Test("Test Against Known Output", arguments: [ + @Test("Known Output", arguments: [ Instance(input: Date(timeIntervalSince1970: -40241318220), expected: "0694-10-18T00:03:00Z"), Instance(input: Date(timeIntervalSince1970: 36571335925), expected: "3128-11-25T08:25:25Z"), Instance(input: Date(timeIntervalSince1970: 18980973526), expected: "2571-06-26T04:38:46Z"), diff --git a/Tests/IgniteTesting/Extensions/Date-RFC822.swift b/Tests/IgniteTesting/Extensions/Date-RFC822.swift index e2f6e860..63b83df5 100644 --- a/Tests/IgniteTesting/Extensions/Date-RFC822.swift +++ b/Tests/IgniteTesting/Extensions/Date-RFC822.swift @@ -25,7 +25,7 @@ struct DateRFC822Tests { let expected: String } - @Test("Test Against Known Output for Greenwich Mean Time", arguments: [ + @Test("Known Output for Greenwich Mean Time", arguments: [ Instance(input: Date(timeIntervalSince1970: 20012346618.957466), expected: "Fri, 02 Mar 2604 09:10:18 +0000"), Instance(input: Date(timeIntervalSince1970: 56076958399.89086), expected: "Tue, 03 Jan 3747 20:53:19 +0000"), Instance(input: Date(timeIntervalSince1970: 43889947931.30432), expected: "Sat, 25 Oct 3360 12:12:11 +0000"), @@ -43,7 +43,7 @@ struct DateRFC822Tests { #expect(instance.input.asRFC822(timeZone: timezone) == instance.expected) } - @Test("Test Against Known Output for New York Time", arguments: [ + @Test("Known Output for New York Time", arguments: [ Instance(input: Date(timeIntervalSince1970: 20012346618.957466), expected: "Fri, 02 Mar 2604 04:10:18 -0500"), Instance(input: Date(timeIntervalSince1970: 56076958399.89086), expected: "Tue, 03 Jan 3747 15:53:19 -0500"), Instance(input: Date(timeIntervalSince1970: 43889947931.30432), expected: "Sat, 25 Oct 3360 08:12:11 -0400"), @@ -63,7 +63,7 @@ struct DateRFC822Tests { #expect(instance.input.asRFC822(timeZone: timezone) == instance.expected) } - @Test("Test Against Known Output for America/St Johns Time", arguments: [ + @Test("Known Output for America/St Johns Time", arguments: [ Instance(input: Date(timeIntervalSince1970: 20012346618.957466), expected: "Fri, 02 Mar 2604 05:40:18 -0330"), Instance(input: Date(timeIntervalSince1970: 56076958399.89086), expected: "Tue, 03 Jan 3747 17:23:19 -0330"), Instance(input: Date(timeIntervalSince1970: 43889947931.30432), expected: "Sat, 25 Oct 3360 09:42:11 -0230"), @@ -84,7 +84,7 @@ struct DateRFC822Tests { #expect(instance.input.asRFC822(timeZone: timezone) == instance.expected) } - @Test("Test Against Known Output for Asia/Jakarta Time", arguments: [ + @Test("Known Output for Asia/Jakarta Time", arguments: [ Instance(input: Date(timeIntervalSince1970: 20012346618.957466), expected: "Fri, 02 Mar 2604 16:10:18 +0700"), Instance(input: Date(timeIntervalSince1970: 56076958399.89086), expected: "Wed, 04 Jan 3747 03:53:19 +0700"), Instance(input: Date(timeIntervalSince1970: 43889947931.30432), expected: "Sat, 25 Oct 3360 19:12:11 +0700"), @@ -105,7 +105,7 @@ struct DateRFC822Tests { #expect(instance.input.asRFC822(timeZone: timezone) == instance.expected) } - @Test("Test Against Known Output for Asia/Kolkata Time", arguments: [ + @Test("Known Output for Asia/Kolkata Time", arguments: [ Instance(input: Date(timeIntervalSince1970: 20012346618.957466), expected: "Fri, 02 Mar 2604 14:40:18 +0530"), Instance(input: Date(timeIntervalSince1970: 56076958399.89086), expected: "Wed, 04 Jan 3747 02:23:19 +0530"), Instance(input: Date(timeIntervalSince1970: 43889947931.30432), expected: "Sat, 25 Oct 3360 17:42:11 +0530"), diff --git a/Tests/IgniteTesting/Extensions/String-Slug.swift b/Tests/IgniteTesting/Extensions/String-Slug.swift index 9ab3b367..24785ae4 100644 --- a/Tests/IgniteTesting/Extensions/String-Slug.swift +++ b/Tests/IgniteTesting/Extensions/String-Slug.swift @@ -206,7 +206,7 @@ struct StringSlugTests { #expect(instance.input.convertedToSlug() == instance.expected) } - @Test("Test Against URL Strings", arguments: [ + @Test("URL Strings", arguments: [ Instance(input: "https://github.com/twostraws/Ignite", expected: "https-github-com-twostraws--ignite"), Instance(input: "https://github.com/twostraws/Ignite/", expected: "https-github-com-twostraws--ignite"), Instance(input: "file:/Users/george/Documents", expected: "file--users-george--documents") @@ -215,7 +215,7 @@ struct StringSlugTests { #expect(instance.input.convertedToSlug() == instance.expected) } - @Test("Test Against paths", arguments: [ + @Test("Paths", arguments: [ Instance(input: "/Users/george/Documents", expected: "-users-george--documents"), Instance(input: "/twostraws/Ignite", expected: "twostraws--ignite"), Instance(input: "~/Documents", expected: "-documents"), diff --git a/Tests/IgniteTesting/Extensions/URL-RemovingWWW.swift b/Tests/IgniteTesting/Extensions/URL-RemovingWWW.swift index ff21b41f..330cb139 100644 --- a/Tests/IgniteTesting/Extensions/URL-RemovingWWW.swift +++ b/Tests/IgniteTesting/Extensions/URL-RemovingWWW.swift @@ -14,7 +14,7 @@ import Testing @Suite("URL-RemovingWWW Tests") @MainActor struct URLRemovingWWWTests { - @Test("Test case when URL contains 'www'") + @Test("URL contains 'www'") func removingWWW_fromURLWithWWW() async throws { // Given let url = URL(string: "https://www.example.com")! @@ -24,7 +24,7 @@ struct URLRemovingWWWTests { #expect(result == "example.com") } - @Test("Test case when URL does NOT contain 'www") + @Test("URL does NOT contain 'www") func removingWWW_fromURLWithoutWWW() async throws { // Given let url = URL(string: "https://example.com")! @@ -34,7 +34,7 @@ struct URLRemovingWWWTests { #expect(result == "example.com") } - @Test("Test case when URL contains 'www' in the subdomain") + @Test("URL contains 'www' in the subdomain") func removingWWW_fromURLWithSubdomain() async throws { // Given let url1 = URL(string: "https://www.blog.example.com")! @@ -47,7 +47,7 @@ struct URLRemovingWWWTests { #expect(result2 == "longersubdomain.blog.example.com") } - @Test("Test case when URL contains 'www' and also contains a path") + @Test("URL contains 'www' and also contains a path") func removingWWW_fromURLWithPath() async throws { // Given let url = URL(string: "https://www.example.com/path/to/resource")! @@ -57,7 +57,7 @@ struct URLRemovingWWWTests { #expect(result == "example.com") // ignores path } - @Test("Test case when URL has an invalid scheme") + @Test("URL has an invalid scheme") func removingWWW_fromURLWithInvalidScheme() async throws { // Given let url = URL(string: "htp://www.example.com")! // host extraction will succeed @@ -67,7 +67,7 @@ struct URLRemovingWWWTests { #expect(result == "example.com") } - @Test("Test case when URL contains www in domain or subdomain") + @Test(" URL contains www in domain or subdomain") func removingWWW_fromURLWithWWWInDomainOrSubdomain() async throws { // Given let url1 = URL(string: "https://wwwmywww.example.com")! @@ -83,7 +83,7 @@ struct URLRemovingWWWTests { #expect(result3 == "www.com") } - @Test("Test case when URL contains an empty host") + @Test("URL contains an empty host") func removingWWW_fromURLWithEmptyHost() async throws { // Given let url = URL(string: "https://www.")! diff --git a/Tests/IgniteTesting/Modifiers/MediaQuery.swift b/Tests/IgniteTesting/Modifiers/MediaQuery.swift index 146b000d..8613c82c 100644 --- a/Tests/IgniteTesting/Modifiers/MediaQuery.swift +++ b/Tests/IgniteTesting/Modifiers/MediaQuery.swift @@ -17,7 +17,7 @@ struct MediaQueryTests { typealias MediaQueryTestCase = (query: MediaQuery, output: String) - @Test("Test breakpoint queries", arguments: [ + @Test("Breakpoint queries", arguments: [ (query: MediaQuery.breakpoint(.small), output: "min-width: 576px"), (query: MediaQuery.breakpoint(.medium), @@ -38,7 +38,7 @@ struct MediaQueryTests { ) } - @Test("Test color scheme queries", arguments: [ + @Test("Color scheme queries", arguments: [ (query: MediaQuery.colorScheme(.light), output: "prefers-color-scheme: light"), (query: MediaQuery.colorScheme(.dark), @@ -53,7 +53,7 @@ struct MediaQueryTests { ) } - @Test("Test contrast queries", arguments: [ + @Test("Contrast queries", arguments: [ (query: MediaQuery.contrast(.high), output: "prefers-contrast: more"), (query: MediaQuery.contrast(.low), @@ -72,7 +72,7 @@ struct MediaQueryTests { ) } - @Test("Test display mode queries", arguments: [ + @Test("Display mode queries", arguments: [ (query: MediaQuery.displayMode(.fullscreen), output: "display-mode: fullscreen"), (query: MediaQuery.displayMode(.browser), @@ -95,7 +95,7 @@ struct MediaQueryTests { ) } - @Test("Test orientation queries", arguments: [ + @Test("Orientation queries", arguments: [ (query: MediaQuery.orientation(.landscape), output: "orientation: landscape"), (query: MediaQuery.orientation(.portrait), @@ -110,7 +110,7 @@ struct MediaQueryTests { ) } - @Test("Test transparency queries", arguments: [ + @Test("Transparency queries", arguments: [ (query: MediaQuery.transparency(.normal), output: "prefers-reduced-transparency: no-preference"), (query: MediaQuery.transparency(.reduced), @@ -123,7 +123,7 @@ struct MediaQueryTests { #expect(output == testCase.output) } - @Test("Test reduced motion queries", arguments: [ + @Test("Reduced motion queries", arguments: [ (query: MediaQuery.motion(.reduced), output: "prefers-reduced-motion: reduce"), (query: MediaQuery.motion(.allowed), @@ -138,7 +138,7 @@ struct MediaQueryTests { ) } - @Test("Test theme queries", arguments: [ + @Test("Theme queries", arguments: [ (query: MediaQuery.theme("dark"), output: "data-theme-state=\"dark\""), (query: MediaQuery.theme("light"), diff --git a/Tests/IgniteTesting/Publishing/FeedGenerator.swift b/Tests/IgniteTesting/Publishing/FeedGenerator.swift index e08336e1..6f3b16ba 100644 --- a/Tests/IgniteTesting/Publishing/FeedGenerator.swift +++ b/Tests/IgniteTesting/Publishing/FeedGenerator.swift @@ -20,7 +20,7 @@ struct FeedGeneratorTests { TestSite(timeZone: .init(abbreviation: "EST")!) ] - @Test("Test generateFeed", arguments: await sites) + @Test("generateFeed()", arguments: await sites) func generateFeed(for site: any Site) async throws { let feedHref = site.url.appending(path: site.feedConfiguration.path).absoluteString var exampleContent = Content() diff --git a/Tests/IgniteTesting/Publishing/Site.swift b/Tests/IgniteTesting/Publishing/Site.swift index 845e7ba0..32a7ec69 100644 --- a/Tests/IgniteTesting/Publishing/Site.swift +++ b/Tests/IgniteTesting/Publishing/Site.swift @@ -20,11 +20,11 @@ import Testing @MainActor struct SiteTests { private let package = TestPackage() - + init() { try? package.clearBuildFolderAndTestContent() } - + @Test("Site published when Markdown content contains invalid lastModified date") func publishingWithInvalidLastModifiedDate() async throws { let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-invalid-lastModified.md") @@ -33,19 +33,19 @@ struct SiteTests { layout: TestStory lastModified: 03-30-2020 16:37:21 --- - + # Story with invalid lastModified """ - + try markdownContent.write(to: markdownFileURL, atomically: false, encoding: .utf8) - + try await TestSitePublisher().publish() - + #expect(package.checkIndexFileExists() == true) - + try package.clearBuildFolderAndTestContent() } - + @Test("Site published given Markdown content with valid metadata") func publishingWithMarkdownContent() async throws { let markdownFileURL = package.contentDirectoryURL.appending(path: "story-with-valid-metadata.md") @@ -54,16 +54,16 @@ struct SiteTests { layout: TestStory lastModified: 2020-03-30 16:37 --- - + # Story with valid metadata """ - + try markdownContent.write(to: markdownFileURL, atomically: false, encoding: .utf8) - + try await TestSitePublisher().publish() - + #expect(package.checkIndexFileExists() == true) - + try package.clearBuildFolderAndTestContent() } } @@ -72,7 +72,7 @@ private struct TestPackage { let packageBaseURL: URL let buildDirectoryURL: URL let contentDirectoryURL: URL - + init() { packageBaseURL = URL(filePath: #filePath, directoryHint: .isDirectory) .deletingLastPathComponent() // "Site.swift" @@ -81,11 +81,11 @@ private struct TestPackage { buildDirectoryURL = packageBaseURL.appending(path: "Build") contentDirectoryURL = packageBaseURL.appending(path: "Content") } - + func checkIndexFileExists() -> Bool { (try? buildDirectoryURL.appending(path: "index.html").checkPromisedItemIsReachable()) ?? false } - + func clearBuildFolderAndTestContent() throws { try FileManager.default.removeItem(at: buildDirectoryURL) let enumerator = FileManager.default.enumerator(at: contentDirectoryURL, includingPropertiesForKeys: nil) diff --git a/Tests/IgniteTesting/TestWebsitePackage/Sources/TestSite.swift b/Tests/IgniteTesting/TestWebsitePackage/Sources/TestSite.swift index 8b112d1b..78a51741 100644 --- a/Tests/IgniteTesting/TestWebsitePackage/Sources/TestSite.swift +++ b/Tests/IgniteTesting/TestWebsitePackage/Sources/TestSite.swift @@ -24,7 +24,7 @@ struct TestSite: Site { contentCount: 20, image: .init(url: "path/to/image.png", width: 100, height: 100) ) - + var contentLayouts: [any ContentLayout] = [ TestStory() ] @@ -50,9 +50,8 @@ struct TestLayout: StaticLayout { /// It helps to run `TestSite/publish` with a correct path of the file that triggered the build. @MainActor struct TestSitePublisher { - let site = TestSite() - + func publish() async throws { try await site.publish() } diff --git a/Tests/IgniteTesting/Types/AnchorPoint.swift b/Tests/IgniteTesting/Types/AnchorPoint.swift index 41e00f1c..9049ea81 100644 --- a/Tests/IgniteTesting/Types/AnchorPoint.swift +++ b/Tests/IgniteTesting/Types/AnchorPoint.swift @@ -14,86 +14,29 @@ import Testing @Suite("AnchorPoint Tests") @MainActor struct AnchorPointTests { - @Test("Test the center anchor point.") - func centerAnchorPoint() async throws { - let element = AnchorPoint.center + static let anchorPoints: [AnchorPoint] = [ + .center, .topLeft, .topRight, + .bottomLeft, .bottomRight, .top, + .bottom, .left, .right + ] - #expect( - element.value == "center") - } - - @Test("Test the top left anchor point.") - func topLeftAnchorPoint() async throws { - let element = AnchorPoint.topLeft - - #expect( - element.value == "top left") - } - - @Test("Test the top right anchor point.") - func topRightAnchorPoint() async throws { - let element = AnchorPoint.topRight - - #expect( - element.value == "top right") - } - - @Test("Test the bottom left anchor point.") - func bottomLeftAnchorPoint() async throws { - let element = AnchorPoint.bottomLeft - - #expect( - element.value == "bottom left") - } - - @Test("Test the bottom right anchor point.") - func bottomRightAnchorPoint() async throws { - let element = AnchorPoint.bottomRight - - #expect( - element.value == "bottom right") - } - - @Test("Test the top anchor point.") - func topAnchorPoint() async throws { - let element = AnchorPoint.top - - #expect( - element.value == "top") - } - - @Test("Test the bottom anchor point.") - func bottomAnchorPoint() async throws { - let element = AnchorPoint.bottom - - #expect( - element.value == "bottom") - } - - @Test("Test the left anchor point.") - func leftAnchorPoint() async throws { - let element = AnchorPoint.left - - #expect( - element.value == "left") - } - - @Test("Test the right anchor point.") - func rightAnchorPoint() async throws { - let element = AnchorPoint.right + static let anchorPointCSSValues = [ + "center", "top left", "top right", + "bottom left", "bottom right", "top", + "bottom", "left", "right" + ] - #expect( - element.value == "right") + @Test("Anchor point", arguments: await zip(anchorPoints, anchorPointCSSValues)) + func anchorPoint(_ anchorPoint: AnchorPoint, css: String) async throws { + #expect(anchorPoint.value == css) } - static let xCoordinates: [String] = ["1", "2", "3", "4", "5"] - static let yCoordinates: [String] = ["6", "7", "8", "9", "10"] + static let xCoordinates = ["1", "2", "3", "4", "5"] + static let yCoordinates = ["6", "7", "8", "9", "10"] - @Test("Test the custom anchor point.", arguments: zip(await Self.xCoordinates, await Self.yCoordinates)) + @Test("Custom anchor point", arguments: zip(await Self.xCoordinates, await Self.yCoordinates)) func customAnchorPoint(xCoord: String, yCoord: String) async throws { let element = AnchorPoint.custom(x: xCoord, y: yCoord) - - #expect( - element.value == "\(xCoord) \(yCoord)") + #expect(element.value == "\(xCoord) \(yCoord)") } } diff --git a/Tests/IgniteTesting/Types/InlineStyle.swift b/Tests/IgniteTesting/Types/InlineStyle.swift index ac9602c9..63f97686 100644 --- a/Tests/IgniteTesting/Types/InlineStyle.swift +++ b/Tests/IgniteTesting/Types/InlineStyle.swift @@ -14,28 +14,35 @@ import Testing @Suite("InlineStyle Tests") @MainActor struct InlineStyleTests { - @Test("Test correct description for property string initializer.") + @Test("Description for property string initializer") func descriptionPropertyStringInit() async throws { let example = InlineStyle("font-size", value: "25px") - #expect(example.description == "font-size: 25px") } - @Test("Test correct description for property initializer.") + @Test("Description for property initializer") func descriptionPropertyInit() async throws { let example = InlineStyle(Property.fontSize, value: "25px") - #expect(example.description == "font-size: 25px") } - @Test("Test comparable operator.", arguments: [ - (InlineStyle(.absolutePosition, value: "top"), InlineStyle(.accentColor, value: "red"), true), - (InlineStyle(.backgroundColor, value: "red"), InlineStyle(.absolutePosition, value: "top"), false), - (InlineStyle(.textAlign, value: "center"), InlineStyle(.color, value: "red"), false), - (InlineStyle(.justifyContent, value: "space-between"), InlineStyle(.alignItems, value: "end"), false) - ]) - func comparable(lhs: InlineStyle, rhs: InlineStyle, expected: Bool) async throws { - #expect((lhs < rhs) == expected) - #expect((lhs > rhs) == !expected) + static let stylePairs: [(lhs: InlineStyle, rhs: InlineStyle)] = [ + (.init(.absolutePosition, value: "top"), .init(.accentColor, value: "red")), + (.init(.backgroundColor, value: "red"), .init(.absolutePosition, value: "top")), + (.init(.textAlign, value: "center"), .init(.color, value: "red")), + (.init(.justifyContent, value: "space-between"), .init(.alignItems, value: "end")) + ] + + static let comparisonResults: [Bool] = [ + true, // absolutePosition < accentColor + false, // backgroundColor > absolutePosition + false, // textAlign > color + false // justifyContent > alignItems + ] + + @Test("Comparable operator", arguments: await zip(stylePairs, comparisonResults)) + func comparable(_ pair: (lhs: InlineStyle, rhs: InlineStyle), lessThan: Bool) async throws { + #expect((pair.lhs < pair.rhs) == lessThan) + #expect((pair.lhs > pair.rhs) == !lessThan) } } diff --git a/Tests/IgniteTesting/Types/LengthUnit.swift b/Tests/IgniteTesting/Types/LengthUnit.swift index 36790e3c..bc022163 100644 --- a/Tests/IgniteTesting/Types/LengthUnit.swift +++ b/Tests/IgniteTesting/Types/LengthUnit.swift @@ -14,96 +14,61 @@ import Testing @Suite("LengthUnit Tests") @MainActor struct LengthUnitTests { - @Test("Test pixels length unit.", arguments: [ - 10, - 25, - 152 - ]) + @Test("Pixels length unit", arguments: [10, 25, 152]) func pixels(pixelAmount: Int) async throws { let element = LengthUnit.px(pixelAmount) - #expect(element.description == "\(pixelAmount)px") } - @Test("Test rem length unit.", arguments: [ - 10, - 25, - 152 - ]) + @Test("rem length unit", arguments: [10, 25, 152]) func rem(pixelAmount: Double) async throws { let element = LengthUnit.rem(pixelAmount) - #expect(element.description == "\(pixelAmount)rem") } - @Test("Test em length unit.", arguments: [ - 10, - 25, - 152 - ]) + @Test("em length unit", arguments: [10, 25, 152]) func em(pixelAmount: Double) async throws { let element = LengthUnit.em(pixelAmount) - #expect(element.description == "\(pixelAmount)em") } - @Test("Test percentage length unit.", arguments: [ - Percentage(10), - Percentage(25), - Percentage(-67) - ]) + @Test("Percentage length unit", arguments: [10%, 25%, -67%]) func percentage(percent: Percentage) async throws { let element = LengthUnit.percent(percent) - #expect(element.description == "\(percent.value)%") } - @Test("Test vw length unit.", arguments: [ - Percentage(10), - Percentage(25), - Percentage(67) - ]) + @Test("vw length unit", arguments: [10%, 25%, -67%]) func vw(percent: Percentage) async throws { let element = LengthUnit.vw(percent) - #expect(element.description == "\(percent.value)vw") } - @Test("Test vh length unit.", arguments: [ - Percentage(10), - Percentage(25), - Percentage(67) - ]) + @Test("vh length unit", arguments: [10%, 25%, -67%]) func vh(percent: Percentage) async throws { let element = LengthUnit.vh(percent) - #expect(element.description == "\(percent.value)vh") } - @Test("Test custom length unit.", arguments: [ - "60vw", - "300px", - "25%" - ]) + @Test("Custom length unit", arguments: ["60vw", "300px", "25%"]) func custom(unit: String) async throws { let element = LengthUnit.custom(unit) - #expect(element.description == unit) } - @Test("Test default value.") + @Test("Default value") func defaultValue() { let element = LengthUnit.default - + #expect(element == .em(.infinity)) #expect(element.description == "infem") } - @Test("Test is default value.", arguments: [ - (LengthUnit.em(20), false), - (LengthUnit.percent(Percentage(.infinity)), false), - (LengthUnit.em(.infinity), true) - ]) + @Test("Is default value", arguments: zip([ + LengthUnit.em(20), + LengthUnit.percent(Percentage(.infinity)), + LengthUnit.em(.infinity) + ], [false, false, true])) func isDefault(unit: LengthUnit, expected: Bool) { #expect(unit.isDefault == expected) } diff --git a/Tests/IgniteTesting/Types/Percentage.swift b/Tests/IgniteTesting/Types/Percentage.swift index 956d6942..9db51007 100644 --- a/Tests/IgniteTesting/Types/Percentage.swift +++ b/Tests/IgniteTesting/Types/Percentage.swift @@ -14,18 +14,13 @@ import Testing @Suite("Percentage Tests") @MainActor struct PercentageTests { - @Test("Test the value property.", arguments: [ - 25, - 74.3, - -126.225 - ]) + @Test("Value property", arguments: [25, 74.3, -126.225]) func value(value: Double) async throws { let element = Percentage(value) - #expect(element.value == value) } - @Test("Test the value function.", arguments: [ + @Test("Value function", arguments: [ (2, Percentage(25.12345678390987), 25.12), (5, Percentage(25.12345678390987), 25.12346), (10, Percentage(25.12345678390987), 25.1234567839) @@ -34,7 +29,7 @@ struct PercentageTests { #expect(percent.value(decimals: decimals) == expected) } - @Test("Test the rounded value.", arguments: [ + @Test("Rounded value", arguments: [ (Percentage(25.4), 25), (Percentage(25.499999), 25), (Percentage(25.5), 26) @@ -43,7 +38,7 @@ struct PercentageTests { #expect(percent.roundedValue == expected) } - @Test("Test subtracting percentages.", arguments: [ + @Test("Subtracting percentages", arguments: [ (Percentage(25.4), Percentage(22.4), 3.0), (Percentage(16.335), Percentage(49), -32.665), (Percentage(77), Percentage(-23), 100.0) @@ -52,7 +47,7 @@ struct PercentageTests { #expect(minuend - subtrahend == expected) } - @Test("Test adding percentages.", arguments: [ + @Test("Adding percentages", arguments: [ (Percentage(25.4), Percentage(22.4), 47.8), (Percentage(16.335), Percentage(49), 65.335), (Percentage(77), Percentage(-23), 54.0) @@ -61,7 +56,7 @@ struct PercentageTests { #expect(abs(firstAddend + secondAddend - expected) < 0.000001) } - @Test("Test multiplying percentages.", arguments: [ + @Test("Multiplying percentages", arguments: [ (2.0, Percentage(25.4), 0.508), (-3.0, Percentage(16.335), -0.49005), (10.0, Percentage(77), 7.70) @@ -71,25 +66,17 @@ struct PercentageTests { #expect(abs(percent * factor - expected) < 0.000001) } - @Test("Test % postfix operator on doubles.", arguments: [ - 25.4, - 83.49999, - 69.5 - ]) + @Test("% postfix operator on doubles", arguments: [25.4, 83.49999, 69.5]) func percentagePostfixDouble(value: Double) async throws { #expect(value% == Percentage(value)) } - @Test("Test % postfix operator on integers.", arguments: [ - 25, - 83, - 69 - ]) + @Test("% postfix operator on integers", arguments: [25, 83, 69]) func percentagePostfixInt(value: Int) async throws { #expect(value% == Percentage(value)) } - @Test("Test comparable operator.", arguments: [ + @Test("Comparable operator", arguments: [ (Percentage(20), Percentage(21), true), (Percentage(20), Percentage(19), false), (Percentage(20), Percentage(-19), false) @@ -99,7 +86,7 @@ struct PercentageTests { #expect((lhs > rhs) == !expected) } - @Test("Test equality operator.", arguments: [ + @Test("Equality operator", arguments: [ (Percentage(20), Percentage(21), false), (Percentage(20), Percentage(19), false), (Percentage(20), Percentage(-19), false), @@ -109,21 +96,13 @@ struct PercentageTests { #expect((lhs == rhs) == expected) } - @Test("Test BinaryFloatingPoint extension.", arguments: [ - 20.88, - -33.12, - 125.54321 - ]) + @Test("BinaryFloatingPoint extension", arguments: [20.88, -33.12, 125.54321]) func asString(value: Double) async throws { let element = Percentage(value) #expect(element.value.asString() == "\(value)%") } - @Test("Test BinaryInteger extension.", arguments: [ - 20, - -33, - 125 - ]) + @Test("BinaryInteger extension", arguments: [20, -33, 125]) func asString(value: Int) async throws { let element = Percentage(value) #expect(element.roundedValue.asString() == "\(value)%") diff --git a/Tests/IgniteTesting/Types/UnitPoint.swift b/Tests/IgniteTesting/Types/UnitPoint.swift index f2b27ed4..48226f78 100644 --- a/Tests/IgniteTesting/Types/UnitPoint.swift +++ b/Tests/IgniteTesting/Types/UnitPoint.swift @@ -14,104 +14,71 @@ import Testing @Suite("UnitPoint Tests") @MainActor struct UnitPointTests { - struct UnitPointTestParams: Sendable { - let start: UnitPoint - let end: UnitPoint - let expected: Double + static let unitPoints: [UnitPoint] = [ + .topLeading, .top, .topTrailing, + .leading, .center, .trailing, + .bottomLeading, .bottom, .bottomTrailing + ] + + static let alignmentValues: [(justifySelf: String, alignSelf: String)] = [ + ("start", "start"), // topLeading + ("center", "start"), // top + ("end", "start"), // topTrailing + ("start", "center"), // leading + ("center", "center"), // center + ("end", "center"), // trailing + ("start", "end"), // bottomLeading + ("center", "end"), // bottom + ("end", "end") // bottomTrailing + ] + + @Test("UnitPoint alignment", arguments: await zip(unitPoints, alignmentValues)) + func testUnitPointAlignment(_ point: UnitPoint, expected: (justifySelf: String, alignSelf: String)) async throws { + #expect(point.justifySelf == expected.justifySelf && point.alignSelf == expected.alignSelf) } - @Test("Test the top leading unit point.") - func topLeadingUnitPoint() async throws { - let element = UnitPoint.topLeading - - #expect(element.justifySelf == "start" && element.alignSelf == "start") - } - - @Test("Test the top unit point.") - func topUnitPoint() async throws { - let element = UnitPoint.top - - #expect(element.justifySelf == "center" && element.alignSelf == "start") + static let pointPairs: [(start: UnitPoint, end: UnitPoint)] = [ + (.topLeading, .bottomTrailing), + (.top, .bottom), + (.topTrailing, .bottomLeading), + (.topTrailing, .topLeading), + (.bottomLeading, .topTrailing), + (.center, .topLeading), + (.leading, .trailing), + (.bottom, .top) + ] + + static let degreeValues: [Double] = [ + 135, // topLeading to bottomTrailing + 180, // top to bottom + 225, // topTrailing to bottomLeading + 270, // topTrailing to topLeading + 45, // bottomLeading to topTrailing + 315, // center to topLeading + 90, // leading to trailing + 0 // bottom to top + ] + + static let radianValues: [Double] = [ + 2.356194490192345, // topLeading to bottomTrailing + 3.141592653589793, // top to bottom + 3.9269908169872414, // topTrailing to bottomLeading + 4.71238898038469, // topTrailing to topLeading + 0.7853981633974483, // bottomLeading to topTrailing + 5.497787143782138, // center to topLeading + 1.5707963267948966, // leading to trailing + 0 // bottom to top + ] + + @Test("Degrees calculation", arguments: await zip(pointPairs, degreeValues)) + func degrees(_ points: (start: UnitPoint, end: UnitPoint), expected: Double) async throws { + let element = points.start.degrees(to: points.end) + #expect(element == expected) } - @Test("Test the top trailing unit point.") - func topTrailingUnitPoint() async throws { - let element = UnitPoint.topTrailing - - #expect(element.justifySelf == "end" && element.alignSelf == "start") - } - - @Test("Test the leading unit point.") - func leadingUnitPoint() async throws { - let element = UnitPoint.leading - - #expect(element.justifySelf == "start" && element.alignSelf == "center") - } - - @Test("Test the center unit point.") - func centerUnitPoint() async throws { - let element = UnitPoint.center - - #expect(element.justifySelf == "center" && element.alignSelf == "center") - } - - @Test("Test the trailing unit point.") - func trailingUnitPoint() async throws { - let element = UnitPoint.trailing - - #expect(element.justifySelf == "end" && element.alignSelf == "center") - } - - @Test("Test the bottom leading unit point.") - func bottomLeadingUnitPoint() async throws { - let element = UnitPoint.bottomLeading - - #expect(element.justifySelf == "start" && element.alignSelf == "end") - } - - @Test("Test the bottom unit point.") - func bottomUnitPoint() async throws { - let element = UnitPoint.bottom - - #expect(element.justifySelf == "center" && element.alignSelf == "end") - } - - @Test("Test the bottom trailing unit point.") - func bottomTrailingUnitPoint() async throws { - let element = UnitPoint.bottomTrailing - - #expect(element.justifySelf == "end" && element.alignSelf == "end") - } - - @Test("Test the degrees calculation.", arguments: [ - UnitPointTestParams(start: UnitPoint.topLeading, end: UnitPoint.bottomTrailing, expected: 135), - UnitPointTestParams(start: UnitPoint.top, end: UnitPoint.bottom, expected: 180), - UnitPointTestParams(start: UnitPoint.topTrailing, end: UnitPoint.bottomLeading, expected: 225), - UnitPointTestParams(start: UnitPoint.topTrailing, end: UnitPoint.topLeading, expected: 270), - UnitPointTestParams(start: UnitPoint.bottomLeading, end: UnitPoint.topTrailing, expected: 45), - UnitPointTestParams(start: UnitPoint.center, end: UnitPoint.topLeading, expected: 315), - UnitPointTestParams(start: UnitPoint.leading, end: UnitPoint.trailing, expected: 90), - UnitPointTestParams(start: UnitPoint.bottom, end: UnitPoint.top, expected: 0) - ]) - func degrees(params: UnitPointTestParams) async throws { - let element = params.start.degrees(to: params.end) - - #expect(element == params.expected) - } - - @Test("Test the radians calculation.", arguments: [ - UnitPointTestParams(start: UnitPoint.topLeading, end: UnitPoint.bottomTrailing, expected: 2.356194490192345), - UnitPointTestParams(start: UnitPoint.top, end: UnitPoint.bottom, expected: 3.141592653589793), - UnitPointTestParams(start: UnitPoint.topTrailing, end: UnitPoint.bottomLeading, expected: 3.9269908169872414), - UnitPointTestParams(start: UnitPoint.topTrailing, end: UnitPoint.topLeading, expected: 4.71238898038469), - UnitPointTestParams(start: UnitPoint.bottomLeading, end: UnitPoint.topTrailing, expected: 0.7853981633974483), - UnitPointTestParams(start: UnitPoint.center, end: UnitPoint.topLeading, expected: 5.497787143782138), - UnitPointTestParams(start: UnitPoint.leading, end: UnitPoint.trailing, expected: 1.5707963267948966), - UnitPointTestParams(start: UnitPoint.bottom, end: UnitPoint.top, expected: 0) - ]) - func radians(params: UnitPointTestParams) async throws { - let element = params.start.radians(to: params.end) - - #expect(element == params.expected) + @Test("Radians calculation", arguments: await zip(pointPairs, radianValues)) + func radians(_ points: (start: UnitPoint, end: UnitPoint), expected: Double) async throws { + let element = points.start.radians(to: points.end) + #expect(element == expected) } }