use std::hint::black_box;
use criterion::{Criterion, criterion_group, criterion_main};
use inkferro_core::text::string_width::string_width;
fn inputs() -> Vec<(&'static str, String, usize)> {
let ascii = "The quick brown fox jumps over the lazy dog 0123456789 !@#$%^&*()".repeat(8);
let ascii_w = ascii.chars().count();
let mixed = "Item 中文 listing — value: 42 (見出し) done? yes 漢字 end.".repeat(8);
let cjk = "中文漢字測試字符串寬度計算引擎".repeat(16);
let hangul = "\u{1100}\u{1161}\u{11A8}\u{1102}\u{1163}\u{1100}\u{1161}".repeat(24);
let emoji = "👨\u{200D}👩\u{200D}👧 ✌\u{FE0F} 👍🏽 🇺🇸 😀 ❤\u{200D}🔥 1\u{FE0F}\u{20E3}".repeat(8);
let ansi = "\x1b[1m\x1b[31mError:\x1b[0m something \x1b[4mfailed\x1b[0m badly. ".repeat(16);
vec![
("ascii", ascii, ascii_w),
("mixed_cjk", mixed, 464),
("cjk", cjk, 480),
("hangul", hangul, 144),
("emoji_zwj", emoji, 160),
("ansi", ansi, 496),
]
}
fn bench_string_width(c: &mut Criterion) {
let cases = inputs();
for (name, input, expected) in &cases {
assert_eq!(
string_width(input),
*expected,
"string_width/{name} fixture drifted"
);
}
let mut group = c.benchmark_group("string_width");
for (name, input, _) in &cases {
group.bench_function(*name, |b| {
b.iter(|| black_box(string_width(black_box(input))));
});
}
group.finish();
}
criterion_group!(benches, bench_string_width);
criterion_main!(benches);