Skip to content

Commit 04552fd

Browse files
committed
test(policy): add roundtrip test for semantic Display
1 parent 36b3c27 commit 04552fd

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/policy/semantic.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,31 @@ mod tests {
10571057
assert!(StringPolicy::from_str("# {pk(A), pk(B), pk(C)} = 2").is_err());
10581058
}
10591059

1060+
fn roundtrip(s: &str) {
1061+
let policy = StringPolicy::from_str(s).unwrap();
1062+
assert_eq!(StringPolicy::from_str(&policy.to_string()).unwrap(), policy);
1063+
}
1064+
1065+
#[test]
1066+
fn display_roundtrip() {
1067+
roundtrip("TRIVIAL");
1068+
roundtrip("UNSATISFIABLE");
1069+
roundtrip("pk(A)");
1070+
roundtrip("after(100)");
1071+
roundtrip("older(50)");
1072+
roundtrip("(pk(A) ∧ pk(B))");
1073+
roundtrip("(pk(A) ∨ pk(B))");
1074+
roundtrip("(pk(A) ∧ pk(B) ∧ pk(C))");
1075+
roundtrip("(pk(A) ∨ pk(B) ∨ pk(C))");
1076+
roundtrip("((pk(A) ∧ pk(B)) ∨ pk(C))");
1077+
roundtrip("#{pk(A), pk(B), pk(C)} = 2");
1078+
roundtrip("(pk(A) ∧ #{pk(B), pk(C), pk(D)} = 2)");
1079+
// Display always emits the mathematical form, so feeding it the
1080+
// function-call form exercises the parser → Display → parser path.
1081+
roundtrip("or(and(pk(A),pk(B)),pk(C))");
1082+
roundtrip("thresh(2,pk(A),pk(B),pk(C))");
1083+
}
1084+
10601085
#[test]
10611086
fn semantic_analysis() {
10621087
let policy = StringPolicy::from_str("pk()").unwrap();

0 commit comments

Comments
 (0)