From 56f554e3d10aa2574a96823ca634f0a29311d1ed Mon Sep 17 00:00:00 2001 From: Vincent Tourraine Date: Mon, 20 Aug 2018 19:22:16 +0200 Subject: [PATCH] Refactor new line regex test with discrete reference files --- AcknowList.xcodeproj/project.pbxproj | 38 +++++++-- Tests/AcknowParserTests.swift | 41 +++------- Tests/RegexTesting-GroundTruth-Alamofire.txt | 7 ++ ...gs => RegexTesting-GroundTruth-Charts.txt} | 80 ------------------- ...Testing-GroundTruth-TPKeyboardAvoiding.txt | 11 +++ ...egexTesting-GroundTruth-TYPFontAwesome.txt | 39 +++++++++ Tests/RegexTesting-GroundTruth-pop.txt | 15 ++++ 7 files changed, 115 insertions(+), 116 deletions(-) create mode 100644 Tests/RegexTesting-GroundTruth-Alamofire.txt rename Tests/{Pods-acknowledgements-RegexTesting-GroundTruth.strings => RegexTesting-GroundTruth-Charts.txt} (56%) create mode 100644 Tests/RegexTesting-GroundTruth-TPKeyboardAvoiding.txt create mode 100644 Tests/RegexTesting-GroundTruth-TYPFontAwesome.txt create mode 100644 Tests/RegexTesting-GroundTruth-pop.txt diff --git a/AcknowList.xcodeproj/project.pbxproj b/AcknowList.xcodeproj/project.pbxproj index ec273b3..712cdca 100644 --- a/AcknowList.xcodeproj/project.pbxproj +++ b/AcknowList.xcodeproj/project.pbxproj @@ -20,7 +20,11 @@ 1AD73B921CAC3B1C0084F8CA /* Pods-acknowledgements.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1AD73B901CAC3B140084F8CA /* Pods-acknowledgements.plist */; }; 1AD73BBE1CAC54C60084F8CA /* AcknowList.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 1AD73BBD1CAC54C60084F8CA /* AcknowList.bundle */; }; 503E61E9212997CE00322F6C /* Pods-acknowledgements-RegexTesting.plist in Resources */ = {isa = PBXBuildFile; fileRef = 503E61E8212997CD00322F6C /* Pods-acknowledgements-RegexTesting.plist */; }; - 503E61EB212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings in Resources */ = {isa = PBXBuildFile; fileRef = 503E61EA212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings */; }; + D70B427D212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt in Resources */ = {isa = PBXBuildFile; fileRef = D70B427C212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt */; }; + D70B427F212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt in Resources */ = {isa = PBXBuildFile; fileRef = D70B427E212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt */; }; + D70B4281212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt in Resources */ = {isa = PBXBuildFile; fileRef = D70B4280212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt */; }; + D70B4283212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt in Resources */ = {isa = PBXBuildFile; fileRef = D70B4282212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt */; }; + D70B4285212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt in Resources */ = {isa = PBXBuildFile; fileRef = D70B4284212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt */; }; D7CCBD131D22624B0013F696 /* Pods-acknowledgements-multi.plist in Resources */ = {isa = PBXBuildFile; fileRef = D7CCBD121D22624B0013F696 /* Pods-acknowledgements-multi.plist */; }; /* End PBXBuildFile section */ @@ -51,7 +55,11 @@ 1AD73B901CAC3B140084F8CA /* Pods-acknowledgements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Pods-acknowledgements.plist"; path = "Tests/Pods-acknowledgements.plist"; sourceTree = SOURCE_ROOT; }; 1AD73BBD1CAC54C60084F8CA /* AcknowList.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = AcknowList.bundle; path = Resources/AcknowList.bundle; sourceTree = SOURCE_ROOT; }; 503E61E8212997CD00322F6C /* Pods-acknowledgements-RegexTesting.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Pods-acknowledgements-RegexTesting.plist"; sourceTree = ""; }; - 503E61EA212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings */ = {isa = PBXFileReference; explicitFileType = text; path = "Pods-acknowledgements-RegexTesting-GroundTruth.strings"; sourceTree = ""; }; + D70B427C212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-Alamofire.txt"; sourceTree = ""; }; + D70B427E212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-Charts.txt"; sourceTree = ""; }; + D70B4280212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-TPKeyboardAvoiding.txt"; sourceTree = ""; }; + D70B4282212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-TYPFontAwesome.txt"; sourceTree = ""; }; + D70B4284212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-pop.txt"; sourceTree = ""; }; D7CCBD121D22624B0013F696 /* Pods-acknowledgements-multi.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Pods-acknowledgements-multi.plist"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -114,6 +122,7 @@ 1420A2E31CAEC92200D98F9C /* AcknowLocalizationTests.swift */, 1A7421731CAC3685007E44FD /* AcknowParserTests.swift */, 1A7421741CAC3685007E44FD /* AcknowViewControllerTests.swift */, + D70B4286212B2EFF007B6A81 /* Resources */, 1AD73B8F1CAC3AEB0084F8CA /* Supporting Files */, ); name = AcknowListTests; @@ -123,10 +132,6 @@ 1AD73B8F1CAC3AEB0084F8CA /* Supporting Files */ = { isa = PBXGroup; children = ( - 1AD73B901CAC3B140084F8CA /* Pods-acknowledgements.plist */, - D7CCBD121D22624B0013F696 /* Pods-acknowledgements-multi.plist */, - 503E61E8212997CD00322F6C /* Pods-acknowledgements-RegexTesting.plist */, - 503E61EA212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings */, 1AA3C3851CAC35190071A7FD /* Info.plist */, ); name = "Supporting Files"; @@ -148,6 +153,21 @@ name = Resources; sourceTree = ""; }; + D70B4286212B2EFF007B6A81 /* Resources */ = { + isa = PBXGroup; + children = ( + 1AD73B901CAC3B140084F8CA /* Pods-acknowledgements.plist */, + D7CCBD121D22624B0013F696 /* Pods-acknowledgements-multi.plist */, + 503E61E8212997CD00322F6C /* Pods-acknowledgements-RegexTesting.plist */, + D70B427C212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt */, + D70B427E212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt */, + D70B4280212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt */, + D70B4282212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt */, + D70B4284212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt */, + ); + name = Resources; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -248,10 +268,14 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 503E61EB212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings in Resources */, + D70B427D212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt in Resources */, 503E61E9212997CE00322F6C /* Pods-acknowledgements-RegexTesting.plist in Resources */, + D70B427F212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt in Resources */, 1AD73B921CAC3B1C0084F8CA /* Pods-acknowledgements.plist in Resources */, + D70B4283212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt in Resources */, D7CCBD131D22624B0013F696 /* Pods-acknowledgements-multi.plist in Resources */, + D70B4281212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt in Resources */, + D70B4285212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/AcknowParserTests.swift b/Tests/AcknowParserTests.swift index f18241e..4a83774 100644 --- a/Tests/AcknowParserTests.swift +++ b/Tests/AcknowParserTests.swift @@ -73,13 +73,12 @@ class AcknowParserTests: XCTestCase { // // (3) Created this test, which parses the plist and applies the regex, then // verifies that the generated strings are correct verus a manually edited - // "ground truth" - func testNewlineRegex() { + // "ground truth" text file. + func testFilterOutPrematureLineBreaks() { let bundle = Bundle(for: AcknowParserTests.self) let plistPath = bundle.path(forResource: "Pods-acknowledgements-RegexTesting", ofType: "plist") - let gtPath = bundle.path(forResource: "Pods-acknowledgements-RegexTesting-GroundTruth", ofType: "strings") - if let plistPath = plistPath, let gtPath = gtPath { + if let plistPath = plistPath { let parser = AcknowParser(plistPath: plistPath) XCTAssertNotNil(parser) @@ -87,32 +86,16 @@ class AcknowParserTests: XCTestCase { XCTAssertEqual(acknowledgements.count, 5) // For each acknowledgement, load the ground truth and compare... + for acknowledgement in acknowledgements { + let groundTruthPath = bundle.url(forResource: "RegexTesting-GroundTruth-\(acknowledgement.title)", withExtension: "txt") + do { + let groundTruth = try String(contentsOf: groundTruthPath!, encoding: .utf8) + XCTAssertEqual(acknowledgement.text, groundTruth) + } + catch { + XCTFail("Cannot load ground truth") + } - // Decode our very crude way of encoding ground truths... - // Components are seperated by "///", in the format: - // /// TEST /// /// - var gtStrings: [String] - do { - gtStrings = try String(contentsOfFile: gtPath).components(separatedBy: "///") - } catch { - return XCTAssert(false, "Ground truth file not found or not readable") - } - gtStrings.removeFirst() // The 1st entry will be an empty string - - for i in 0..