///|
/// Shared test helpers.
fn assert_true(value : Bool) -> Unit raise {
if !value {
fail("expected true")
}
}
///|
fn assert_false(value : Bool) -> Unit raise {
if value {
fail("expected false")
}
}
///|
fn assert_int_eq(actual : Int, expected : Int) -> Unit raise {
if actual != expected {
fail("expected \{expected}, got \{actual}")
}
}
///|
fn assert_str_eq(actual : String, expected : String) -> Unit raise {
if actual != expected {
fail("expected '\{expected}', got '\{actual}'")
}
}
///|
fn unwrap_parse(input : String) -> ProblemParseResult raise {
match parse_problem_json(input) {
Ok(value) => value
Err(error) => fail("unexpected parse error: \{error.to_string()}")
}
}
///|
fn unwrap_problem(input : String) -> ProblemDetails raise {
unwrap_parse(input).problem()
}
///|
fn expect_error(input : String) -> ProblemError raise {
match parse_problem_json(input) {
Ok(_) => fail("expected parse error")
Err(error) => error
}
}
///|
fn unwrap_build(
result : Result[ProblemDetails, ProblemError],
) -> ProblemDetails raise {
match result {
Ok(value) => value
Err(error) => fail(error.to_string())
}
}
///|
fn has_audit(report : AuditReport, kind : AuditIssueKind) -> Bool {
for issue in report.issues() {
if issue.kind() == kind {
return true
}
}
false
}
///|
fn bytes_prefix(input : Bytes, length : Int) -> Bytes {
let out : Array[Byte] = []
for i = 0; i < length; i = i + 1 {
out.push(input[i])
}
Bytes::from_array(out)
}