Skip to content

Commit 9e87268

Browse files
committed
Test token replacement
1 parent 68e93da commit 9e87268

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

OSRMTextInstructions.xcodeproj/project.pbxproj

Lines changed: 10 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 */; };
@@ -76,6 +79,7 @@
7679
35EBDB5D1E5E1572006EB3CD /* OSRMTextInstructions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OSRMTextInstructions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7780
C51B63E81E65FA04002F4634 /* TokenType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenType.swift; sourceTree = "<group>"; };
7881
DA2DFB3B1E8373AF00CEEBE9 /* json2plist.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = json2plist.sh; sourceTree = "<group>"; };
82+
DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenTests.swift; sourceTree = SOURCE_ROOT; };
7983
DA5F58931E85A32C00BA4D0A /* OSRMTextInstructions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OSRMTextInstructions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8084
DA5F589B1E85A32C00BA4D0A /* OSRMTextInstructionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OSRMTextInstructionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
8185
DA5F58B61E85B24E00BA4D0A /* MapboxDirections.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapboxDirections.framework; path = Carthage/Build/Mac/MapboxDirections.framework; sourceTree = "<group>"; };
@@ -172,8 +176,9 @@
172176
352BBC2A1E5E4D4200703DF1 /* OSRMTextInstructionsTests */ = {
173177
isa = PBXGroup;
174178
children = (
175-
352BBC2B1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift */,
176179
352BBC2D1E5E4D4200703DF1 /* Info.plist */,
180+
352BBC2B1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift */,
181+
DA5F02771F6CBAAF0040C4AD /* TokenTests.swift */,
177182
);
178183
path = OSRMTextInstructionsTests;
179184
sourceTree = "<group>";
@@ -628,6 +633,7 @@
628633
isa = PBXSourcesBuildPhase;
629634
buildActionMask = 2147483647;
630635
files = (
636+
DA5F02781F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
631637
352BBC2C1E5E4D4200703DF1 /* OSRMTextInstructionsTests.swift in Sources */,
632638
);
633639
runOnlyForDeploymentPostprocessing = 0;
@@ -654,6 +660,7 @@
654660
isa = PBXSourcesBuildPhase;
655661
buildActionMask = 2147483647;
656662
files = (
663+
DA5F02791F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
657664
DA5F58AE1E85B0AE00BA4D0A /* OSRMTextInstructionsTests.swift in Sources */,
658665
);
659666
runOnlyForDeploymentPostprocessing = 0;
@@ -671,6 +678,7 @@
671678
isa = PBXSourcesBuildPhase;
672679
buildActionMask = 2147483647;
673680
files = (
681+
DA5F027A1F6CBAAF0040C4AD /* TokenTests.swift in Sources */,
674682
DA5F58E61E85BE1900BA4D0A /* OSRMTextInstructionsTests.swift in Sources */,
675683
);
676684
runOnlyForDeploymentPostprocessing = 0;
@@ -1198,6 +1206,7 @@
11981206
DA5F58FB1E85C13700BA4D0A /* Release */,
11991207
);
12001208
defaultConfigurationIsVisible = 0;
1209+
defaultConfigurationName = Release;
12011210
};
12021211
/* End XCConfigurationList section */
12031212
};

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)