File tree Expand file tree Collapse file tree 4 files changed +30
-4
lines changed
main/java/com/mirkoddd/sift
test/java/com/mirkoddd/sift Expand file tree Collapse file tree 4 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ String priceRegex = anywhere()
7070 )
7171 .shake();
7272
73- // Result: Cost: \$[0-9]+(?:(?:\\ .[0-9]{2}) )?
73+ // Result: Cost: \$[0-9]+(?:\ .[0-9]{2})?
7474```
7575
7676## API Overview
Original file line number Diff line number Diff line change 11allprojects {
22 group = ' com.mirkoddd'
3- version = ' 1.1.0 '
3+ version = ' 1.1.1 '
44
55 repositories {
66 mavenCentral()
Original file line number Diff line number Diff line change @@ -107,12 +107,12 @@ public ConnectorStep any() {
107107 // --- CONNECTORS ---
108108 @ Override
109109 public ConnectorStep withOptional (SiftPattern pattern ) {
110- return this .optional ().followedBy (pattern );
110+ return this .followedBy (). optional ().followedBy (pattern );
111111 }
112112
113113 @ Override
114114 public ConnectorStep withOptional (char character ) {
115- return this .optional ().followedBy (character );
115+ return this .followedBy (). optional ().followedBy (character );
116116 }
117117
118118 @ Override
Original file line number Diff line number Diff line change @@ -334,4 +334,30 @@ void wordBoundaries() {
334334 assertRegexDoesNotMatch (regex , "scatter" );
335335 }
336336 }
337+
338+ @ Test
339+ @ DisplayName ("Bugfix: withOptional syntactic sugar should not overwrite previous quantifiers" )
340+ void syntacticSugarQuantifierBug () {
341+ String regex = anywhere ()
342+ .oneOrMore ().digits ()
343+ .withOptional (literal ("A" ))
344+ .shake ();
345+
346+ // before fix: [0-9]?(?:A)?
347+ assertEquals ("[0-9]+(?:A)?" , regex );
348+
349+ //from README.md
350+ String priceRegex = anywhere ()
351+ .followedBy (literal ("Cost: $" ))
352+ .followedBy ().oneOrMore ().digits ()
353+ .withOptional (
354+ anywhere ().followedBy ('.' ).followedBy ().exactly (2 ).digits ()
355+ )
356+ .shake ();
357+
358+
359+ assertEquals ("Cost: \\ $[0-9]+(?:\\ .[0-9]{2})?" , priceRegex );
360+ assertRegexMatches (priceRegex , "Cost: $10" );
361+ assertRegexMatches (priceRegex , "Cost: $10.99" );
362+ }
337363}
You can’t perform that action at this time.
0 commit comments