/* ----------------------------------------------------------------------------- Copyright 2019-2021 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 "Argv checks" { success args "arg1" "arg2" "arg3" "arg4" } unittest global { Int count <- Argv.global().size() \ Testing.checkEquals(count,5) \ Testing.checkEquals(Argv.global().readAt(0),"testcase") \ Testing.checkEquals(Argv.global().readAt(1),"arg1") \ Testing.checkEquals(Argv.global().readAt(2),"arg2") \ Testing.checkEquals(Argv.global().readAt(3),"arg3") \ Testing.checkEquals(Argv.global().readAt(4),"arg4") } unittest subSequence { ReadAt argv <- Argv.global().subSequence(2,2) Int count <- argv.size() \ Testing.checkEquals(count,2) \ Testing.checkEquals(argv.readAt(0),"arg2") \ Testing.checkEquals(argv.readAt(1),"arg3") } testcase "Argv readAt out of bounds" { crash require "index 5" } unittest test { \ Argv.global().readAt(5) } testcase "Argv subSequence out of bounds" { crash require "index 5" } unittest test { \ Argv.global().subSequence(5,1) } testcase "ErrorOr checks" { success } unittest withValue { ErrorOr value <- ErrorOr:value(10) \ Testing.checkEquals(value.isError(),false) \ Testing.checkEquals(value.getValue(),10) } unittest withError { ErrorOr value <- ErrorOr:error("error message") \ Testing.checkEquals(value.isError(),true) \ Testing.checkEquals(value.getError().formatted(),"error message") } unittest convertError { scoped { ErrorOr error <- ErrorOr:error("error message") } in ErrorOr value <- error.convertError() \ Testing.checkEquals(value.getError().formatted(),"error message") } testcase "ErrorOr getError() crashes with value" { crash require "empty" } unittest test { ErrorOr value <- ErrorOr:value(10) \ value.getError() } testcase "ErrorOr getValue() crashes with error" { crash require "error message" } unittest test { ErrorOr value <- ErrorOr:error("error message") \ value.getValue() } testcase "ErrorOr convertError() crashes with no error" { crash require "no error" } unittest test { ErrorOr value <- ErrorOr:value(10) \ value.convertError() }