Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 38d1bfe

Browse files
committed
updated Unit Tests for Linux
1 parent 5e17b3a commit 38d1bfe

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

Sources/UnitTests/RegularExpressionTests.swift

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ final class RegularExpressionTests: XCTestCase {
2727
guard let match = regex.match(string, options: [])
2828
else { XCTFail("Could not find match"); return }
2929

30-
let stringRange = NSRange(Range(match.range))
30+
let stringRange = NSRange(match.range)
3131

32-
#if os(Linux)
33-
let matchString = NSString(string: string).substringWithRange(stringRange)
34-
#else
35-
let matchString = NSString(string: string).substring(with: stringRange)
36-
#endif
32+
let matchString = NSString(string: string).substring(with: stringRange)
3733

3834
XCTAssert(matchString == "Welcome")
3935
}
@@ -49,13 +45,9 @@ final class RegularExpressionTests: XCTestCase {
4945
guard let match = regex.match(string, options: [])
5046
else { XCTFail("Could not find match"); return }
5147

52-
let stringRange = NSRange(Range(match.range))
48+
let stringRange = NSRange(match.range)
5349

54-
#if os(Linux)
55-
let matchString = NSString(string: string).substringWithRange(stringRange)
56-
#else
57-
let matchString = NSString(string: string).substring(with: stringRange)
58-
#endif
50+
let matchString = NSString(string: string).substring(with: stringRange)
5951

6052
XCTAssert(matchString == "aaa")
6153
}
@@ -70,13 +62,9 @@ final class RegularExpressionTests: XCTestCase {
7062
guard let match = regex.match(string, options: [])
7163
else { XCTFail("Could not find match"); return }
7264

73-
let stringRange = NSRange(Range(match.range))
65+
let stringRange = NSRange(match.range)
7466

75-
#if os(Linux)
76-
let matchString = NSString(string: string).substringWithRange(stringRange)
77-
#else
78-
let matchString = NSString(string: string).substring(with: stringRange)
79-
#endif
67+
let matchString = NSString(string: string).substring(with: stringRange)
8068

8169
XCTAssert(matchString == "Bird", matchString)
8270
}
@@ -91,13 +79,9 @@ final class RegularExpressionTests: XCTestCase {
9179
guard let match = regex.match(string, options: [])
9280
else { XCTFail("Could not find match"); return }
9381

94-
let stringRange = NSRange(Range(match.range))
82+
let stringRange = NSRange(match.range)
9583

96-
#if os(Linux)
97-
let matchString = NSString(string: string).substringWithRange(stringRange)
98-
#else
99-
let matchString = NSString(string: string).substring(with: stringRange)
100-
#endif
84+
let matchString = NSString(string: string).substring(with: stringRange)
10185

10286
// matched whole string
10387
XCTAssert(matchString == string)
@@ -140,3 +124,15 @@ final class RegularExpressionTests: XCTestCase {
140124
}
141125
}
142126
}
127+
128+
#if os(Linux)
129+
130+
extension NSRange {
131+
132+
init(_ range: Range<Int>) {
133+
134+
self = NSRange(CountableRange(range))
135+
}
136+
}
137+
138+
#endif

0 commit comments

Comments
 (0)