Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkawa committed Feb 17, 2015
1 parent fe25288 commit 66836fd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
22 changes: 22 additions & 0 deletions UnitTests/LprojFileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import XCTest

class LprojFileTests: XCTestCase {
var lprojFile: LprojFile!

override func setUp() {
super.setUp()

let path = NSFileManager.defaultManager().currentDirectoryPath.stringByAppendingPathComponent("DemoApp/Base.lproj")
let URL = NSURL(fileURLWithPath: path)!
lprojFile = LprojFile(URL: URL)
}

func testXibFiles() {
XCTAssertEqual(lprojFile!.xibFiles.map({ $0.name }), ["LaunchScreen", "Main"])
}

func testStringsFiles() {
XCTAssertEqual(lprojFile!.stringsFiles.map({ $0.name }), ["Localizable"])
}
}
23 changes: 23 additions & 0 deletions UnitTests/StringsFileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation
import XCTest

class StringsFileTests: XCTestCase {
var localizableStringsFile: StringsFile!
var xibStringsFile: StringsFile!

override func setUp() {
super.setUp()

let directoryPath = NSFileManager.defaultManager().currentDirectoryPath.stringByAppendingPathComponent("DemoApp")
let directoryURL = NSURL(fileURLWithPath: directoryPath)!
localizableStringsFile = StringsFile(URL: directoryURL.URLByAppendingPathComponent("en.lproj/Localizable.strings"))
xibStringsFile = StringsFile(URL: directoryURL.URLByAppendingPathComponent("en.lproj/Main.strings"))
}

func testUpdate() {
xibStringsFile.updateValuesUsingLocalizableStringsFile(localizableStringsFile)

XCTAssertEqual(xibStringsFile.dictionary["xUH-o8-DGc.text"]!, "Hello")
XCTAssertEqual(xibStringsFile.dictionary["uZj-A7-ihc.normalTitle"]!, "Get started")
}
}
8 changes: 8 additions & 0 deletions ls2xs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
7F0A6CEF1A932B7D007CF9D8 /* LprojFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F0A6CEE1A932B7D007CF9D8 /* LprojFileTests.swift */; };
7F0A6CF11A932D24007CF9D8 /* StringsFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F0A6CF01A932D24007CF9D8 /* StringsFileTests.swift */; };
7F3616581A89DA8C00254E5E /* NSFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F9751651A89D999005E27F8 /* NSFileManager.swift */; };
7F96F2181A931753001F50EE /* Target.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F96F2171A931753001F50EE /* Target.swift */; };
7F96F21C1A931F48001F50EE /* Target.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F96F2171A931753001F50EE /* Target.swift */; };
Expand All @@ -30,6 +32,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7F0A6CEE1A932B7D007CF9D8 /* LprojFileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LprojFileTests.swift; sourceTree = "<group>"; };
7F0A6CF01A932D24007CF9D8 /* StringsFileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringsFileTests.swift; sourceTree = "<group>"; };
7F36165A1A89DF9200254E5E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
7F36165C1A89DF9600254E5E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
7F96F2171A931753001F50EE /* Target.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Target.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,6 +145,8 @@
isa = PBXGroup;
children = (
7F9ABCED1A88E7F500ACB4B9 /* TargetTests.swift */,
7F0A6CEE1A932B7D007CF9D8 /* LprojFileTests.swift */,
7F0A6CF01A932D24007CF9D8 /* StringsFileTests.swift */,
7F9ABCE61A88E7D700ACB4B9 /* Supporting Files */,
);
path = UnitTests;
Expand Down Expand Up @@ -306,11 +312,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7F0A6CEF1A932B7D007CF9D8 /* LprojFileTests.swift in Sources */,
7F9ABCF11A88E84500ACB4B9 /* StringsFile.swift in Sources */,
7F9ABCEE1A88E7F500ACB4B9 /* TargetTests.swift in Sources */,
7F3616581A89DA8C00254E5E /* NSFileManager.swift in Sources */,
7F9751641A89D8CF005E27F8 /* main.swift in Sources */,
7F96F21E1A931F48001F50EE /* XibFile.swift in Sources */,
7F0A6CF11A932D24007CF9D8 /* StringsFileTests.swift in Sources */,
7F96F21C1A931F48001F50EE /* Target.swift in Sources */,
7F96F21D1A931F48001F50EE /* LprojFile.swift in Sources */,
);
Expand Down
4 changes: 3 additions & 1 deletion ls2xs/StringsFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import Foundation

class StringsFile {
let URL: NSURL
let name: String
var dictionary: [String: String]

init?(URL: NSURL) {
self.URL = URL
self.name = URL.lastPathComponent?.stringByDeletingPathExtension ?? ""
self.dictionary = (NSDictionary(contentsOfURL: URL) as? [String: String]) ?? [String: String]()

if URL.pathExtension != "strings" {
if URL.pathExtension != "strings" || self.name.isEmpty {
return nil
}
}
Expand Down

0 comments on commit 66836fd

Please sign in to comment.