-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from kasiaMarek/greedy
Make TyRE operators greedy.
- Loading branch information
Showing
5 changed files
with
29 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.* | ||
*.worksheet.sc | ||
!.gitignore | ||
!.scalafmt.conf | ||
!.github/ | ||
|
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
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
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,20 @@ | ||
package net.marek.tyre | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
class GreedyTest extends AnyFunSuite: | ||
|
||
test("Star and option are greedy"): | ||
val ts = tyre"a?a?" | ||
val ms = ts.compile() | ||
assert(ms.run("a").contains((Some('a'), None))) | ||
val t = tyre"ab|[a-z]c" | ||
val tc1 = tyre"$t*$t?" | ||
val mc1 = tc1.compile() | ||
assert(mc1.run("abab").contains((List(('a', 'b'), ('a', 'b')), None))) | ||
val tc2 = tyre"$t*$t*" | ||
val mc2 = tc2.compile() | ||
assert(mc2.run("abab").contains((List(('a', 'b'), ('a', 'b')), Nil))) | ||
val tc3 = tyre"$t?$t*" | ||
val mc3 = tc3.compile() | ||
assert(mc3.run("abab").contains((Some(('a', 'b')), List(('a', 'b'))))) |
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