use udled::tokenizers::{
AlphaNumeric, Alphabetic, AsciiWhiteSpace, LineBreak, Numeric, Punct, WhiteSpace,
};
use udled::Input;
#[test]
fn alphabetic() {
let mut input = Input::new("abc123");
assert_eq!(input.parse(Alphabetic).unwrap().value, 'a');
assert_eq!(input.parse(Alphabetic).unwrap().value, 'b');
assert_eq!(input.parse(Alphabetic).unwrap().value, 'c');
assert!(input.parse(Alphabetic).is_err());
}
#[test]
fn alphanumeric() {
let mut input = Input::new("a1!");
assert_eq!(input.parse(AlphaNumeric).unwrap().value, 'a');
assert_eq!(input.parse(AlphaNumeric).unwrap().value, '1');
assert!(input.parse(AlphaNumeric).is_err());
}
#[test]
fn numeric() {
let mut input = Input::new("123a");
assert_eq!(input.parse(Numeric).unwrap().value, '1');
assert_eq!(input.parse(Numeric).unwrap().value, '2');
assert_eq!(input.parse(Numeric).unwrap().value, '3');
assert!(input.parse(Numeric).is_err());
}
#[test]
fn punct_tokenizer() {
let mut input = Input::new("!@#");
assert_eq!(input.parse(Punct).unwrap().value, '!');
assert_eq!(input.parse(Punct).unwrap().value, '@');
assert_eq!(input.parse(Punct).unwrap().value, '#');
assert!(input.parse(Punct).is_err());
}
#[test]
fn ascii_whitespace() {
let mut input = Input::new(" \t\n");
assert_eq!(input.parse(AsciiWhiteSpace).unwrap().value, ' ');
assert_eq!(input.parse(AsciiWhiteSpace).unwrap().value, '\t');
assert_eq!(input.parse(AsciiWhiteSpace).unwrap().value, '\n');
assert!(input.parse(AsciiWhiteSpace).is_err());
}
#[test]
fn whitespace() {
let mut input = Input::new(" \u{00A0}");
assert_eq!(input.parse(WhiteSpace).unwrap().value, ' ');
assert_eq!(input.parse(WhiteSpace).unwrap().value, '\u{00A0}');
}
#[test]
fn linebreak() {
let mut input = Input::new("\n\r\u{2028}");
assert_eq!(input.parse(LineBreak).unwrap().value, '\n');
assert_eq!(input.parse(LineBreak).unwrap().value, '\r');
assert_eq!(input.parse(LineBreak).unwrap().value, '\u{2028}');
}
#[test]
fn digit_base() {
use udled::tokenizers::Digit;
let mut input = Input::new("9");
assert_eq!(input.parse(Digit::default()).unwrap().value, 9);
let mut input = Input::new("F");
assert_eq!(input.parse(Digit(16)).unwrap().value, 15);
let mut input = Input::new("G");
assert!(input.parse(Digit(16)).is_err());
let mut input = Input::new("7");
assert!(input.parse(Digit(4)).is_err());
}