Better tests for environment handling. (#6047)

Have tests which will fail if we screw up the indexing for any of:
- function application args
- the stack (let bindings)
- free-variables of a closure

In particular if we mix up the direction of out indexing. i.e. 0..n-1 VS n-1..0

Try to make the three tests as selective as possible, by only failing for the one aspect they are designed to test.

changelog_begin
changelog_end
This commit is contained in:
nickchapman-da 2020-05-20 15:41:56 +01:00 committed by GitHub
parent 38f23dd08b
commit c72daadba3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,20 +24,44 @@ class SpeedyTest extends WordSpec with Matchers {
import SpeedyTest._
import defaultParserParameters.{defaultPackageId => pkgId}
"free variables" should {
val pkgs = typeAndCompile(p"")
val pkgs = typeAndCompile(p"")
"application arguments" should {
"be handled correctly" in {
eval(
e"""
(\ (a: Int64) (b: Int64) -> SUB_INT64 a b) 88 33
""",
pkgs
// Test should fail if we get the order of the function arguments wrong.
) shouldEqual Right(SInt64(55))
}
}
"be captured correctly" in {
"stack variables" should {
"be handled correctly" in {
eval(
e"""
let a : Int64 = 88 in
let b : Int64 = 33 in
(\ (x: Unit) -> SUB_INT64 a b) ()
SUB_INT64 a b
""",
pkgs
// If the get the order of the free variables wrong, this test should fail because
// the subtraction performed will be (33-88) and so result in (-55).
// Test should fail if we access the stack with incorrect indexing.
) shouldEqual Right(SInt64(55))
}
}
"free variables" should {
"be handled correctly" in {
eval(
e"""
(\(a : Int64) ->
let b : Int64 = 33 in
(\ (x: Unit) -> SUB_INT64 a b) ()) 88
""",
pkgs
// Test should fail if we index free-variables of a closure incorrectly.
) shouldEqual Right(SInt64(55))
}
}