zeolite-lang-0.24.0.0: lib/util/test/extra.0rt
/* -----------------------------------------------------------------------------
Copyright 2019-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 "Argv checks" {
success TestChecker
args "arg1" "arg2" "arg3" "arg4"
}
unittest global {
Int count <- Argv.global().size()
\ count `Matches:with` CheckValue:equals(5)
\ Argv.global().readAt(0) `Matches:with` CheckValue:equals("testcase")
\ Argv.global().readAt(1) `Matches:with` CheckValue:equals("arg1")
\ Argv.global().readAt(2) `Matches:with` CheckValue:equals("arg2")
\ Argv.global().readAt(3) `Matches:with` CheckValue:equals("arg3")
\ Argv.global().readAt(4) `Matches:with` CheckValue:equals("arg4")
}
unittest subSequence {
ReadAt<String> argv <- Argv.global().subSequence(2, 2)
Int count <- argv.size()
\ count `Matches:with` CheckValue:equals(2)
\ argv.readAt(0) `Matches:with` CheckValue:equals("arg2")
\ argv.readAt(1) `Matches:with` CheckValue:equals("arg3")
}
testcase "Argv readAt out of bounds" {
failure
require "index 5"
}
unittest test {
\ Argv.global().readAt(5)
}
testcase "Argv subSequence out of bounds" {
failure
require "index 5"
}
unittest test {
\ Argv.global().subSequence(5, 1)
}
testcase "ErrorOr checks" {
success TestChecker
}
unittest withValue {
ErrorOr<Int> value <- ErrorOr:value<Int>(10)
\ value.isError() `Matches:with` CheckValue:equals(false)
\ value.getValue() `Matches:with` CheckValue:equals(10)
\ value.tryValue() `Matches:with` CheckValue:equals(10)
}
unittest withError {
ErrorOr<String> value <- ErrorOr:error("error message")
\ value.isError() `Matches:with` CheckValue:equals(true)
\ value.tryValue() `Matches:with` CheckValue:equals(empty?String)
\ value.getError().formatted() `Matches:with` CheckValue:equals("error message")
}
unittest convertError {
scoped {
ErrorOr<String> error <- ErrorOr:error("error message")
} in ErrorOr<Int> value <- error.convertError()
\ value.getError().formatted() `Matches:with` CheckValue:equals("error message")
}
testcase "ErrorOr getError() crashes with value" {
failure
require "empty"
}
unittest test {
ErrorOr<Int> value <- ErrorOr:value<Int>(10)
\ value.getError()
}
testcase "ErrorOr getValue() crashes with error" {
failure
require "error message"
}
unittest test {
ErrorOr<String> value <- ErrorOr:error("error message")
\ value.getValue()
}
testcase "ErrorOr convertError() crashes with no error" {
failure
require "no error"
}
unittest test {
ErrorOr<Int> value <- ErrorOr:value<Int>(10)
\ value.convertError()
}
testcase "Void tests" {
success TestChecker
}
unittest formatted {
\ Void.default().formatted() `Matches:with` CheckValue:equals("Void")
}
unittest lessThan {
\ Void.default() `Void.lessThan` Void.default() `Matches:with` CheckValue:equals(false)
}
unittest equals {
\ Void.default() `Void.equals` Void.default() `Matches:with` CheckValue:equals(true)
}
unittest hashed {
\ Void.default().duplicate().hashed() `Matches:with` CheckValue:equals(Void.default().hashed())
}
testcase "AlwaysEmpty tests" {
success TestChecker
}
unittest conversions {
ReadAt<Int> read <- AlwaysEmpty.default()
WriteAt<Int> write <- AlwaysEmpty.default()
}
unittest size {
\ AlwaysEmpty.default().size() `Matches:with` CheckValue:equals(0)
}
unittest duplicate {
\ AlwaysEmpty.default().duplicate().size() `Matches:with` CheckValue:equals(0)
}
unittest defaultOrder {
traverse (AlwaysEmpty.default().defaultOrder() -> _) {
fail("expected empty")
}
}
testcase "AlwaysEmpty.readAt fails" {
failure
require "empty"
}
unittest readAt {
\ AlwaysEmpty.default().readAt(0)
}
testcase "AlwaysEmpty.writeAt fails" {
failure
require "empty"
}
unittest readAt {
\ AlwaysEmpty.default().writeAt(0, 123)
}