#[path = "common/mod.rs"]
mod common;
use rusty_figlet::{FigletBuilder, FigletError, Font};
#[test]
fn all_twelve_bundled_fonts_parse_clean() {
let variants = [
Font::Standard,
Font::Slant,
Font::Small,
Font::Big,
Font::Mini,
Font::Banner,
Font::Block,
Font::Bubble,
Font::Digital,
Font::Lean,
Font::Script,
Font::Shadow,
];
for font in variants {
let result = FigletBuilder::new().font(font.clone()).build();
assert!(
result.is_ok(),
"bundled font {font:?} must parse cleanly; got error: {:?}",
result.err()
);
let banner = result.unwrap().render("A").expect("render 'A'");
assert!(banner.height() >= 1, "{font:?} must report height >= 1");
}
}
#[test]
fn malformed_bad_signature_is_rejected() {
let bytes = common::make_malformed_flf_bad_signature();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("bad signature must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(reason.contains("bad signature"), "reason: {reason}");
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}
#[test]
fn malformed_truncated_header_is_rejected() {
let bytes = common::make_malformed_flf_truncated_header();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("truncated header must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(reason.contains("truncated header"), "reason: {reason}");
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}
#[test]
fn malformed_comment_lines_mismatch_is_rejected() {
let bytes = common::make_malformed_flf_comment_mismatch();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("comment mismatch must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(reason.contains("comment"), "reason: {reason}");
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}
#[test]
fn malformed_short_glyph_block_is_rejected() {
let bytes = common::make_malformed_flf_short_glyph();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("short glyph block must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(reason.contains("short glyph block"), "reason: {reason}");
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}
#[test]
fn malformed_missing_endmark_is_rejected() {
let bytes = common::make_malformed_flf_missing_endmark();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("missing endmark must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(reason.contains("endmark"), "reason: {reason}");
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}
#[test]
fn malformed_codetag_count_divergence_is_rejected() {
let bytes = common::make_malformed_flf_codetag_divergence();
let err = FigletBuilder::new()
.font_bytes(&bytes)
.build()
.expect_err("codetag divergence must be rejected");
match err {
FigletError::FontParse { reason, line } => {
assert!(
reason.contains("codetag")
|| reason.contains("German codepoint")
|| reason.contains("short glyph block")
|| reason.contains("endmark"),
"reason: {reason}"
);
assert!(line >= 1, "line must be >= 1, got {line}");
}
other => panic!("expected FontParse, got {other:?}"),
}
}