Add a test for partition_source

This commit is contained in:
Eric Huss
2025-09-15 18:08:25 -07:00
parent 1daa650d61
commit 09f05e8a86

View File

@@ -1312,4 +1312,43 @@ mod tests {
assert_eq!(json!(TextDirection::RightToLeft), json!("rtl"));
assert_eq!(json!(TextDirection::LeftToRight), json!("ltr"));
}
#[test]
fn partition_rust_source() {
assert_eq!(partition_source(""), ("".to_string(), "".to_string()));
assert_eq!(
partition_source("let x = 1;"),
("".to_string(), "let x = 1;\n".to_string())
);
assert_eq!(
partition_source("fn main()\n{ let x = 1; }\n"),
("".to_string(), "fn main()\n{ let x = 1; }\n".to_string())
);
assert_eq!(
partition_source("#![allow(foo)]"),
("#![allow(foo)]\n".to_string(), "".to_string())
);
assert_eq!(
partition_source("#![allow(foo)]\n"),
("#![allow(foo)]\n".to_string(), "".to_string())
);
assert_eq!(
partition_source("#![allow(foo)]\nlet x = 1;"),
("#![allow(foo)]\n".to_string(), "let x = 1;\n".to_string())
);
assert_eq!(
partition_source(
"\n\
#![allow(foo)]\n\
\n\
#![allow(bar)]\n\
\n\
let x = 1;"
),
(
"\n#![allow(foo)]\n\n#![allow(bar)]\n\n".to_string(),
"let x = 1;\n".to_string()
)
);
}
}