use super::parse;
#[test]
fn should_count_columns_in_chars_after_multibyte_chars() {
const LINES: u32 = 3;
const LINE: &str = "\"é😀\", \"é😀\", \"é😀\",\r\n";
let mut source = String::from("[");
for _ in 0..LINES {
source.push_str(LINE);
}
source.push_str("0]");
let doc = parse(source.as_str().into()).unwrap();
let items = doc.root().as_array().unwrap();
let locations: Vec<(u32, u32)> = items.iter().map(|item| item.location().into()).collect();
let mut expected = vec![(0, 1), (0, 7), (0, 13)];
for line in 1..LINES {
expected.extend([(line, 0), (line, 6), (line, 12)]);
}
expected.push((LINES, 0));
assert_eq!(locations, expected);
}
#[test]
fn should_count_a_byte_order_mark_as_one_column() {
let doc = parse("\u{feff}[0]".into()).unwrap();
let root = doc.root();
let [item] = root.as_array().unwrap() else {
panic!("expected exactly one item");
};
assert_eq!(root.location(), (0, 1));
assert_eq!(item.location(), (0, 2));
}