Skip to content

Commit

Permalink
fix the law checking
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Dec 11, 2024
1 parent cedb092 commit afb5fb9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/test/scala/org/bykn/bosatsu/PatternTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalatest.funsuite.AnyFunSuite

class PatternTest extends AnyFunSuite {
implicit val generatorDrivenConfig: PropertyCheckConfiguration =
PropertyCheckConfiguration(minSuccessful = 1000)
PropertyCheckConfiguration(minSuccessful = 5000)

val patGen = Gen.choose(0, 5).flatMap(Generators.genPattern(_))

Expand Down Expand Up @@ -160,8 +160,27 @@ class PatternTest extends AnyFunSuite {
}

test("substitute names homomorphism") {
import Identifier._

def law[A, B](p: Pattern[A, B], map: Map[Bindable, Bindable]) = {
val subsP = p.substitute(map)
assert(subsP.names.distinct == p.names.map(n => map.getOrElse(n, n)).distinct, s"got $subsP")
}

def b(s: String) = Identifier.Name(s)

{
import Pattern._
import StrPart._
import Lit.Str

val p = Union(Var(Name("a")), NonEmptyList(StrPat(NonEmptyList(NamedStr(Name("k")), List(LitStr("wrk"), WildChar))), List(Named(Name("hqZ9aeuAood"), WildCard), Literal(Str("q5VgEdksu")), WildCard)))

law(p, Map(b("k") -> b("a")))
}

forAll(patGen, Gen.mapOf(Gen.zip(Generators.bindIdentGen, Generators.bindIdentGen))) { (p, map) =>
assert(p.substitute(map).names == p.names.map(n => map.getOrElse(n, n)))
law(p, map)
}
}
}

0 comments on commit afb5fb9

Please sign in to comment.