use super::common::{serialize_yaml, TestErrorHandler}; use compiler::scanner::{ScanOption, Scanner, TextMode, TokenSource}; use insta::assert_snapshot; use serde::Serialize; fn scan_with_opt(s: &str, opt: ScanOption) -> impl TokenSource { let scanner = Scanner::new(opt); let ctx = TestErrorHandler; scanner.scan(s, ctx) } pub fn base_scan(s: &str) -> impl TokenSource { scan_with_opt(s, ScanOption::default()) } fn assert_yaml(val: S, expr: &str) { let name = insta::_macro_support::AutoName; let val = serialize_yaml(val); assert_snapshot!(name, val, expr); } #[test] fn test_scan() { let cases = [ r#"..."#, r#"..."#, r#""#, r#""#, r#""#, r#""#, r#""#, r#"=123 />"#, r#""#, r#""#, // abrupt closing r#""#, // abrupt closing r#""#, // ok r#" text -->"#, // ok r#"

"#, ]; for case in cases { let val: Vec<_> = base_scan(case).collect(); assert_yaml(val, case); } } #[test] fn test_scan_raw_text() { let cases = [ r#""#, r#""#, ]; for &case in cases.iter() { let opt = ScanOption { get_text_mode: |_| TextMode::RawText, ..Default::default() }; let t: Vec<_> = scan_with_opt(case, opt).collect(); assert_yaml(t, case); } } #[test] fn test_scan_rc_data() { let cases = [ r#""#, r#""#, r#""#, r#"'}}"#, r#""#, r#""#, r#""#, ]; for &case in cases.iter() { let opt = ScanOption { get_text_mode: |_| TextMode::RcData, ..Default::default() }; let a: Vec<_> = scan_with_opt(case, opt).collect(); assert_yaml(a, case); } }