From 4a8eda982c099ef27a6671eb4a6da40aaa19a687 Mon Sep 17 00:00:00 2001 From: David Mohundro Date: Thu, 15 Aug 2024 19:25:03 -0500 Subject: [PATCH] fix: swiftlint fixes --- .swiftlint.yml | 1 - Package.swift | 2 +- .../LazyTypesConversionTests.swift | 12 ++- .../LazyWhiteSpaceParsingTests.swift | 19 ++-- .../SWXMLHashTests/LazyXMLParsingTests.swift | 45 ++++++--- .../MixedTextWithXMLElementsTests.swift | 3 +- ...versionArrayOfNonPrimitiveTypesTests.swift | 39 +++++--- .../TypeConversionBasicTypesTests.swift | 49 ++++++---- .../TypeConversionComplexTypesTests.swift | 18 ++-- .../TypeConversionPrimitiveTypesTests.swift | 60 +++++++----- .../WhiteSpaceParsingTests.swift | 6 +- Tests/SWXMLHashTests/XMLHashConfigTests.swift | 3 +- Tests/SWXMLHashTests/XMLParsingTests.swift | 92 +++++++++++++------ .../XMLParsingValidationTests.swift | 6 +- 14 files changed, 232 insertions(+), 123 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index ac387b2d..ab6d5540 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -3,7 +3,6 @@ included: - Tests - ./Package.swift opt_in_rules: - - anyobject_protocol - array_init - attributes - closure_end_indentation diff --git a/Package.swift b/Package.swift index 627b3cdd..0ddfd99a 100644 --- a/Package.swift +++ b/Package.swift @@ -36,7 +36,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/apple/swift-testing.git", from: "0.10.0"), + .package(url: "https://github.com/apple/swift-testing.git", from: "0.10.0") ], targets: [ .target( diff --git a/Tests/SWXMLHashTests/LazyTypesConversionTests.swift b/Tests/SWXMLHashTests/LazyTypesConversionTests.swift index ae9ae520..80b96244 100644 --- a/Tests/SWXMLHashTests/LazyTypesConversionTests.swift +++ b/Tests/SWXMLHashTests/LazyTypesConversionTests.swift @@ -26,7 +26,8 @@ import SWXMLHash import Testing -@Suite("LazyTypesConversionTests") struct LazyTypesConversionTests { +@Suite("LazyTypesConversionTests") +struct LazyTypesConversionTests { var parser: XMLIndexer? let xmlWithBasicTypes = """ @@ -49,7 +50,8 @@ import Testing parser = XMLHash.config { cfg in cfg.shouldProcessLazily = true }.parse(xmlWithBasicTypes) } - @Test func shouldConvertValueToNonOptional() { + @Test + func shouldConvertValueToNonOptional() { do { let value: String = try parser!["root"]["string"].value() #expect(value == "the string value") @@ -58,7 +60,8 @@ import Testing } } - @Test func shouldConvertAttributeToNonOptional() { + @Test + func shouldConvertAttributeToNonOptional() { do { let value: Int = try parser!["root"]["attribute"].value(ofAttribute: "int") #expect(value == 1) @@ -67,7 +70,8 @@ import Testing } } - @Test func shouldBeAbleToGetUserInfoDuringDeserialization() { + @Test + func shouldBeAbleToGetUserInfoDuringDeserialization() { let parser = XMLHash.config { config in let options = SampleUserInfo(apiVersion: .v1) config.userInfo = [ SampleUserInfo.key: options ] diff --git a/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift b/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift index 42a88495..f684d87f 100644 --- a/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift +++ b/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift @@ -35,23 +35,28 @@ struct LazyWhiteSpaceParsingTests { init() { // Put setup code here. This method is called before the invocation of each test method in the class. -#if SWIFT_PACKAGE +// #if SWIFT_PACKAGE +// let path = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("test.xml").path +// #else +// let bundle = Bundle(for: WhiteSpaceParsingTests.self) +// let path = bundle.path(forResource: "test", ofType: "xml")! +// #endif + let path = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("test.xml").path -#else - let bundle = Bundle(for: WhiteSpaceParsingTests.self) - let path = bundle.path(forResource: "test", ofType: "xml")! -#endif + // swiftlint:disable:next force_try let data = try! Data(contentsOf: URL(fileURLWithPath: path)) xml = XMLHash.lazy(data) } // issue #6 - @Test func shouldBeAbleToPullTextBetweenElementsWithoutWhitespace() { + @Test + func shouldBeAbleToPullTextBetweenElementsWithoutWhitespace() { #expect(xml!["niotemplate"]["section"][0]["constraint"][1].element?.text == "H:|-15-[title]-15-|") } - @Test func shouldBeAbleToCorrectlyParseCDATASectionsWithWhitespace() { + @Test + func shouldBeAbleToCorrectlyParseCDATASectionsWithWhitespace() { #expect(xml!["niotemplate"]["other"].element?.text == "\n \n this\n has\n white\n space\n \n ") } } diff --git a/Tests/SWXMLHashTests/LazyXMLParsingTests.swift b/Tests/SWXMLHashTests/LazyXMLParsingTests.swift index cbf04443..a4fd1a6b 100644 --- a/Tests/SWXMLHashTests/LazyXMLParsingTests.swift +++ b/Tests/SWXMLHashTests/LazyXMLParsingTests.swift @@ -66,24 +66,29 @@ struct LazyXMLParsingTests { xml = XMLHash.config { config in config.shouldProcessLazily = true }.parse(xmlToParse) } - @Test func shouldBeAbleToParseIndividualElements() { + @Test + func shouldBeAbleToParseIndividualElements() { #expect(xml!["root"]["header"]["title"].element?.text == "Test Title Header") } - @Test func shouldBeAbleToHandleSubsequentParseCalls() { + @Test + func shouldBeAbleToHandleSubsequentParseCalls() { #expect(xml!["root"]["header"]["title"].element?.text == "Test Title Header") #expect(xml!["root"]["catalog"]["book"][1]["author"].element?.text == "Ralls, Kim") } - @Test func shouldBeAbleToParseElementGroups() { + @Test + func shouldBeAbleToParseElementGroups() { #expect(xml!["root"]["catalog"]["book"][1]["author"].element?.text == "Ralls, Kim") } - @Test func shouldBeAbleToParseAttributes() { + @Test + func shouldBeAbleToParseAttributes() { #expect(xml!["root"]["catalog"]["book"][1].element?.attribute(by: "id")?.text == "bk102") } - @Test func shouldBeAbleToLookUpElementsByNameAndAttribute() { + @Test + func shouldBeAbleToLookUpElementsByNameAndAttribute() { do { let value = try xml!["root"]["catalog"]["book"].withAttribute("id", "bk102")["author"].element?.text #expect(value == "Ralls, Kim") @@ -92,20 +97,24 @@ struct LazyXMLParsingTests { } } - @Test func shouldBeAbleToIterateElementGroups() { + @Test + func shouldBeAbleToIterateElementGroups() { let result = xml!["root"]["catalog"]["book"].all.map({ $0["genre"].element!.text }).joined(separator: ", ") #expect(result == "Computer, Fantasy, Fantasy") } - @Test func shouldBeAbleToIterateElementGroupsEvenIfOnlyOneElementIsFound() { + @Test + func shouldBeAbleToIterateElementGroupsEvenIfOnlyOneElementIsFound() { #expect(xml!["root"]["header"]["title"].all.count == 1) } - @Test func shouldBeAbleToIndexElementGroupsEvenIfOnlyOneElementIsFound() { + @Test + func shouldBeAbleToIndexElementGroupsEvenIfOnlyOneElementIsFound() { #expect(xml!["root"]["header"]["title"][0].element?.text == "Test Title Header") } - @Test func shouldBeAbleToIterateUsingForIn() { + @Test + func shouldBeAbleToIterateUsingForIn() { var count = 0 for _ in xml!["root"]["catalog"]["book"].all { count += 1 @@ -114,16 +123,19 @@ struct LazyXMLParsingTests { #expect(count == 3) } - @Test func shouldBeAbleToEnumerateChildren() { + @Test + func shouldBeAbleToEnumerateChildren() { let result = xml!["root"]["catalog"]["book"][0].children.map({ $0.element!.name }).joined(separator: ", ") #expect(result == "author, title, genre, price, publish_date, description") } - @Test func shouldBeAbleToHandleMixedContent() { + @Test + func shouldBeAbleToHandleMixedContent() { #expect(xml!["root"]["header"].element?.text == "header mixed contentmore mixed content") } - @Test func shouldHandleInterleavingXMLElements() { + @Test + func shouldHandleInterleavingXMLElements() { let interleavedXml = "

one

two

three

four
" let parsed = XMLHash.parse(interleavedXml) @@ -131,18 +143,21 @@ struct LazyXMLParsingTests { #expect(result == "one, two, three, four") } - @Test func shouldBeAbleToProvideADescriptionForTheDocument() { + @Test + func shouldBeAbleToProvideADescriptionForTheDocument() { let descriptionXml = "puppies" let parsed = XMLHash.parse(descriptionXml) #expect(parsed.description == "puppies") } - @Test func shouldReturnNilWhenKeysDontMatch() { + @Test + func shouldReturnNilWhenKeysDontMatch() { #expect(xml!["root"]["what"]["header"]["foo"].element?.name == nil) } - @Test func shouldBeAbleToFilterOnIndexer() { + @Test + func shouldBeAbleToFilterOnIndexer() { let subIndexer = xml!["root"]["catalog"]["book"] .filterAll { elem, _ in elem.attribute(by: "id")!.text == "bk102" } .filterChildren { _, index in index >= 1 && index <= 3 } diff --git a/Tests/SWXMLHashTests/MixedTextWithXMLElementsTests.swift b/Tests/SWXMLHashTests/MixedTextWithXMLElementsTests.swift index b947645a..d1d465d7 100644 --- a/Tests/SWXMLHashTests/MixedTextWithXMLElementsTests.swift +++ b/Tests/SWXMLHashTests/MixedTextWithXMLElementsTests.swift @@ -36,7 +36,8 @@ struct MixedTextWithXMLElementsTests { xml = XMLHash.parse(xmlContent) } - @Test func shouldBeAbleToGetAllContentsInsideOfAnElement() { + @Test + func shouldBeAbleToGetAllContentsInsideOfAnElement() { #expect(xml!["everything"]["news"]["content"].description == "Here is a cool thing A and second cool thing B") } } diff --git a/Tests/SWXMLHashTests/TypeConversionArrayOfNonPrimitiveTypesTests.swift b/Tests/SWXMLHashTests/TypeConversionArrayOfNonPrimitiveTypesTests.swift index 43f1a11d..a59744f1 100644 --- a/Tests/SWXMLHashTests/TypeConversionArrayOfNonPrimitiveTypesTests.swift +++ b/Tests/SWXMLHashTests/TypeConversionArrayOfNonPrimitiveTypesTests.swift @@ -90,7 +90,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { parser = XMLHash.parse(xmlWithArraysOfTypes) } - @Test func shouldConvertArrayOfGoodBasicItemsToNonOptional() { + @Test + func shouldConvertArrayOfGoodBasicItemsToNonOptional() { do { let value: [BasicItem] = try parser!["root"]["arrayOfGoodBasicItems"]["basicItem"].value() #expect(value == correctBasicItems) @@ -99,7 +100,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodBasicItemsToOptional() { + @Test + func shouldConvertArrayOfGoodBasicItemsToOptional() { do { let value: [BasicItem]? = try parser!["root"]["arrayOfGoodBasicItems"]["basicItem"].value() #expect(value != nil) @@ -111,7 +113,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodBasicItemsToArrayOfOptionals() { + @Test + func shouldConvertArrayOfGoodBasicItemsToArrayOfOptionals() { do { let value: [BasicItem?] = try parser!["root"]["arrayOfGoodBasicItems"]["basicItem"].value() #expect(value.compactMap({ $0 }) == correctBasicItems) @@ -120,25 +123,29 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldThrowWhenConvertingArrayOfBadBasicItemsToNonOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadBasicItemsToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadBasicItems"]["basicItem"].value() as [BasicItem]) } } - @Test func shouldThrowWhenConvertingArrayOfBadBasicItemsToOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadBasicItemsToOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadBasicItems"]["basicItem"].value() as [BasicItem]?) } } - @Test func shouldThrowWhenConvertingArrayOfBadBasicItemsToArrayOfOptionals() { + @Test + func shouldThrowWhenConvertingArrayOfBadBasicItemsToArrayOfOptionals() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadBasicItems"]["basicItem"].value() as [BasicItem?]) } } - @Test func shouldConvertArrayOfEmptyMissingToOptional() { + @Test + func shouldConvertArrayOfEmptyMissingToOptional() { do { let value: [BasicItem]? = try parser!["root"]["arrayOfMissingBasicItems"]["basicItem"].value() #expect(value == nil) @@ -147,7 +154,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodAttributeItemsToNonOptional() { + @Test + func shouldConvertArrayOfGoodAttributeItemsToNonOptional() { do { let value: [AttributeItem] = try parser!["root"]["arrayOfGoodAttributeItems"]["attributeItem"].value() #expect(value == correctAttributeItems) @@ -156,7 +164,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodAttributeItemsToOptional() { + @Test + func shouldConvertArrayOfGoodAttributeItemsToOptional() { do { let value: [AttributeItem]? = try parser!["root"]["arrayOfGoodAttributeItems"]["attributeItem"].value() #expect(value != nil) @@ -168,7 +177,8 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodAttributeItemsToArrayOfOptionals() { + @Test + func shouldConvertArrayOfGoodAttributeItemsToArrayOfOptionals() { do { let value: [AttributeItem?] = try parser!["root"]["arrayOfGoodAttributeItems"]["attributeItem"].value() #expect(value.compactMap({ $0 }) == correctAttributeItems) @@ -177,19 +187,22 @@ struct TypeConversionArrayOfNonPrimitiveTypesTests { } } - @Test func shouldThrowWhenConvertingArrayOfBadAttributeItemsToNonOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadAttributeItemsToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadAttributeItems"]["attributeItem"].value() as [AttributeItem]) } } - @Test func shouldThrowWhenConvertingArrayOfBadAttributeItemsToOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadAttributeItemsToOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadAttributeItems"]["attributeItem"].value() as [AttributeItem]?) } } - @Test func shouldThrowWhenConvertingArrayOfBadAttributeItemsToArrayOfOptionals() { + @Test + func shouldThrowWhenConvertingArrayOfBadAttributeItemsToArrayOfOptionals() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadAttributeItems"]["attributeItem"].value() as [AttributeItem?]) } diff --git a/Tests/SWXMLHashTests/TypeConversionBasicTypesTests.swift b/Tests/SWXMLHashTests/TypeConversionBasicTypesTests.swift index d87e1121..4d64b8ca 100644 --- a/Tests/SWXMLHashTests/TypeConversionBasicTypesTests.swift +++ b/Tests/SWXMLHashTests/TypeConversionBasicTypesTests.swift @@ -78,7 +78,8 @@ struct TypeConversionBasicTypesTests { parser = XMLHash.parse(xmlWithBasicTypes) } - @Test func shouldConvertValueToNonOptional() { + @Test + func shouldConvertValueToNonOptional() { do { let value: String = try parser!["root"]["string"].value() #expect(value == "the string value") @@ -87,22 +88,25 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertEmptyToNonOptional() { + @Test + func shouldConvertEmptyToNonOptional() { do { let value: String = try parser!["root"]["empty"].value() - #expect(value == "") + #expect(value.isEmpty) } catch { Issue.record("\(error)") } } - @Test func shouldThrowWhenConvertingMissingToNonOptional() { + @Test + func shouldThrowWhenConvertingMissingToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["missing"].value() as String) } } - @Test func shouldConvertValueToOptional() { + @Test + func shouldConvertValueToOptional() { do { let value: String? = try parser!["root"]["string"].value() #expect(value == "the string value") @@ -111,16 +115,18 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertEmptyToOptional() { + @Test + func shouldConvertEmptyToOptional() { do { let value: String? = try parser!["root"]["empty"].value() - #expect(value == "") + #expect(value?.isEmpty == true) } catch { Issue.record("\(error)") } } - @Test func shouldConvertMissingToOptional() { + @Test + func shouldConvertMissingToOptional() { do { let value: String? = try parser!["root"]["missing"].value() #expect(value == nil) @@ -129,7 +135,8 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertAttributeToNonOptional() { + @Test + func shouldConvertAttributeToNonOptional() { do { let value: String = try parser!["root"]["attr"].value(ofAttribute: "string") #expect(value == "stringValue") @@ -138,23 +145,27 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertAttributeToOptional() { + @Test + func shouldConvertAttributeToOptional() { let value: String? = parser!["root"]["attr"].value(ofAttribute: "string") #expect(value == "stringValue") } - @Test func shouldThrowWhenConvertingMissingAttributeToNonOptional() { + @Test + func shouldThrowWhenConvertingMissingAttributeToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["attr"].value(ofAttribute: "missing") as String) } } - @Test func shouldConvertMissingAttributeToOptional() { + @Test + func shouldConvertMissingAttributeToOptional() { let value: String? = parser!["root"]["attr"].value(ofAttribute: "missing") #expect(value == nil) } - @Test func shouldConvertAttributeToNonOptionalWithStringRawRepresentable() { + @Test + func shouldConvertAttributeToNonOptionalWithStringRawRepresentable() { enum Keys: String { case string } @@ -166,7 +177,8 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertAttributeToOptionalWithStringRawRepresentable() { + @Test + func shouldConvertAttributeToOptionalWithStringRawRepresentable() { enum Keys: String { case string } @@ -174,7 +186,8 @@ struct TypeConversionBasicTypesTests { #expect(value == "stringValue") } - @Test func shouldThrowWhenConvertingMissingAttributeToNonOptionalWithStringRawRepresentable() { + @Test + func shouldThrowWhenConvertingMissingAttributeToNonOptionalWithStringRawRepresentable() { enum Keys: String { case missing } @@ -183,7 +196,8 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldConvertMissingAttributeToOptionalWithStringRawRepresentable() { + @Test + func shouldConvertMissingAttributeToOptionalWithStringRawRepresentable() { enum Keys: String { case missing } @@ -535,7 +549,8 @@ struct TypeConversionBasicTypesTests { } } - @Test func shouldBeAbleToGetUserInfoDuringDeserialization() { + @Test + func shouldBeAbleToGetUserInfoDuringDeserialization() { let parser = XMLHash.config { config in let options = SampleUserInfo(apiVersion: .v1) config.userInfo = [ SampleUserInfo.key: options ] diff --git a/Tests/SWXMLHashTests/TypeConversionComplexTypesTests.swift b/Tests/SWXMLHashTests/TypeConversionComplexTypesTests.swift index 8e3e9a7d..97d9195e 100644 --- a/Tests/SWXMLHashTests/TypeConversionComplexTypesTests.swift +++ b/Tests/SWXMLHashTests/TypeConversionComplexTypesTests.swift @@ -76,7 +76,8 @@ struct TypeConversionComplexTypesTests { parser = XMLHash.parse(xmlWithComplexType) } - @Test func shouldConvertComplexItemToNonOptional() { + @Test + func shouldConvertComplexItemToNonOptional() { do { let value: ComplexItem = try parser!["root"]["complexItem"].value() #expect(value == correctComplexItem) @@ -85,19 +86,22 @@ struct TypeConversionComplexTypesTests { } } - @Test func shouldThrowWhenConvertingEmptyToNonOptional() { + @Test + func shouldThrowWhenConvertingEmptyToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["empty"].value() as ComplexItem) } } - @Test func shouldThrowWhenConvertingMissingToNonOptional() { + @Test + func shouldThrowWhenConvertingMissingToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["missing"].value() as ComplexItem) } } - @Test func shouldConvertComplexItemToOptional() { + @Test + func shouldConvertComplexItemToOptional() { do { let value: ComplexItem? = try parser!["root"]["complexItem"].value() #expect(value == correctComplexItem) @@ -106,13 +110,15 @@ struct TypeConversionComplexTypesTests { } } - @Test func shouldConvertEmptyToOptional() { + @Test + func shouldConvertEmptyToOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["empty"].value() as ComplexItem?) } } - @Test func shouldConvertMissingToOptional() { + @Test + func shouldConvertMissingToOptional() { do { let value: ComplexItem? = try parser!["root"]["missing"].value() #expect(value == nil) diff --git a/Tests/SWXMLHashTests/TypeConversionPrimitiveTypesTests.swift b/Tests/SWXMLHashTests/TypeConversionPrimitiveTypesTests.swift index 6657df5b..48427a73 100644 --- a/Tests/SWXMLHashTests/TypeConversionPrimitiveTypesTests.swift +++ b/Tests/SWXMLHashTests/TypeConversionPrimitiveTypesTests.swift @@ -26,8 +26,6 @@ import SWXMLHash import Testing -// swiftlint:disable line_length - struct TypeConversionPrimitiveTypesTests { var parser: XMLIndexer? let xmlWithArraysOfTypes = """ @@ -52,7 +50,8 @@ struct TypeConversionPrimitiveTypesTests { parser = XMLHash.parse(xmlWithArraysOfTypes) } - @Test func shouldConvertArrayOfGoodIntsToNonOptional() { + @Test + func shouldConvertArrayOfGoodIntsToNonOptional() { do { let value: [Int] = try parser!["root"]["arrayOfGoodInts"]["int"].value() #expect(value == [0, 1, 2, 3]) @@ -61,7 +60,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodIntsToOptional() { + @Test + func shouldConvertArrayOfGoodIntsToOptional() { do { let value: [Int]? = try parser!["root"]["arrayOfGoodInts"]["int"].value() #expect(value != nil) @@ -73,7 +73,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfGoodIntsToArrayOfOptionals() { + @Test + func shouldConvertArrayOfGoodIntsToArrayOfOptionals() { do { let value: [Int?] = try parser!["root"]["arrayOfGoodInts"]["int"].value() #expect(value.compactMap({ $0 }) == [0, 1, 2, 3]) @@ -82,43 +83,50 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldThrowWhenConvertingArrayOfBadIntsToNonOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadIntsToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadInts"]["int"].value() as [Int]) } } - @Test func shouldThrowWhenConvertingArrayOfBadIntsToOptional() { + @Test + func shouldThrowWhenConvertingArrayOfBadIntsToOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadInts"]["int"].value() as [Int]?) } } - @Test func shouldThrowWhenConvertingArrayOfBadIntsToArrayOfOptionals() { + @Test + func shouldThrowWhenConvertingArrayOfBadIntsToArrayOfOptionals() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfBadInts"]["int"].value() as [Int?]) } } - @Test func shouldThrowWhenConvertingArrayOfMixedIntsToNonOptional() { + @Test + func shouldThrowWhenConvertingArrayOfMixedIntsToNonOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfMixedInts"]["int"].value() as [Int]) } } - @Test func shouldThrowWhenConvertingArrayOfMixedIntsToOptional() { + @Test + func shouldThrowWhenConvertingArrayOfMixedIntsToOptional() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfMixedInts"]["int"].value() as [Int]?) } } - @Test func shouldThrowWhenConvertingArrayOfMixedIntsToArrayOfOptionals() { + @Test + func shouldThrowWhenConvertingArrayOfMixedIntsToArrayOfOptionals() { #expect(throws: XMLDeserializationError.self) { try (parser!["root"]["arrayOfMixedInts"]["int"].value() as [Int?]) } } - @Test func shouldConvertArrayOfAttributeIntsToNonOptional() { + @Test + func shouldConvertArrayOfAttributeIntsToNonOptional() { do { let value: [Int] = try parser!["root"]["arrayOfAttributeInts"]["int"].value(ofAttribute: "value") #expect(value == [0, 1, 2, 3]) @@ -127,7 +135,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfAttributeIntsToOptional() { + @Test + func shouldConvertArrayOfAttributeIntsToOptional() { do { let value: [Int]? = try parser!["root"]["arrayOfAttributeInts"]["int"].value(ofAttribute: "value") #expect(value != nil) @@ -139,7 +148,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfAttributeIntsToArrayOfOptionals() { + @Test + func shouldConvertArrayOfAttributeIntsToArrayOfOptionals() { do { let value: [Int?] = try parser!["root"]["arrayOfAttributeInts"]["int"].value(ofAttribute: "value") #expect(value.compactMap({ $0 }) == [0, 1, 2, 3]) @@ -148,7 +158,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfAttributeIntsToNonOptionalWithStringRawRepresentable() { + @Test + func shouldConvertArrayOfAttributeIntsToNonOptionalWithStringRawRepresentable() { enum Keys: String { case value } @@ -160,7 +171,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfAttributeIntsToOptionalWithStringRawRepresentable() { + @Test + func shouldConvertArrayOfAttributeIntsToOptionalWithStringRawRepresentable() { enum Keys: String { case value } @@ -175,7 +187,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertArrayOfAttributeIntsToArrayOfOptionalsWithStringRawRepresentable() { + @Test + func shouldConvertArrayOfAttributeIntsToArrayOfOptionalsWithStringRawRepresentable() { enum Keys: String { case value } @@ -187,7 +200,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertEmptyArrayOfIntsToNonOptional() { + @Test + func shouldConvertEmptyArrayOfIntsToNonOptional() { do { let value: [Int] = try parser!["root"]["empty"]["int"].value() #expect(value == []) @@ -196,7 +210,8 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertEmptyArrayOfIntsToOptional() { + @Test + func shouldConvertEmptyArrayOfIntsToOptional() { do { let value: [Int]? = try parser!["root"]["empty"]["int"].value() #expect(value == nil) @@ -205,14 +220,13 @@ struct TypeConversionPrimitiveTypesTests { } } - @Test func shouldConvertEmptyArrayOfIntsToArrayOfOptionals() { + @Test + func shouldConvertEmptyArrayOfIntsToArrayOfOptionals() { do { let value: [Int?] = try parser!["root"]["empty"]["int"].value() - #expect(value.count == 0) + #expect(value.isEmpty) } catch { Issue.record("\(error)") } } } - -// swiftlint:enable line_length diff --git a/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift b/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift index 9c51eea8..0a9f3bb9 100644 --- a/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift +++ b/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift @@ -46,11 +46,13 @@ struct WhiteSpaceParsingTests { } // issue #6 - @Test func shouldBeAbleToPullTextBetweenElementsWithoutWhitespace() { + @Test + func shouldBeAbleToPullTextBetweenElementsWithoutWhitespace() { #expect(xml!["niotemplate"]["section"][0]["constraint"][1].element?.text == "H:|-15-[title]-15-|") } - @Test func shouldBeAbleToCorrectlyParseCDATASectionsWithWhitespace() { + @Test + func shouldBeAbleToCorrectlyParseCDATASectionsWithWhitespace() { #expect(xml!["niotemplate"]["other"].element?.text == "\n \n this\n has\n white\n space\n \n ") } } diff --git a/Tests/SWXMLHashTests/XMLHashConfigTests.swift b/Tests/SWXMLHashTests/XMLHashConfigTests.swift index 7ffd7f79..01a097d7 100644 --- a/Tests/SWXMLHashTests/XMLHashConfigTests.swift +++ b/Tests/SWXMLHashTests/XMLHashConfigTests.swift @@ -46,7 +46,8 @@ struct XMLHashConfigTests { }.parse(xmlWithNamespace) } - @Test func shouldAllowProcessingNamespacesOrNot() { + @Test + func shouldAllowProcessingNamespacesOrNot() { #expect(parser!["root"]["table"]["tr"]["td"][0].element?.text == "Apples") } } diff --git a/Tests/SWXMLHashTests/XMLParsingTests.swift b/Tests/SWXMLHashTests/XMLParsingTests.swift index 0f65c693..d55e1edc 100644 --- a/Tests/SWXMLHashTests/XMLParsingTests.swift +++ b/Tests/SWXMLHashTests/XMLParsingTests.swift @@ -70,41 +70,51 @@ struct XMLParsingTests { xml = XMLHash.parse(xmlToParse) } - @Test func shouldBeAbleToParseIndividualElements() { + @Test + func shouldBeAbleToParseIndividualElements() { #expect(xml!["root"]["header"]["title"].element?.text == "Test Title Header") } - @Test func shouldBeAbleToParseIndividualElementsWithStringRawRepresentable() { + @Test + func shouldBeAbleToParseIndividualElementsWithStringRawRepresentable() { enum Keys: String { case root; case header; case title } #expect(xml![Keys.root][Keys.header][Keys.title].element?.text == "Test Title Header") } - @Test func shouldBeAbleToParseElementGroups() { + @Test + func shouldBeAbleToParseElementGroups() { #expect(xml!["root"]["catalog"]["book"][1]["author"].element?.text == "Ralls, Kim") } - @Test func shouldBeAbleToParseElementGroupsByIndex() { + @Test + func shouldBeAbleToParseElementGroupsByIndex() { + // swiftlint:disable:next force_try #expect(try! xml!["root"]["catalog"]["book"].byIndex(1)["author"].element?.text == "Ralls, Kim") } - @Test func shouldBeAbleToByIndexWithoutGoingOutOfBounds() { + @Test + func shouldBeAbleToByIndexWithoutGoingOutOfBounds() { + // swiftlint:disable:next force_try #expect(try! xml!["root"]["catalog"]["book"].byIndex(3)["author"].element?.text == nil) } - @Test func shouldBeAbleToParseAttributes() { + @Test + func shouldBeAbleToParseAttributes() { #expect(xml!["root"]["catalog"]["book"][1].element?.attribute(by: "id")?.text == "bk102") } - @Test func shouldBeAbleToParseAttributesWithStringRawRepresentable() { + @Test + func shouldBeAbleToParseAttributesWithStringRawRepresentable() { enum Keys: String { case root; case catalog; case book; case id } #expect(xml![Keys.root][Keys.catalog][Keys.book][1].element?.attribute(by: Keys.id)?.text == "bk102") } - @Test func shouldBeAbleToLookUpElementsByNameAndAttribute() { + @Test + func shouldBeAbleToLookUpElementsByNameAndAttribute() { do { let value = try xml!["root"]["catalog"]["book"].withAttribute("id", "bk102")["author"].element?.text #expect(value == "Ralls, Kim") @@ -113,7 +123,8 @@ struct XMLParsingTests { } } - @Test func shouldBeAbleToLookUpElementsByNameAndAttributeWithStringRawRepresentable() { + @Test + func shouldBeAbleToLookUpElementsByNameAndAttributeWithStringRawRepresentable() { enum Keys: String { case root; case catalog; case book; case id; case bk102; case author } @@ -125,7 +136,8 @@ struct XMLParsingTests { } } - @Test func shouldBeAbleToLookUpElementsByNameAndAttributeCaseInsensitive() { + @Test + func shouldBeAbleToLookUpElementsByNameAndAttributeCaseInsensitive() { do { let xmlInsensitive = XMLHash.config({ config in config.caseInsensitive = true @@ -137,20 +149,24 @@ struct XMLParsingTests { } } - @Test func shouldBeAbleToIterateElementGroups() { + @Test + func shouldBeAbleToIterateElementGroups() { let result = xml!["root"]["catalog"]["book"].all.map({ $0["genre"].element!.text }).joined(separator: ", ") #expect(result == "Computer, Fantasy, Fantasy") } - @Test func shouldBeAbleToIterateElementGroupsEvenIfOnlyOneElementIsFound() { + @Test + func shouldBeAbleToIterateElementGroupsEvenIfOnlyOneElementIsFound() { #expect(xml!["root"]["header"]["title"].all.count == 1) } - @Test func shouldBeAbleToIndexElementGroupsEvenIfOnlyOneElementIsFound() { + @Test + func shouldBeAbleToIndexElementGroupsEvenIfOnlyOneElementIsFound() { #expect(xml!["root"]["header"]["title"][0].element?.text == "Test Title Header") } - @Test func shouldBeAbleToIterateUsingForIn() { + @Test + func shouldBeAbleToIterateUsingForIn() { var count = 0 for _ in xml!["root"]["catalog"]["book"].all { count += 1 @@ -159,16 +175,19 @@ struct XMLParsingTests { #expect(count == 3) } - @Test func shouldBeAbleToEnumerateChildren() { + @Test + func shouldBeAbleToEnumerateChildren() { let result = xml!["root"]["catalog"]["book"][0].children.map({ $0.element!.name }).joined(separator: ", ") #expect(result == "author, title, genre, price, publish_date, description") } - @Test func shouldBeAbleToHandleMixedContent() { + @Test + func shouldBeAbleToHandleMixedContent() { #expect(xml!["root"]["header"].element?.text == "header mixed contentmore mixed content") } - @Test func shouldBeAbleToIterateOverMixedContent() { + @Test + func shouldBeAbleToIterateOverMixedContent() { let mixedContentXml = "

mixed content iteration support" let parsed = XMLHash.parse(mixedContentXml) let element = parsed["html"]["body"]["p"].element @@ -191,7 +210,8 @@ struct XMLParsingTests { } } - @Test func shouldBeAbleToRecursiveOutputTextContent() { + @Test + func shouldBeAbleToRecursiveOutputTextContent() { let mixedContentXmlInputs = [ // From SourceKit cursor info key.annotated_decl "typealias SomeHandle = UInt", @@ -216,7 +236,8 @@ struct XMLParsingTests { } } - @Test func shouldHandleInterleavingXMLElements() { + @Test + func shouldHandleInterleavingXMLElements() { let interleavedXml = "

one

two

three

four
" let parsed = XMLHash.parse(interleavedXml) @@ -224,14 +245,16 @@ struct XMLParsingTests { #expect(result == "one, two, three, four") } - @Test func shouldBeAbleToProvideADescriptionForTheDocument() { + @Test + func shouldBeAbleToProvideADescriptionForTheDocument() { let descriptionXml = "puppies" let parsed = XMLHash.parse(descriptionXml) #expect(parsed.description == "puppies") } - @Test func shouldBeAbleToGetInnerXML() { + @Test + func shouldBeAbleToGetInnerXML() { let testXML = "puppies12" let parsed = XMLHash.parse(testXML) @@ -240,11 +263,13 @@ struct XMLParsingTests { // error handling - @Test func shouldReturnNilWhenKeysDontMatch() { + @Test + func shouldReturnNilWhenKeysDontMatch() { #expect(xml!["root"]["what"]["header"]["foo"].element?.name == nil) } - @Test func shouldProvideAnErrorObjectWhenKeysDontMatch() { + @Test + func shouldProvideAnErrorObjectWhenKeysDontMatch() { var err: IndexingError? defer { #expect(err != nil) @@ -260,7 +285,8 @@ struct XMLParsingTests { Added Only test coverage for: `byKey(_ key: K) throws -> XMLIndexer where K.RawValue == String` */ - @Test func shouldProvideAnErrorObjectWhenKeysDontMatchWithStringRawRepresentable() { + @Test + func shouldProvideAnErrorObjectWhenKeysDontMatchWithStringRawRepresentable() { enum Keys: String { case root; case what; case header; case foo } @@ -275,7 +301,8 @@ struct XMLParsingTests { } catch { err = nil } } - @Test func shouldProvideAnErrorElementWhenIndexersDontMatch() { + @Test + func shouldProvideAnErrorElementWhenIndexersDontMatch() { var err: IndexingError? defer { #expect(err != nil) @@ -287,7 +314,8 @@ struct XMLParsingTests { } catch { err = nil } } - @Test func shouldStillReturnErrorsWhenAccessingViaSubscripting() { + @Test + func shouldStillReturnErrorsWhenAccessingViaSubscripting() { var err: IndexingError? switch xml!["what"]["subelement"][5]["nomatch"] { case .xmlError(let error): @@ -298,7 +326,8 @@ struct XMLParsingTests { #expect(err != nil) } - @Test func shouldBeAbleToCreateASubIndexer() { + @Test + func shouldBeAbleToCreateASubIndexer() { let xmlToParse = """ @@ -327,7 +356,8 @@ struct XMLParsingTests { #expect(subIndexer["last-weird-element"].element == nil) } - @Test func shouldBeAbleToCreateASubIndexerFromFilter() { + @Test + func shouldBeAbleToCreateASubIndexerFromFilter() { let subIndexer = xml!["root"]["catalog"]["book"][1].filterChildren { elem, _ in let filterByNames = ["title", "genre", "price"] return filterByNames.contains(elem.name) @@ -342,7 +372,8 @@ struct XMLParsingTests { #expect(subIndexer.children[2].element?.text == "5.95") } - @Test func shouldBeAbleToFilterOnIndexer() { + @Test + func shouldBeAbleToFilterOnIndexer() { let subIndexer = xml!["root"]["catalog"]["book"] .filterAll { elem, _ in elem.attribute(by: "id")!.text == "bk102" } .filterChildren { _, index in index >= 1 && index <= 3 } @@ -356,7 +387,8 @@ struct XMLParsingTests { #expect(subIndexer.children[2].element?.text == "5.95") } - @Test func shouldThrowErrorForInvalidXML() { + @Test + func shouldThrowErrorForInvalidXML() { let invalidXML = "what is this" var err: ParsingError? let parser = XMLHash.config { config in diff --git a/Tests/SWXMLHashTests/XMLParsingValidationTests.swift b/Tests/SWXMLHashTests/XMLParsingValidationTests.swift index aea9aef0..c4859cfa 100644 --- a/Tests/SWXMLHashTests/XMLParsingValidationTests.swift +++ b/Tests/SWXMLHashTests/XMLParsingValidationTests.swift @@ -68,7 +68,8 @@ struct XMLParsingValidationTests { """ - @Test func validatePriceOutOfBounds() { + @Test + func validatePriceOutOfBounds() { do { let xml = XMLHash.parse(xmlToParseOOB) let _: BasicItem = try xml["root"]["basicItem"].value() @@ -80,7 +81,8 @@ struct XMLParsingValidationTests { } } - @Test func validatePriceInBounds() { + @Test + func validatePriceInBounds() { do { let xml = XMLHash.parse(xmlToParseIB) let value: BasicItem = try xml["root"]["basicItem"].value()