-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3631: Regex now handles OR alternatives with more than two claus…
…es (#3642)
- Loading branch information
1 parent
d16127a
commit d152d67
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
unit-tests/shared/src/test/scala-3/scala/issues/RegexIssuesTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package scala.issues | ||
|
||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
class RegexIssuesTest: | ||
|
||
/* Issue 3631 describes a parse failue in a complicated regex. | ||
* To increase confidence, the Test should stay as close as feasible | ||
* to the original report. | ||
* | ||
* The complication is that Scala 2.12 regex class does not have | ||
* the "matches" method used in the Issue. That method was introduced | ||
* in Scala 2.13. | ||
* | ||
* To reduce duplication & confusion, this Test is run only on Scala 3. | ||
* | ||
* This test should be run on both Scala and JVM to ensure that the regex | ||
* from the Issue continues to parse on the latter. | ||
*/ | ||
|
||
@Test def test_Issue3631(): Unit = { | ||
// Use the full regex from the Issue, which is _not_ the minimal reproducer. | ||
val pattern = "^(\\-|\\+)?(0\\.[0-9]+|[1-9][0-9]*\\.[0-9]+|[1-9][0-9]*|0)$" | ||
val expected = "1" | ||
|
||
assertTrue( | ||
s"regex '${pattern}' does not match '${expected}'", | ||
pattern.r.matches(expected) | ||
) | ||
} | ||
|
||
end RegexIssuesTest |