Skip to content

Commit

Permalink
Fix 1157 (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek authored Mar 24, 2024
1 parent 0fd27df commit acd149a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class StringSeqPatternSetLaws extends SetOpsLaws[SeqPattern[Char]] {
Pattern.fromList(p.toList.take(4)).normalize
}

lazy val allStrings: LazyList[String] =
// we only use 0/1 strings in Lit, but AnyElem can match others
"" #:: (for {
t <- allStrings // it's important to put this first
h <- LazyList('0', '1', '2')
} yield s"$h$t")

val pmatcher = Pattern.stringUnitMatcher

def matches(p: Pattern, s: String): Boolean = pmatcher(p)(s).isDefined
Expand All @@ -33,13 +40,14 @@ class StringSeqPatternSetLaws extends SetOpsLaws[SeqPattern[Char]] {
.listOfN(
5000,
Gen.frequency(
10 -> StringSeqPatternGen.genBitString,
5 -> StringSeqPatternGen.genBitString,
1 -> Gen.listOf(Gen.oneOf(List('0', '1', '2'))).map(_.mkString)
)
)
.map { tests =>
.map { tests0 =>
// we have to generate more than just 01 strings,
// since Any can match more than that
val tests = tests0 ::: allStrings.take(10000).toList
new Eq[List[Pattern]] {
// this can flake because if two things are different,
// but happen to have the same match results for this
Expand All @@ -53,6 +61,8 @@ class StringSeqPatternSetLaws extends SetOpsLaws[SeqPattern[Char]] {
a.exists(matches(_, s)) == b.exists(matches(_, s))
}
}

override def toString = s"Eq via tests = $tests"
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/org/bykn/bosatsu/set/SetOpsLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ abstract class SetOpsLaws[A] extends munit.ScalaCheckSuite {
val diffA = setOps.difference(a, b)
val diffB = setOps.difference(b, a)

assert(!eqv.eqv(intr, a :: Nil))
assert(!eqv.eqv(intr, a :: Nil), s"intr = $intr")
assert(!eqv.eqv(intr, b :: Nil), s"intr = $intr")
assert(!eqv.eqv(a :: Nil, b :: Nil))
assert(intr.nonEmpty, s"a = $a, b = $b , intr = $intr")
Expand Down

0 comments on commit acd149a

Please sign in to comment.