/* ----------------------------------------------------------------------------- Copyright 2020-2021,2023 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] testcase "multi return to call" { error require "call.+Value.+Value" } @value interface Value { get () -> (Value, Value) call () -> () } define Test { @value process (Value) -> () process (value) { \ value.get().call() } } concrete Test { } testcase "zero return to call" { error require "call.+none" } @value interface Value { get () -> () call () -> () } define Test { @value process (Value) -> () process (value) { \ value.get().call() } } concrete Test { } testcase "multi return assign" { success } unittest test { Test value <- Test.create() _, Test value2 <- value.double() value, _ <- value2.double() } concrete Test { @type create () -> (Test) @value double () -> (Test, Test) } define Test { create () { return Test{} } double () { return self, self } } testcase "multi return as args" { success } unittest test { \ Test.call(Test.get()) } define Test { get () { return 1, 2 } call (x, y) { if (x != 1) { fail("Failed") } if (y != 2) { fail("Failed") } } } concrete Test { @type get () -> (Int, Int) @type call (Int, Int) -> () } testcase "multi return as args with params" { success } unittest testExplicit { \ Test.call(Test.get()) } unittest testInferred { \ Test.call(Test.get()) } define Test { get () { return 1, 2 } call (x, y) { if (!(x `#x.lessThan` y)) { fail("Failed") } } } concrete Test { @type get () -> (Int, Int) @type call<#x> #x defines LessThan<#x> (#x, #x) -> () } testcase "return selection" { success } unittest correctPosition { \ Testing.checkEquals(Test.get(){0}, 123) \ Testing.checkEquals(Test.get(){1}, "message") } unittest chainedCall { \ Testing.checkEquals(Test.get(){0}.formatted(), "123") } concrete Test { @type get () -> (Int, String) } define Test { get () { return 123, "message" } } testcase "bad return-selection index" { error require "100" } unittest test { \ Test.get(){100} } concrete Test { @type get () -> (Int, String) } define Test { get () { return 123, "message" } } testcase "cannot select return from literal" { error require "selection" } unittest test { \ "message"{0} } testcase "cannot select return from boxed variable" { error require "selection" } unittest test { String value <- "message" \ value{0} } testcase "cannot select return from unboxed variable" { error require "selection" } unittest test { Int value <- 123 \ value{0} } testcase "cannot double select" { error require "selection" exclude "123" } unittest test { \ "message".formatted(){0}{123} }