zeolite-lang-0.15.0.0: lib/util/extra.0rt
/* -----------------------------------------------------------------------------
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()
if (count != 5) {
fail(count)
}
\ 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<String> argv <- Argv.global().subSequence(2,2)
Int count <- argv.size()
if (count != 2) {
fail(count)
}
\ 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<Int> value <- ErrorOr:value<Int>(10)
if (value.isError()) {
fail("Failed")
}
\ Testing.checkEquals<?>(value.getValue(),10)
}
unittest withError {
ErrorOr<String> value <- ErrorOr:error("error message")
if (!value.isError()) {
fail("Failed")
}
\ Testing.checkEquals<?>(value.getError().formatted(),"error message")
}
unittest convertError {
scoped {
ErrorOr<String> error <- ErrorOr:error("error message")
} in ErrorOr<Int> value <- error.convertError()
\ Testing.checkEquals<?>(value.getError().formatted(),"error message")
}
testcase "ErrorOr getError() crashes with value" {
crash
require "empty"
}
unittest test {
ErrorOr<Int> value <- ErrorOr:value<Int>(10)
\ value.getError()
}
testcase "ErrorOr getValue() crashes with error" {
crash
require "error message"
}
unittest test {
ErrorOr<String> value <- ErrorOr:error("error message")
\ value.getValue()
}
testcase "ErrorOr convertError() crashes with no error" {
crash
require "no error"
}
unittest test {
ErrorOr<Int> value <- ErrorOr:value<Int>(10)
\ value.convertError()
}