Skip to content

Commit

Permalink
Add tests for TranslationsLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkowz committed Jul 26, 2015
1 parent f947174 commit eed66f3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
24 changes: 23 additions & 1 deletion Swifternalization.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
6D5004671B3EF92600A54B36 /* TranslatablePair.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D5004651B3EF92600A54B36 /* TranslatablePair.swift */; };
6D5004921B3EFF6D00A54B36 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6D5004941B3EFF6D00A54B36 /* Localizable.strings */; };
6D5004961B3EFFC100A54B36 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6D5004591B3EF91600A54B36 /* Info.plist */; };
6D5BA5F01B651796000D7E49 /* TranslationsLoaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D5BA5EF1B651796000D7E49 /* TranslationsLoaderTests.swift */; };
6D5BA5F11B6517A6000D7E49 /* TranslationsLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC731B5EBDA600A1220F /* TranslationsLoader.swift */; };
6D5BA5F21B6517FE000D7E49 /* TranslationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC741B5EBDA600A1220F /* TranslationType.swift */; };
6D5BA5F31B651809000D7E49 /* LengthVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC6A1B5EBDA600A1220F /* LengthVariation.swift */; };
6D5BA5F41B65180F000D7E49 /* LengthVariationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC6B1B5EBDA600A1220F /* LengthVariationType.swift */; };
6D5BA5F51B65181C000D7E49 /* TranslationSimple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC721B5EBDA600A1220F /* TranslationSimple.swift */; };
6D5BA5F61B651821000D7E49 /* TranslationLengthVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC711B5EBDA600A1220F /* TranslationLengthVariation.swift */; };
6D5BA5F71B651825000D7E49 /* ProcessableLengthVariationExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC6E1B5EBDA600A1220F /* ProcessableLengthVariationExpression.swift */; };
6D5BA5F81B65182D000D7E49 /* ProcessableTranslationLengthVariationExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC701B5EBDA600A1220F /* ProcessableTranslationLengthVariationExpression.swift */; };
6D5BA5F91B651831000D7E49 /* ProcessableTranslationExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3CC6F1B5EBDA600A1220F /* ProcessableTranslationExpression.swift */; };
6D6282921B3F04C800E65FCD /* Expression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6282911B3F04C800E65FCD /* Expression.swift */; };
6D6282941B3F052B00E65FCD /* TranslatablePairTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D6282931B3F052B00E65FCD /* TranslatablePairTests.swift */; };
6D6282951B3F05DE00E65FCD /* TranslatablePair.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D5004651B3EF92600A54B36 /* TranslatablePair.swift */; };
Expand Down Expand Up @@ -127,6 +137,7 @@
6D5004641B3EF92600A54B36 /* Swifternalization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swifternalization.swift; sourceTree = "<group>"; };
6D5004651B3EF92600A54B36 /* TranslatablePair.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslatablePair.swift; sourceTree = "<group>"; };
6D5004931B3EFF6D00A54B36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
6D5BA5EF1B651796000D7E49 /* TranslationsLoaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslationsLoaderTests.swift; sourceTree = "<group>"; };
6D6282911B3F04C800E65FCD /* Expression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Expression.swift; sourceTree = "<group>"; };
6D6282931B3F052B00E65FCD /* TranslatablePairTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslatablePairTests.swift; sourceTree = "<group>"; };
6D6282971B3F13C300E65FCD /* ExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpressionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -285,8 +296,8 @@
6D5004571B3EF91600A54B36 /* SwifternalizationTests */ = {
isa = PBXGroup;
children = (
6DD3B93F1B5ED37A00C79EAC /* Loaders */,
6D140F451B56D04300359143 /* Helpers */,
6DD3B93F1B5ED37A00C79EAC /* Loaders */,
6D6282971B3F13C300E65FCD /* ExpressionTests.swift */,
6D6282BE1B3F42CA00E65FCD /* InequalityExpressionMatcherTests.swift */,
6D6282A81B3F25DC00E65FCD /* InequalityExpressionParserTests.swift */,
Expand Down Expand Up @@ -439,6 +450,7 @@
children = (
6DD3B9401B5ED38B00C79EAC /* JSONFileLoaderTests.swift */,
6DD3B9431B5ED55500C79EAC /* ExpressionsLoaderTests.swift */,
6D5BA5EF1B651796000D7E49 /* TranslationsLoaderTests.swift */,
);
name = Loaders;
sourceTree = "<group>";
Expand Down Expand Up @@ -646,20 +658,26 @@
6D50045B1B3EF91600A54B36 /* SwifternalizationTests.swift in Sources */,
6D6282A61B3F25B900E65FCD /* InequalityExpressionParser.swift in Sources */,
6D6282B81B3F3E2200E65FCD /* InequalitySign.swift in Sources */,
6D5BA5F31B651809000D7E49 /* LengthVariation.swift in Sources */,
6DB3CC861B5EBF4800A1220F /* CountryCode.swift in Sources */,
6D6282A71B3F25BE00E65FCD /* ExpressionMatcher.swift in Sources */,
6DD3B94B1B5ED65A00C79EAC /* NSBundle+TestExtension.swift in Sources */,
6D6464851B40146600C46C6D /* KeyValueType.swift in Sources */,
6DD3B9481B5ED61500C79EAC /* Processable.swift in Sources */,
6D6282C81B3F4F6400E65FCD /* RegexExpressionMatcher.swift in Sources */,
6DD3B9421B5ED3F000C79EAC /* JSONFileLoader.swift in Sources */,
6D5BA5F91B651831000D7E49 /* ProcessableTranslationExpression.swift in Sources */,
6D5BA5F21B6517FE000D7E49 /* TranslationType.swift in Sources */,
6DBB6C6A1B40412D002F39A3 /* InternalPattern.swift in Sources */,
6DD3B9411B5ED38B00C79EAC /* JSONFileLoaderTests.swift in Sources */,
6DB3CC911B5EC29E00A1220F /* ExpressionType.swift in Sources */,
6D6282941B3F052B00E65FCD /* TranslatablePairTests.swift in Sources */,
6DBB6C941B40769F002F39A3 /* SharedPolishExpression.swift in Sources */,
6DBB6C931B40769F002F39A3 /* SharedExpression.swift in Sources */,
6DBB6C521B401B8A002F39A3 /* Swifternalization.swift in Sources */,
6D5BA5F71B651825000D7E49 /* ProcessableLengthVariationExpression.swift in Sources */,
6D5BA5F01B651796000D7E49 /* TranslationsLoaderTests.swift in Sources */,
6D5BA5F41B65180F000D7E49 /* LengthVariationType.swift in Sources */,
6D6282951B3F05DE00E65FCD /* TranslatablePair.swift in Sources */,
6D6282BF1B3F42CA00E65FCD /* InequalityExpressionMatcherTests.swift in Sources */,
6D6282961B3F063A00E65FCD /* Expression.swift in Sources */,
Expand All @@ -672,14 +690,18 @@
6D6282CB1B3F508C00E65FCD /* RegexExpressionParserTests.swift in Sources */,
6DD3B9461B5ED5B500C79EAC /* ProcessableExpression.swift in Sources */,
6D6282C31B3F45A600E65FCD /* InequalityExtendedExpressionParserTests.swift in Sources */,
6D5BA5F51B65181C000D7E49 /* TranslationSimple.swift in Sources */,
6D6282A91B3F25DC00E65FCD /* InequalityExpressionParserTests.swift in Sources */,
6D5BA5F81B65182D000D7E49 /* ProcessableTranslationLengthVariationExpression.swift in Sources */,
6D6282AA1B3F269900E65FCD /* ExpressionParser.swift in Sources */,
6D5BA5F11B6517A6000D7E49 /* TranslationsLoader.swift in Sources */,
6D6282BB1B3F41DB00E65FCD /* InequalityExtendedExpressionMatcher.swift in Sources */,
6DBB6C511B401B7C002F39A3 /* LocalizableFilesLoader.swift in Sources */,
6DBB6C6C1B40431D002F39A3 /* LocalizableFilesLoaderTests.swift in Sources */,
6DD3B9471B5ED61100C79EAC /* ExpressionPatternType.swift in Sources */,
6DBB6C961B4076E8002F39A3 /* SharedBaseExpressionTests.swift in Sources */,
6D62829B1B3F17FE00E65FCD /* Regex.swift in Sources */,
6D5BA5F61B651821000D7E49 /* TranslationLengthVariation.swift in Sources */,
6D6282CD1B3F52AD00E65FCD /* RegexExpressionMatcherTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 2 additions & 2 deletions Swifternalization/TranslationsLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ final class TranslationsLoader: JSONFileLoader {

:return: translations parsed from the file.
*/
class func loadTranslations(countryCode: CountryCode) -> [TranslationType] {
class func loadTranslations(countryCode: CountryCode, bundle: NSBundle = NSBundle.mainBundle()) -> [TranslationType] {
var loadedTranslations = [TranslationType]()
let json = self.load(countryCode, bundle: NSBundle.mainBundle())
let json = self.load(countryCode, bundle: bundle)
if json == nil { return [TranslationType]() }

for (translationKey, value) in json! {
Expand Down
28 changes: 28 additions & 0 deletions SwifternalizationTests/TranslationsLoaderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// TranslationsLoaderTests.swift
// Swifternalization
//
// Created by Tomasz Szulc on 26/07/15.
// Copyright (c) 2015 Tomasz Szulc. All rights reserved.
//

import UIKit
import XCTest

class TranslationsLoaderTests: XCTestCase {

func testShouldLoadBase() {
let content = TranslationsLoader.loadTranslations("pl", bundle: NSBundle.testBundle())
XCTAssertTrue(content.count > 0, "")
}

func testShouldLoadPL() {
let content = TranslationsLoader.loadTranslations("base", bundle: NSBundle.testBundle())
XCTAssertTrue(content.count > 0, "")
}

func testShouldNotLoadDE() {
let content = TranslationsLoader.loadTranslations("de", bundle: NSBundle.testBundle())
XCTAssertFalse(content.count > 0, "")
}
}

0 comments on commit eed66f3

Please sign in to comment.