use crate::lint::Level;
use crate::tokens::Method;
use std::fmt::{self, Display, Formatter};
pub(crate) fn codepoint(character: char) -> String {
Codepoint(character).to_string()
}
#[derive(Debug, Clone, Copy)]
pub(super) struct Codepoint(pub char);
impl Display for Codepoint {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "U+{:04X}", u32::from(self.0))
}
}
pub(super) const fn level_name(level: Level) -> &'static str {
match level {
Level::Allow => "allow",
Level::Warn => "warn",
Level::Deny => "deny",
Level::Forbid => "forbid",
}
}
pub(super) const fn method_name(method: Method) -> &'static str {
match method {
Method::Estimate => "estimate",
Method::Bpe => "bpe",
}
}
#[cfg(test)]
mod tests {
use super::{codepoint, level_name, method_name};
use crate::lint::Level;
use crate::tokens::Method;
#[test]
fn a_code_point_is_padded_to_four_uppercase_digits() {
assert_eq!(codepoint('\u{a0}'), "U+00A0");
}
#[test]
fn a_code_point_past_four_digits_is_not_truncated() {
assert_eq!(codepoint('\u{1F600}'), "U+1F600");
}
#[test]
fn levels_use_the_rustc_words() {
assert_eq!(level_name(Level::Forbid), "forbid");
assert_eq!(level_name(Level::Allow), "allow");
}
#[test]
fn methods_name_themselves() {
assert_eq!(method_name(Method::Estimate), "estimate");
assert_eq!(method_name(Method::Bpe), "bpe");
}
}