cranelift_filetests/
match_directive.rs1pub fn match_directive<'a>(comment: &'a str, directive: &str) -> Option<&'a str> {
8 assert!(
9 directive.ends_with(':'),
10 "Directive must include trailing colon"
11 );
12 let text = comment.trim_start_matches(';').trim_start();
13 text.strip_prefix(directive).map(|s| s.trim())
14}
15
16#[test]
17fn test_match_directive() {
18 assert_eq!(match_directive("; foo: bar ", "foo:"), Some("bar"));
19 assert_eq!(match_directive(" foo:bar", "foo:"), Some("bar"));
20 assert_eq!(match_directive("foo:bar", "foo:"), Some("bar"));
21 assert_eq!(match_directive(";x foo: bar", "foo:"), None);
22 assert_eq!(match_directive(";;; foo: bar", "foo:"), Some("bar"));
23}