Skip to content

Commit 0a8959e

Browse files
committed
Test token replacement
1 parent 8b15c7d commit 0a8959e

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

OSRMTextInstructions.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
358D145A1E5E355600ADE590 /* OSRMTextInstructions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D14571E5E355600ADE590 /* OSRMTextInstructions.h */; settings = {ATTRIBUTES = (Public, ); }; };
1616
358D145B1E5E355600ADE590 /* OSRMTextInstructions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 358D14581E5E355600ADE590 /* OSRMTextInstructions.swift */; };
1717
C51B63E91E65FA04002F4634 /* TokenType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C51B63E81E65FA04002F4634 /* TokenType.swift */; };
18+
DA5F02781F6CBAAF0040C4AD /* TokenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */; };
19+
DA5F02791F6CBAAF0040C4AD /* TokenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */; };
20+
DA5F027A1F6CBAAF0040C4AD /* TokenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */; };
1821
DA5F589C1E85A32C00BA4D0A /* OSRMTextInstructions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA5F58931E85A32C00BA4D0A /* OSRMTextInstructions.framework */; };
1922
DA5F58AB1E85B0A000BA4D0A /* OSRMTextInstructions.h in Headers */ = {isa = PBXBuildFile; fileRef = 358D14571E5E355600ADE590 /* OSRMTextInstructions.h */; settings = {ATTRIBUTES = (Public, ); }; };
2023
DA5F58AC1E85B0A500BA4D0A /* OSRMTextInstructions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 358D14581E5E355600ADE590 /* OSRMTextInstructions.swift */; };
@@ -80,6 +83,7 @@
8083
35EBDB5D1E5E1572006EB3CD /* OSRMTextInstructions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OSRMTextInstructions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8184
C51B63E81E65FA04002F4634 /* TokenType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenType.swift; sourceTree = "<group>"; };
8285
DA2DFB3B1E8373AF00CEEBE9 /* json2plist.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = json2plist.sh; sourceTree = "<group>"; };
86+
DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenTests.swift; sourceTree = SOURCE_ROOT; };
8387
DA5F58931E85A32C00BA4D0A /* OSRMTextInstructions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OSRMTextInstructions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8488
DA5F589B1E85A32C00BA4D0A /* OSRMTextInstructionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OSRMTextInstructionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
8589
DA5F58B61E85B24E00BA4D0A /* MapboxDirections.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapboxDirections.framework; path = Carthage/Build/Mac/MapboxDirections.framework; sourceTree = "<group>"; };
@@ -177,8 +181,9 @@
177181
352BBC2A1E5E4D4200703DF1 /* OSRMTextInstructionsTests */ = {
178182
isa = PBXGroup;
179183
children = (
180-
352BBC2B1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift */,
181184
352BBC2D1E5E4D4200703DF1 /* Info.plist */,
185+
352BBC2B1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift */,
186+
DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */,
182187
);
183188
path = OSRMTextInstructionsTests;
184189
sourceTree = "<group>";
@@ -637,6 +642,7 @@
637642
isa = PBXSourcesBuildPhase;
638643
buildActionMask = 2147483647;
639644
files = (
645+
DA5F02781F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
640646
352BBC2C1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift in Sources */,
641647
);
642648
runOnlyForDeploymentPostprocessing = 0;
@@ -665,6 +671,7 @@
665671
isa = PBXSourcesBuildPhase;
666672
buildActionMask = 2147483647;
667673
files = (
674+
DA5F02791F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
668675
DA5F58AE1E85B0AE00BA4D0A /* OSRMTextInstructionsTests.swift in Sources */,
669676
);
670677
runOnlyForDeploymentPostprocessing = 0;
@@ -683,6 +690,7 @@
683690
isa = PBXSourcesBuildPhase;
684691
buildActionMask = 2147483647;
685692
files = (
693+
DA5F027A1F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
686694
DA5F58E61E85BE1900BA4D0A /* OSRMTextInstructionsTests.swift in Sources */,
687695
);
688696
runOnlyForDeploymentPostprocessing = 0;

OSRMTextInstructions.xcodeproj/xcshareddata/xcschemes/OSRMTextInstructions macOS.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
3031
<Testables>
3132
<TestableReference
3233
skipped = "NO">

OSRMTextInstructions/OSRMTextInstructions.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ extension String: Tokenized {
3434

3535
var token: NSString?
3636
guard scanner.scanUpTo("}", into: &token) else {
37+
result += "{"
3738
continue
3839
}
3940

4041
if scanner.scanString("}", into: nil) {
4142
if let tokenType = TokenType(description: token! as String) {
4243
result += interpolator(tokenType)
44+
} else {
45+
result += "{\(token!)}"
4346
}
4447
} else {
45-
result += token! as String
48+
result += "{\(token!)"
4649
}
4750
}
4851

TokenTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import XCTest
2+
import OSRMTextInstructions
3+
4+
class TokenTests: XCTestCase {
5+
func testReplacingTokens() {
6+
XCTAssertEqual("Dead Beef", "Dead Beef".replacingTokens { _ in "" })
7+
XCTAssertEqual("Food", "F{ref}{ref}d".replacingTokens { _ in "o" })
8+
9+
XCTAssertEqual("Take the left stairs to the 20th floor", "Take the {modifier} stairs to the {nth} floor".replacingTokens { (tokenType) -> String in
10+
switch tokenType {
11+
case .modifier:
12+
return "left"
13+
case .wayPoint:
14+
return "20th"
15+
default:
16+
XCTAssert(false)
17+
return "wrong"
18+
}
19+
})
20+
21+
XCTAssertEqual("{👿}", "{👿}".replacingTokens { _ in "👼" })
22+
XCTAssertEqual("{", "{".replacingTokens { _ in "🕳" })
23+
XCTAssertEqual("{💣", "{💣".replacingTokens { _ in "🕳" })
24+
XCTAssertEqual("}", "}".replacingTokens { _ in "🕳" })
25+
}
26+
}

0 commit comments

Comments
 (0)