Skip to content

Commit 833af42

Browse files
authored
Merge pull request #5 from jasl/octwu/fix_crash_case
fix crash test case
2 parents c3cd019 + 95cdaf9 commit 833af42

File tree

8 files changed

+19
-46
lines changed

8 files changed

+19
-46
lines changed

RouterX.xcodeproj/project.pbxproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
OBJ_63 /* RoutingPatternParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_23 /* RoutingPatternParserTests.swift */; };
3737
OBJ_64 /* RoutingPatternScannerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_24 /* RoutingPatternScannerTests.swift */; };
3838
OBJ_65 /* URLPathScannerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_25 /* URLPathScannerTests.swift */; };
39-
OBJ_66 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_26 /* XCTestManifests.swift */; };
4039
OBJ_68 /* RouterX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "RouterX::RouterX::Product" /* RouterX.framework */; };
4140
/* End PBXBuildFile section */
4241

@@ -71,7 +70,6 @@
7170
OBJ_23 /* RoutingPatternParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutingPatternParserTests.swift; sourceTree = "<group>"; };
7271
OBJ_24 /* RoutingPatternScannerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutingPatternScannerTests.swift; sourceTree = "<group>"; };
7372
OBJ_25 /* URLPathScannerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLPathScannerTests.swift; sourceTree = "<group>"; };
74-
OBJ_26 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = "<group>"; };
7573
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
7674
OBJ_9 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
7775
"RouterX::RouterX::Product" /* RouterX.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RouterX.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -114,7 +112,6 @@
114112
OBJ_23 /* RoutingPatternParserTests.swift */,
115113
OBJ_24 /* RoutingPatternScannerTests.swift */,
116114
OBJ_25 /* URLPathScannerTests.swift */,
117-
OBJ_26 /* XCTestManifests.swift */,
118115
);
119116
name = RouterXTests;
120117
path = Tests/RouterXTests;
@@ -137,15 +134,14 @@
137134
name = Products;
138135
sourceTree = BUILT_PRODUCTS_DIR;
139136
};
140-
OBJ_5 /* */ = {
137+
OBJ_5 = {
141138
isa = PBXGroup;
142139
children = (
143140
OBJ_6 /* Package.swift */,
144141
OBJ_7 /* Sources */,
145142
OBJ_17 /* Tests */,
146143
OBJ_27 /* Products */,
147144
);
148-
name = "";
149145
sourceTree = "<group>";
150146
};
151147
OBJ_7 /* Sources */ = {
@@ -237,7 +233,7 @@
237233
knownRegions = (
238234
en,
239235
);
240-
mainGroup = OBJ_5 /* */;
236+
mainGroup = OBJ_5;
241237
productRefGroup = OBJ_27 /* Products */;
242238
projectDirPath = "";
243239
projectRoot = "";
@@ -284,7 +280,6 @@
284280
OBJ_63 /* RoutingPatternParserTests.swift in Sources */,
285281
OBJ_64 /* RoutingPatternScannerTests.swift in Sources */,
286282
OBJ_65 /* URLPathScannerTests.swift in Sources */,
287-
OBJ_66 /* XCTestManifests.swift in Sources */,
288283
);
289284
runOnlyForDeploymentPostprocessing = 0;
290285
};

Sources/RouterX/RouterXCore.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ open class RouterXCore {
5252
return nil
5353
}
5454
}
55+
56+
guard let pathPatternIdentifier = targetRoute.patternIdentifier else { return nil }
5557

56-
return MatchedRoute(url: url, parameters: parameters, patternIdentifier: targetRoute.patternIdentifier!)
58+
return MatchedRoute(url: url, parameters: parameters, patternIdentifier: pathPatternIdentifier)
5759
}
5860

5961
open func matchURLPath(_ urlPath: String) -> MatchedRoute? {

Tests/RouterXTests/RouterTests.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,19 @@ final class RouterTests: XCTestCase {
3535
isUnmatchHandlerPerformed = true
3636
}))
3737
XCTAssertTrue(isUnmatchHandlerPerformed)
38-
}
3938

40-
static var allTests = [
41-
("testIntegration", testIntegration)
42-
]
39+
let pattern2 = "/band/:band_id/product"
40+
let pattern2Case1 = "/band/20/product"
41+
let pattern2Case2 = "/band/21"
42+
let pattern2Case3 = "/band"
43+
44+
XCTAssertTrue(router.register(pattern: pattern2, handler: { _, parameters, _ in
45+
XCTAssertEqual(parameters["band_id"], "20")
46+
XCTAssertEqual(parameters.count, 1)
47+
}))
48+
49+
XCTAssertTrue(router.match(urlPath: pattern2Case1))
50+
XCTAssertFalse(router.match(urlPath: pattern2Case2))
51+
XCTAssertFalse(router.match(urlPath: pattern2Case3))
52+
}
4353
}

Tests/RouterXTests/RouterXCoreTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,4 @@ final class RouterXCoreTests: XCTestCase {
2626

2727
XCTAssertNil(router.matchURL(unmatchedCase as URL))
2828
}
29-
30-
static var allTests = [
31-
("testIntegration", testIntegration)
32-
]
3329
}

Tests/RouterXTests/RoutingPatternParserTests.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import XCTest
55
final class RoutingPatternParserTests: XCTestCase {
66
let patternIdentifier: RouterX.PatternIdentifier = 1
77

8-
static var allTests = [
9-
("testParsingFailureShouldThrowError", testParsingFailureShouldThrowError),
10-
("testParseSlash", testParseSlash),
11-
("testParseDot", testParseDot),
12-
("testParseLiteral", testParseLiteral),
13-
("testParseSymbol", testParseSymbol),
14-
("testStar", testStar),
15-
("testParseLParen", testParseLParen)
16-
]
17-
188
func testParsingFailureShouldThrowError() {
199
let badTokens: [RoutingPatternToken] = [.rParen, .literal("bad")]
2010
let route = RouteVertex()

Tests/RouterXTests/RoutingPatternScannerTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import XCTest
33
@testable import RouterX
44

55
final class RoutingPatternScannerTests: XCTestCase {
6-
static var allTests = [
7-
("testScanner", testScanner),
8-
("testRoundTrip", testRoundTrip)
9-
]
106

117
func testScanner() {
128
let cases: [String: Array<RoutingPatternToken>] = [

Tests/RouterXTests/URLPathScannerTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import XCTest
33
@testable import RouterX
44

55
class URLPathScannerTests: XCTestCase {
6-
static var allTests = [
7-
("testScanner", testScanner)
8-
]
96

107
func testScanner() {
118
let cases: [String: Array<URLPathToken>] = [

Tests/RouterXTests/XCTestManifests.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)