File tree Expand file tree Collapse file tree
core/shared/src/main/scala/monocle/std
test/shared/src/test/scala/monocle/std Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,8 +36,10 @@ trait StringOptics extends PlatformSpecificStringOptics {
3636 // we reject cases where String will be an invalid Prism according 2nd Prism law
3737 // * String starts with +
3838 // * String starts with 0 and has multiple digits
39+ // * String starts with -0 (negative zero forms never round-trip)
3940 def inputBreaksPrismLaws (input : String ): Boolean =
40- s.isEmpty || s.startsWith(" +" ) || (s.startsWith(" 0" ) && s.length > 1 )
41+ s.isEmpty || s.startsWith(" +" ) || (s.startsWith(" 0" ) && s.length > 1 ) ||
42+ (s.length > 1 && s.charAt(0 ) == '-' && s.charAt(1 ) == '0' )
4143
4244 if (inputBreaksPrismLaws(s)) None
4345 else
Original file line number Diff line number Diff line change @@ -25,4 +25,17 @@ class StringsSpec extends MonocleSuite {
2525 // checkAll("String to URI", PrismTests(stringToURI))
2626
2727 checkAll(" plated String" , TraversalTests (plate[String ]))
28+
29+ // see #1582: "-0" et al. parsed to 0L but reverseGet round-tripped to "0"
30+ test(" stringToLong rejects negative-zero forms" ) {
31+ assertEquals(stringToLong.getOption(" -0" ), None )
32+ assertEquals(stringToLong.getOption(" -00" ), None )
33+ assertEquals(stringToLong.getOption(" -01" ), None )
34+ }
35+
36+ test(" stringToLong still accepts ordinary negatives and zero" ) {
37+ assertEquals(stringToLong.getOption(" 0" ), Some (0L ))
38+ assertEquals(stringToLong.getOption(" -1" ), Some (- 1L ))
39+ assertEquals(stringToLong.getOption(" -10" ), Some (- 10L ))
40+ }
2841}
You can’t perform that action at this time.
0 commit comments