Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1157 #1184

Merged
merged 1 commit into from Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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