zeolite-lang-0.24.0.0: lib/testing/test/evaluation.0rt
/* -----------------------------------------------------------------------------
Copyright 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 "Matches no errors" {
success TestChecker
}
unittest withOnce {
\ "foo" `Matches:with` CheckAlways:match()
}
unittest withMulti {
\ "foo" `Matches:with` CheckAlways:match()
\ "foo" `Matches:with` CheckAlways:match()
}
unittest tryWithOnce {
\ "foo" `Matches:tryWith` CheckAlways:match()
}
unittest tryWithMulti {
\ "foo" `Matches:tryWith` CheckAlways:match()
\ "foo" `Matches:tryWith` CheckAlways:match()
}
unittest valueOnce {
\ TestValue.default() `Matches:value` TestValue.default()
}
unittest valueMulti {
\ TestValue.default() `Matches:value` TestValue.default()
\ TestValue.default() `Matches:value` TestValue.default()
}
unittest tryValueOnce {
\ TestValue.default() `Matches:tryValue` TestValue.default()
}
unittest tryValueMulti {
\ TestValue.default() `Matches:tryValue` TestValue.default()
\ TestValue.default() `Matches:tryValue` TestValue.default()
}
testcase "Matches:with fails immediately" {
failure TestChecker
require "message1"
exclude "message2"
}
unittest test {
\ "foo" `Matches:with` CheckAlways:error("message1")
\ "foo" `Matches:with` CheckAlways:error("message2")
}
testcase "Matches:tryWith fails later" {
failure TestChecker
require "message1"
require "message2"
}
unittest test {
\ "foo" `Matches:tryWith` CheckAlways:error("message1")
\ "foo" `Matches:tryWith` CheckAlways:error("message2")
}
testcase "Matches:value fails immediately" {
failure TestChecker
require "message1"
exclude "321"
exclude "message2"
exclude "999"
}
unittest test {
\ TestValue.default() `Matches:value` TestValue.new(123, "message1", empty)
\ TestValue.default() `Matches:value` TestValue.new(321, "message2", 999)
}
testcase "Matches:value failure with empty" {
failure TestChecker
require "empty"
}
unittest test {
\ empty?TestValue `Matches:value` TestValue.new(123, "message1", empty)
}
testcase "Matches:tryValue fails later" {
failure TestChecker
require "message1"
require "321"
require "message2"
require "999"
}
unittest test {
\ TestValue.default() `Matches:tryValue` TestValue.new(123, "message1", empty)
\ TestValue.default() `Matches:tryValue` TestValue.new(321, "message2", 999)
}
testcase "Matches:tryValue failure with empty" {
failure TestChecker
require "empty"
}
unittest test {
\ empty?TestValue `Matches:tryValue` TestValue.new(123, "message1", empty)
}
testcase "Matches:with doesn't evaluate pending errors" {
failure TestChecker
require "message2"
exclude "message1"
}
unittest test {
\ "foo" `Matches:tryWith` CheckAlways:error("message1")
\ "foo" `Matches:with` CheckAlways:match()
fail("message2")
}
testcase "Matches:value doesn't evaluate pending errors" {
failure TestChecker
require "message2"
exclude "message1"
}
unittest test {
\ TestValue.default() `Matches:tryValue` TestValue.new(123, "message1", empty)
\ TestValue.default() `Matches:value` TestValue.default()
fail("message2")
}
testcase "CheckAlways" {
success
}
unittest match {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ CheckAlways:match().check(123, report)
\ Testing.checkEquals(report.hasError(), false)
}
unittest fromWithoutError {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ CheckAlways:error("message").check(123, report)
\ Testing.checkEquals(report.hasError(), true)
}
testcase "CheckAlways:die" {
failure
require "something"
}
unittest test {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ report.addError(message: "message")
\ CheckAlways:die("something").check(123, report)
}