File tree Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,14 @@ package extension XMLParser {
5555 package mutating func scanStringIfPossible( _ token: String ) -> Bool {
5656 return ( try ? self . scanString ( token) ) == true
5757 }
58-
58+
59+ @discardableResult
60+ package mutating func nextScanString( _ token: String ) -> Bool {
61+ scanner. currentIndex = currentIndex
62+ defer { scanner. currentIndex = currentIndex }
63+ return scanStringIfPossible ( token)
64+ }
65+
5966 package mutating func scanString( matchingAny tokens: Set < String > ) throws -> String {
6067 scanner. currentIndex = currentIndex
6168 guard let match = tokens. first ( where: { scanner. scanString ( $0) != nil } ) else {
Original file line number Diff line number Diff line change @@ -110,4 +110,43 @@ final class ParserXMLStyleSheetTests: XCTestCase {
110110 XCTAssertEqual ( sheet [ . class( " b " ) ] ? . fill, . color( . keyword( . blue) ) )
111111 XCTAssertEqual ( sheet [ . element( " rect " ) ] ? . fill, . color( . keyword( . pink) ) )
112112 }
113+
114+ func testMergesSelectors( ) throws {
115+ let entries = try XMLParser . parseEntries (
116+ """
117+ .a {
118+ fill: red;
119+ }
120+ .a {
121+ stroke: blue;
122+ }
123+ .a {
124+ fill: purple;
125+ }
126+ """
127+ )
128+
129+ XCTAssertEqual (
130+ entries,
131+ [ . class( " a " ) : [ " fill " : " purple " , " stroke " : " blue " ] ]
132+ )
133+ }
134+
135+ func testMutlipleSelectors( ) throws {
136+ let entries = try XMLParser . parseEntries (
137+ """
138+ .a, .b {
139+ fill: red;
140+ }
141+ """
142+ )
143+
144+ XCTAssertEqual (
145+ entries,
146+ [
147+ . class( " a " ) : [ " fill " : " red " ] ,
148+ . class( " b " ) : [ " fill " : " red " ]
149+ ]
150+ )
151+ }
113152}
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ struct GalleryView: View {
5252 " yawning.svg " ,
5353 " thats-no-moon.svg " ,
5454 " alert.svg " ,
55- " effigy.svg "
55+ " effigy.svg " ,
56+ " stylesheet-multiple.svg "
5657 ] . compactMap {
5758 SVG ( named: $0, in: . samples)
5859 }
You can’t perform that action at this time.
0 commit comments