Skip to content

Commit

Permalink
Refactor new line regex test with discrete reference files
Browse files Browse the repository at this point in the history
  • Loading branch information
vtourraine committed Aug 20, 2018
1 parent 2bba9ef commit 56f554e
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 116 deletions.
38 changes: 31 additions & 7 deletions AcknowList.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 = "<group>"; };
503E61EA212999FB00322F6C /* Pods-acknowledgements-RegexTesting-GroundTruth.strings */ = {isa = PBXFileReference; explicitFileType = text; path = "Pods-acknowledgements-RegexTesting-GroundTruth.strings"; sourceTree = "<group>"; };
D70B427C212B2916007B6A81 /* RegexTesting-GroundTruth-Alamofire.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-Alamofire.txt"; sourceTree = "<group>"; };
D70B427E212B2941007B6A81 /* RegexTesting-GroundTruth-Charts.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-Charts.txt"; sourceTree = "<group>"; };
D70B4280212B295B007B6A81 /* RegexTesting-GroundTruth-TPKeyboardAvoiding.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-TPKeyboardAvoiding.txt"; sourceTree = "<group>"; };
D70B4282212B2970007B6A81 /* RegexTesting-GroundTruth-TYPFontAwesome.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-TYPFontAwesome.txt"; sourceTree = "<group>"; };
D70B4284212B2988007B6A81 /* RegexTesting-GroundTruth-pop.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RegexTesting-GroundTruth-pop.txt"; sourceTree = "<group>"; };
D7CCBD121D22624B0013F696 /* Pods-acknowledgements-multi.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Pods-acknowledgements-multi.plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -114,6 +122,7 @@
1420A2E31CAEC92200D98F9C /* AcknowLocalizationTests.swift */,
1A7421731CAC3685007E44FD /* AcknowParserTests.swift */,
1A7421741CAC3685007E44FD /* AcknowViewControllerTests.swift */,
D70B4286212B2EFF007B6A81 /* Resources */,
1AD73B8F1CAC3AEB0084F8CA /* Supporting Files */,
);
name = AcknowListTests;
Expand All @@ -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";
Expand All @@ -148,6 +153,21 @@
name = Resources;
sourceTree = "<group>";
};
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 = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -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;
};
Expand Down
41 changes: 12 additions & 29 deletions Tests/AcknowParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,46 +73,29 @@ 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)

let acknowledgements = parser.parseAcknowledgements()
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 <Number> /// <Pod Name> /// <License Text>
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..<acknowledgements.count {
// For each i value, gtStrings[i * 3 + 0] is the test number,
// gtStrings[i * 3 + 1] is the pod name,
// gtStrings[i * 3 + 2] is the license text to compare
//
// We trim newlines and whitespace **surrounding** the content to avoid
// encoding discrepencies, but not within the string itself (obviously).
let testNumberHeader = gtStrings[i * 3].trimmingCharacters(in: .whitespaces)
let testTitle = gtStrings[i * 3 + 1].trimmingCharacters(in: .whitespaces)
let testLicenseText = gtStrings[i * 3 + 2].trimmingCharacters(in: .whitespacesAndNewlines)

XCTAssertEqual(testNumberHeader, "TEST \(i + 1)")
XCTAssertEqual(testTitle, acknowledgements[i].title)
XCTAssertEqual(testLicenseText, acknowledgements[i].text.trimmingCharacters(in: .whitespacesAndNewlines))
}
}
else {
Expand Down
7 changes: 7 additions & 0 deletions Tests/RegexTesting-GroundTruth-Alamofire.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/// TEST 1 /// Alamofire ///
Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

/// TEST 2 /// Charts ///
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Expand Down Expand Up @@ -74,73 +64,3 @@ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

/// TEST 3 /// TPKeyboardAvoiding ///
Copyright (c) 2013 Michael Tyson

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

/// TEST 4 /// TYPFontAwesome ///
Copyright (c) 2014, Font Awesome (http://fontawesome.io), with Reserved Font Name Font Awesome.

This Font Software is licensed under the SIL Open Font License, Version 1.1.

This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

SIL OPEN FONT LICENSE

Version 1.1 - 26 February 2007

PREAMBLE The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS "Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting — in part or in whole — any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION This license becomes null and void if any of the above conditions are not met.

DISCLAIMER THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

/// TEST 5 /// pop ///
BSD License

For Pop software

Copyright (c) 2014, Facebook, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name Facebook nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 56f554e

Please sign in to comment.