This commit is contained in:
2020-11-29 09:51:53 +08:00
parent 295e097e91
commit 3f6a6b6013

View File

@@ -72,3 +72,34 @@ fn encode_str(s: &str) -> String {
} }
ret ret
} }
#[test]
fn test_qjs_01() {
let qjs = CommitMsgCheckQuickJs::new_from_js(r##"
function check(a) {
return false;
}
function hint() {
return "hello";
}
"##).unwrap();
assert_eq!(false, qjs.check("aa"));
assert_eq!(false, qjs.check("'\""));
assert_eq!(false, qjs.check("'\"\n\r"));
qjs.print_hint();
}
#[test]
fn test_qjs_02() {
let qjs = CommitMsgCheckQuickJs::new_from_js(r##"
function check(msg) {
return msg.startsWith('feat: ');
}
function hint() {
return "hello";
}
"##).unwrap();
assert_eq!(true, qjs.check("feat: xxx"));
}