zeolite-lang-0.24.0.0: lib/testing/test/util.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 "IndentAppend" {
success
}
unittest nothingAppended {
String result <- IndentAppend.new(String.builder())
.build()
.formatted()
\ Testing.checkEquals(result, "")
}
unittest addNewline {
String result <- IndentAppend.new(String.builder())
.addNewline()
.build()
.formatted()
\ Testing.checkEquals(result, "\n")
}
unittest usesNewlines {
String result <- IndentAppend.new(String.builder())
.append("message1")
.append("message2")
.build()
.formatted()
\ Testing.checkEquals(result, "message1\nmessage2\n")
}
unittest indents {
String result <- IndentAppend.new(String.builder())
.pushIndent()
.append("message1")
.pushIndent()
.append("message2")
.popIndent()
.popIndent()
.append("message3")
.build()
.formatted()
\ Testing.checkEquals(result, " message1\n message2\nmessage3\n")
}
testcase "ValueList" {
success
}
concrete Helper {
@type new (ValueList<Int>) -> (Helper)
@value checkNext (Int) -> (Helper)
@value checkFinished () -> ()
}
define Helper {
@value optional Order<Int> current
new (list) {
return Helper{ list.defaultOrder() }
}
checkNext (value) {
\ Testing.checkEquals(current&.get(), value)
current <- current&.next()
return self
}
checkFinished () {
if (`present` current) {
fail("list not empty")
}
}
}
unittest nothingAdded {
ValueList<Int> list <- ValueList<Int>.new()
\ Testing.checkEquals(list.isEmpty(), true)
\ Helper.new(list)
.checkFinished()
}
unittest withItems {
ValueList<Int> list <- ValueList<Int>.new()
.append(1)
.append(2)
.append(3)
\ Testing.checkEquals(list.isEmpty(), false)
\ Helper.new(list)
.checkNext(1)
.checkNext(2)
.checkNext(3)
.checkFinished()
}
testcase "TestHandler skips tracing" {
failure
require "message"
exclude "exitTest"
}
unittest exitTest {
\ TestHandler:failAndExit("message")
}
testcase "TestReportTree success" {
success
}
unittest nothingAdded {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
IndentAppend output <- IndentAppend.new(String.builder())
\ Testing.checkEquals(report.hasError(), false)
\ report.prune()&.writeTo(output)
\ Testing.checkEquals(output.build().formatted(), "")
}
unittest nonFailingSections {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ report.newSection(title: "child1")
\ report.newSection(title: "child2")
\ Testing.checkEquals(report.hasError(), false)
IndentAppend output <- IndentAppend.new(String.builder())
\ report.prune()&.writeTo(output)
\ Testing.checkEquals(output.build().formatted(), "")
}
testcase "TestReportTree prune doesn't include non-failing sections" {
failure
require "title"
require "child2"
require "message2"
require "child4"
require "message4"
exclude "child1"
exclude "child5"
}
unittest test {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ report.newSection(title: "child1")
\ report.newSection(title: "child2").addError(message: "message2")
\ report.newSection(title: "child3").addError(message: "message3").discardReport()
\ report.newSection(title: "child4").addError(message: "message4")
\ report.newSection(title: "child5")
\ Testing.checkEquals(report.hasError(), true)
IndentAppend output <- IndentAppend.new(String.builder())
\ report.prune()&.writeTo(output)
\ TestHandler:failAndExit(output.build().formatted())
}
testcase "TestReportTree unpruned preserves non-failing sections" {
failure
require "title"
require "child1"
require "child2"
require "message2"
require "child4"
require "message4"
require "child5"
}
unittest test {
TestReportTree report <- TestReportTree.new("title", ValueList<Formatted>.new())
\ report.newSection(title: "child1")
\ report.newSection(title: "child2").addError(message: "message2")
\ report.newSection(title: "child3").addError(message: "message3").discardReport()
\ report.newSection(title: "child4").addError(message: "message4")
\ report.newSection(title: "child5")
\ Testing.checkEquals(report.hasError(), true)
IndentAppend output <- IndentAppend.new(String.builder())
\ report.writeTo(output)
\ TestHandler:failAndExit(output.build().formatted())
}