@@ -72,14 +72,13 @@ class ConcatenationTests: XCTestCase {
72
72
XCTAssert ( type ( of: Literal ( " q " . utf8) • Capture ( ) ) . Input == String . UTF8View. self)
73
73
}
74
74
75
- /*
76
- func testRepeatOrThenEndOfLine() throws {
77
- assertParseAll(
78
- Capture((alphanumeric / OneOf(" "))+ • Line.end),
79
- input: "FMA026712 TECNOAUTOMOTRIZ ATLACOMULCO S",
80
- result: ["FMA026712 TECNOAUTOMOTRIZ ATLACOMULCO S"])
81
- }
82
- */
75
+ func testRepeatOrThenEndOfLine( ) throws {
76
+ assertParseAll (
77
+ Capture ( ( alphanumeric / OneOf( " " ) ) + • Line. end) ,
78
+ input: " FMA026712 TECNOAUTOMOTRIZ ATLACOMULCO S " ,
79
+ result: [ " FMA026712 TECNOAUTOMOTRIZ ATLACOMULCO S " ] )
80
+ }
81
+
83
82
func testMatchFullRange( ) throws {
84
83
let text = """
85
84
line 1
@@ -156,71 +155,58 @@ class ConcatenationTests: XCTestCase {
156
155
0005..0010 ; Common # Cc [32] <control-0000>..<control-001F>
157
156
002F ; Common # Zs SPACE
158
157
"""
159
- /*
160
- lazy var rangeAndProperty: Parser<String> = {
161
- let hexNumber = Capture(name: "codePoint", hexDigit+)
162
- let hexRange = AnyPattern("\(hexNumber)..\(hexNumber)") / hexNumber
163
- return try! Parser(search: AnyPattern("\n\(hexRange • Skip()); \(Capture(name: "property", Skip())) "))
164
- }()
165
-
166
- func testStringInterpolation() throws {
167
- assertCaptures(rangeAndProperty, input: text, result: [["0005", "0010", "Common"], ["002F", "Common"]])
168
- }
169
-
170
- func testMatchDecoding() throws {
171
- struct Property: Decodable, Equatable {
172
- let codePoint: [Int]
173
- let property: String
174
- let notCaptured: String?
175
- }
176
-
177
- let matches = Array(rangeAndProperty.matches(in: text))
178
- let property = try matches.first!.decode(Property.self, from: text)
179
- XCTAssertEqual(property, Property(codePoint: [5, 10], property: "Common", notCaptured: nil))
180
-
181
- XCTAssertThrowsError(try matches.last!.decode(Property.self, from: text))
182
- }
183
-
184
- func testParserDecoding() {
185
- struct Property: Decodable, Equatable {
186
- let codePoint: [String]
187
- let property: String
188
- }
189
-
190
- XCTAssertEqual(try rangeAndProperty.decode([Property].self, from: text),
191
- [Property(codePoint: ["0005", "0010"], property: "Common"),
192
- Property(codePoint: ["002F"], property: "Common")])
193
- XCTAssertEqual(try rangeAndProperty.decodeFirst(Property.self, from: text),
194
- Property(codePoint: ["0005", "0010"], property: "Common"))
195
- }
196
- */
197
- func testReadmeExample( ) throws {
198
- let text = " This is a point: (43,7), so is (0,5). But my final point is (3,-1). "
199
158
200
- let number = OneOf ( " +- " ) ¿ • digit+
201
- let point = try Parser ( search: AnyPattern ( " ( \( Capture ( name: " x " , number) ) , \( Capture ( name: " y " , number) ) ) " ) )
159
+ lazy var rangeAndProperty : Parser < String > = {
160
+ let hexNumber = Capture ( name: " codePoint " , hexDigit+ )
161
+ let hexRange = AnyPattern ( " \( hexNumber) .. \( hexNumber) " ) / hexNumber
162
+ return try ! Parser ( search: AnyPattern ( " \n \( hexRange • Skip ( ) ) ; \( Capture ( name: " property " , Skip ( ) ) ) " ) )
163
+ } ( )
202
164
203
- let pointsAsSubstrings = point. matches ( in: text) . map { match in
204
- ( text [ match [ one: " x " ] !] , text [ match [ one: " y " ] !] )
165
+ func testStringInterpolation( ) throws {
166
+ assertCaptures ( rangeAndProperty, input: text, result: [ [ " 0005 " , " 0010 " , " Common " ] , [ " 002F " , " Common " ] ] )
167
+ }
168
+
169
+ func testMatchDecoding( ) throws {
170
+ struct Property : Decodable , Equatable {
171
+ let codePoint : [ Int ]
172
+ let property : String
173
+ let notCaptured : String ?
205
174
}
206
175
176
+ let matches = Array ( rangeAndProperty. matches ( in: text) )
177
+ let property = try matches. first!. decode ( Property . self, from: text)
178
+ XCTAssertEqual ( property, Property ( codePoint: [ 5 , 10 ] , property: " Common " , notCaptured: nil ) )
179
+
180
+ XCTAssertThrowsError ( try matches. last!. decode ( Property . self, from: text) )
181
+ }
182
+
183
+ func testParserDecoding( ) {
184
+ struct Property : Decodable , Equatable {
185
+ let codePoint : [ String ]
186
+ let property : String
187
+ }
188
+
189
+ XCTAssertEqual ( try rangeAndProperty. decode ( [ Property ] . self, from: text) ,
190
+ [ Property ( codePoint: [ " 0005 " , " 0010 " ] , property: " Common " ) ,
191
+ Property ( codePoint: [ " 002F " ] , property: " Common " ) ] )
192
+ XCTAssertEqual ( try rangeAndProperty. decodeFirst ( Property . self, from: text) ,
193
+ Property ( codePoint: [ " 0005 " , " 0010 " ] , property: " Common " ) )
194
+ }
195
+
196
+ func testReadmeExample( ) throws {
197
+ let text = " This is a point: (43,7), so is (0, 5). But my final point is (3,-1). "
198
+
199
+ let number = ( " + " / " - " / " " ) • digit+
200
+ let point = " ( " • Capture ( name: " x " , number)
201
+ • " , " • " " ¿ • Capture( name: " y " , number) • " ) "
202
+
207
203
struct Point : Codable , Equatable {
208
204
let x , y : Int
209
205
}
210
206
211
- let points = try point. decode ( [ Point ] . self, from: text)
207
+ let points = try Parser ( search: point) . decode ( [ Point ] . self, from: text)
208
+ XCTAssertEqual ( points, [ Point ( x: 43 , y: 7 ) , Point ( x: 0 , y: 5 ) , Point ( x: 3 , y: - 1 ) ] )
212
209
213
210
assertCaptures ( point, input: text, result: [ [ " 43 " , " 7 " ] , [ " 0 " , " 5 " ] , [ " 3 " , " -1 " ] ] )
214
- _ = ( pointsAsSubstrings, points)
215
211
}
216
-
217
- /*
218
- func testOperatorPrecedence() throws {
219
- let p1 = "a" • Skip() • letter • !alphanumeric • "b"+
220
- XCTAssert(type(of: p1.first.first.first.second) == Skip.self)
221
- XCTAssert(type(of: "a" • "b" / "c" • "d")
222
- == OrPattern<Concat<Literal, Literal>, Concat<Literal, Literal>>.self,
223
- #"`/` should have lower precedence than `•`"#)
224
- }
225
- */
226
212
}
0 commit comments