-
Notifications
You must be signed in to change notification settings - Fork 5
/
RegexShrinkTests.scala
72 lines (62 loc) · 2.07 KB
/
RegexShrinkTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package ceedubs.irrec
package regex
import cats.Eq
import cats.tests.CatsSuite
import org.scalacheck.Shrink, Shrink.shrink
class RegexShrinkTests extends CatsSuite {
// this is pretty hacky but I haven't yet written a meaningful equality for regexes.
implicit private val eqIntRegex: Eq[Regex[Int]] = Eq.fromUniversalEquals
implicit val shrinkIntRegex: Shrink[Regex[Int]] = RegexShrink.shrinkForRegex
test("shrinking a literal") {
val r: Regex[Int] = Regex.lit(2)
val expected = List(Regex.lit(1), Regex.lit(-1), Regex.lit(0))
shrink(r).toList should ===(expected)
}
test("shrinking a wildcard") {
val r: Regex[Int] = Regex.wildcard[Int]
val expected = List.empty[Regex[Int]]
shrink(r).toList should ===(expected)
}
test("shrinking a range") {
val r: Regex[Int] = Regex.range(1, 2)
val expected = List(Regex.range(0, 2), Regex.range(1, 1), Regex.range(1, -1), Regex.range(1, 0))
shrink(r).toList should ===(expected)
}
test("shrinking a plus") {
val r: Regex[Int] = Regex.lit(1) | Regex.lit(1)
val expected = List(
// shrinking left
Regex.lit(0),
// shrinking right
Regex.lit(0),
// shrinking both
Regex.lit(0) | Regex.lit(0))
shrink(r).toList should ===(expected)
}
test("shrinking a times") {
val r: Regex[Int] = Regex.lit(1) * Regex.lit(1)
val expected = List(
// shrinking left
Regex.lit(0),
// shrinking right
Regex.lit(0),
// shrinking both
Regex.lit(0) * Regex.lit(0))
shrink(r).toList should ===(expected)
}
test("shrinking a * should shrink the inner regex") {
val r: Regex[Int] = Regex.lit(2).star
val expected = List(Regex.lit(1), Regex.lit(-1), Regex.lit(0))
shrink(r).toList should ===(expected)
}
test("zero cannot be shrunk") {
val r: Regex[Int] = Regex.impossible
val expected = List.empty[Regex[Int]]
shrink(r).toList should ===(expected)
}
test("one cannot be shrunk") {
val r: Regex[Int] = Regex.empty
val expected = List.empty[Regex[Int]]
shrink(r).toList should ===(expected)
}
}