zeolite-lang-0.24.0.0: lib/testing/test/matching.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 "MultiChecker.check short cicuits" {
failure
require "title0"
require "title2"
require "message2"
exclude "title1"
exclude "title3"
exclude "message3"
}
unittest test {
TestReportTree report <- TestReportTree.new("title0", ValueList<Formatted>.new())
\ MultiChecker.new(report)
.check(title: "title1", "foo", CheckAlways:match())
&.check(title: "title2", "foo", CheckAlways:error("message2"))
&.check(title: "title3", "foo", CheckAlways:error("message3"))
IndentAppend output <- IndentAppend.new(String.builder())
\ report.prune()&.writeTo(output)
\ TestHandler:failAndExit(output.build().formatted())
}
testcase "MultiChecker.tryCheck continues" {
failure
require "title0"
require "title2"
require "message2"
require "title3"
require "message3"
exclude "title1"
}
unittest test {
TestReportTree report <- TestReportTree.new("title0", ValueList<Formatted>.new())
\ MultiChecker.new(report)
.tryCheck<String>(title: "title1", "foo", CheckAlways:match())
.tryCheck<String>(title: "title2", "foo", CheckAlways:error("message2"))
.tryCheck<String>(title: "title3", "foo", CheckAlways:error("message3"))
IndentAppend output <- IndentAppend.new(String.builder())
\ report.prune()&.writeTo(output)
\ TestHandler:failAndExit(output.build().formatted())
}
testcase "MultiChecker.check doesn't force pending errors" {
failure
require "title0"
require "title1"
require "message1"
require "title3"
require "message3"
exclude "title2"
}
unittest test {
TestReportTree report <- TestReportTree.new("title0", ValueList<Formatted>.new())
\ MultiChecker.new(report)
.tryCheck<String>(title: "title1", "foo", CheckAlways:error("message1"))
.check(title: "title2", "foo", CheckAlways:match())
&.tryCheck<String>(title: "title3", "foo", CheckAlways:error("message3"))
IndentAppend output <- IndentAppend.new(String.builder())
\ report.prune()&.writeTo(output)
\ TestHandler:failAndExit(output.build().formatted())
}
testcase "MatcherCompose:not success" {
success TestChecker
}
unittest test {
\ "foo" `Matches:with` `MatcherCompose:not` CheckAlways:error("message")
}
testcase "MatcherCompose:not failure" {
failure TestChecker
require "expected failure"
}
unittest test {
\ "foo" `Matches:with` `MatcherCompose:not` CheckAlways:match()
}
testcase "MatcherCompose:or success" {
success TestChecker
}
unittest test {
\ "foo" `Matches:with` (CheckAlways:match() `MatcherCompose:or` CheckAlways:match())
\ "foo" `Matches:with` (CheckAlways:match() `MatcherCompose:or` CheckAlways:error("message"))
\ "foo" `Matches:with` (CheckAlways:error("message") `MatcherCompose:or` CheckAlways:match())
}
testcase "MatcherCompose:or failure" {
failure TestChecker
require "message1"
require "message2"
}
unittest test {
\ "foo" `Matches:with` (CheckAlways:error("message1") `MatcherCompose:or` CheckAlways:error("message2"))
}
testcase "MatcherCompose:and success" {
success TestChecker
}
unittest test {
\ "foo" `Matches:with` (CheckAlways:match() `MatcherCompose:and` CheckAlways:match())
}
testcase "MatcherCompose:and failure both" {
failure TestChecker
require "message1"
require "message2"
}
unittest test {
\ "foo" `Matches:with` (CheckAlways:error("message1") `MatcherCompose:and` CheckAlways:error("message2"))
}
testcase "MatcherCompose:and failure one" {
failure TestChecker
require "message"
}
unittest test {
\ "foo" `Matches:with` (CheckAlways:match() `MatcherCompose:and` CheckAlways:error("message"))
}
testcase "MatcherCompose:anyOf success" {
success TestChecker
}
unittest someMatching {
\ "foo" `Matches:with` MatcherCompose:anyOf(ValueList<ValueMatcher<any>>.new()
.append(CheckAlways:error("message"))
.append(CheckAlways:match())
.append(CheckAlways:die("message")))
}
unittest emptyList {
\ "foo" `Matches:with` MatcherCompose:anyOf(ValueList<ValueMatcher<any>>.new())
}
testcase "MatcherCompose:anyOf failure" {
failure TestChecker
require "message1"
require "message2"
}
unittest test {
\ "foo" `Matches:with` MatcherCompose:anyOf(ValueList<ValueMatcher<any>>.new()
.append(CheckAlways:error("message1"))
.append(CheckAlways:error("message2")))
}
testcase "MatcherCompose:allOf success" {
success TestChecker
}
unittest allMatching {
\ "foo" `Matches:with` MatcherCompose:allOf(ValueList<ValueMatcher<any>>.new()
.append(CheckAlways:match())
.append(CheckAlways:match()))
}
unittest emptyList {
\ "foo" `Matches:with` MatcherCompose:allOf(ValueList<ValueMatcher<any>>.new())
}
testcase "MatcherCompose:allOf failure" {
failure TestChecker
require "message1"
require "message2"
}
unittest test {
\ "foo" `Matches:with` MatcherCompose:allOf(ValueList<ValueMatcher<any>>.new()
.append(CheckAlways:match())
.append(CheckAlways:error("message1"))
.append(CheckAlways:match())
.append(CheckAlways:error("message2")))
}