diff --git a/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala b/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala index 67e4570ad..4cb790056 100644 --- a/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala +++ b/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala @@ -13,6 +13,8 @@ abstract class JSBackendDiffMaker extends MLsDiffMaker: val sjs = NullaryCommand("sjs") val showRepl = NullaryCommand("showRepl") val silent = NullaryCommand("silent") + val expect = Command("expect"): ln => + ln.trim private val baseScp: codegen.js.Scope = codegen.js.Scope.empty @@ -61,6 +63,7 @@ abstract class JSBackendDiffMaker extends MLsDiffMaker: output(s"JS:") output(jsStr) def mkQuery(prefix: Str, jsStr: Str) = + import hkmc2.Message.MessageContext val queryStr = jsStr.replaceAll("\n", " ") val (reply, stderr) = host.query(queryStr, expectRuntimeErrors.isUnset && fixme.isUnset && todo.isUnset) reply match @@ -73,11 +76,15 @@ abstract class JSBackendDiffMaker extends MLsDiffMaker: output(s"> ${line}") content match case "undefined" => - case _ => output(s"$prefix= ${content}") + case _ => + expect.get match + case S(expected) if content != expected => raise: + ErrorReport(msg"Expected: ${expected}, got: ${content}" -> N :: Nil, + source = Diagnostic.Source.Runtime) + case _ => output(s"$prefix= ${content}") case ReplHost.Empty => case ReplHost.Unexecuted(message) => ??? case ReplHost.Error(isSyntaxError, message) => - import hkmc2.Message.MessageContext if (isSyntaxError) then // If there is a syntax error in the generated code, // it should be a code generation error. diff --git a/hkmc2/shared/src/test/mlscript/ucs/general/DualOptions.mls b/hkmc2/shared/src/test/mlscript/ucs/general/DualOptions.mls index a8f6f0e4b..fbf736498 100644 --- a/hkmc2/shared/src/test/mlscript/ucs/general/DualOptions.mls +++ b/hkmc2/shared/src/test/mlscript/ucs/general/DualOptions.mls @@ -10,6 +10,7 @@ class Some[T](value: T) extends Option[T] module None extends Option[nothing] class Pair[A, B](x: A, y: B) +// All `add_n` functions should be inferred to have the same type. fun add_1(x, y) = if @@ -95,25 +96,25 @@ fun add_4(x, y) = :fixme add_4(None, None) //│ ╔══[ERROR] Name not found: add_4 -//│ ║ l.96: add_4(None, None) +//│ ║ l.97: add_4(None, None) //│ ╙── ^^^^^ :fixme add_4(Some(5), None) //│ ╔══[ERROR] Name not found: add_4 -//│ ║ l.102: add_4(Some(5), None) +//│ ║ l.103: add_4(Some(5), None) //│ ╙── ^^^^^ :fixme add_4(None, Some(9)) //│ ╔══[ERROR] Name not found: add_4 -//│ ║ l.108: add_4(None, Some(9)) +//│ ║ l.109: add_4(None, Some(9)) //│ ╙── ^^^^^ :fixme add_4(Some(5), Some(9)) //│ ╔══[ERROR] Name not found: add_4 -//│ ║ l.114: add_4(Some(5), Some(9)) +//│ ║ l.115: add_4(Some(5), Some(9)) //│ ╙── ^^^^^ @@ -158,6 +159,7 @@ add_6(Some(5), Some(9)) //│ = 14 +// Functions from now on have a predicate `p` that can be used to add some preconditions. fun add_6(p, x, y) = @@ -169,15 +171,23 @@ fun add_6(p, x, y) = y is None and x is None then 0 +:expect 0 add_6((x) => true, None, None) //│ = 0 +:expect 42 add_6((x) => true, Some(5), None) //│ = 42 +:expect 5 +add_6((x) => false, Some(5), None) +//│ = 5 + +:expect 9 add_6((x) => true, None, Some(9)) //│ = 9 +:expect 14 add_6((x) => true, Some(5), Some(9)) //│ = 14 @@ -192,18 +202,23 @@ fun add_7(p, x, y) = y is None and x is None then 0 +:expect 0 add_7((x) => x > 0, None, None) //│ = 0 +:expect 5 add_7((x) => x > 0, Some(5), None) //│ = 5 +:expect 36 add_7((x) => x > 0, None, Some(9)) //│ = 36 +:expect -9 add_7((x) => x > 0, None, Some(-9)) //│ = -9 +:expect 14 add_7((x) => x > 0, Some(5), Some(9)) //│ = 14 @@ -218,21 +233,27 @@ fun add_8(p, x, y) = y is None and x is None then 0 +:expect 0 add_8((x) => x > 0, None, None) //│ = 0 +:expect 42 add_8((x) => true, Some(9), None) //│ = 42 +:expect 5 add_8((x) => x > 0, Some(5), None) //│ = 5 +:expect 36 add_8((x) => x > 0, None, Some(9)) //│ = 36 +:expect -9 add_8((x) => x > 0, None, Some(-9)) //│ = -9 +:expect 14 add_8((x) => x > 0, Some(5), Some(9)) //│ = 14