Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cedar-drt/fuzz/fuzz_targets/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use serde::Serialize;
use similar_asserts::SimpleDiff;
use smol_str::SmolStr;
use std::collections::HashMap;
use uuid::Builder;

Expand Down Expand Up @@ -161,12 +160,12 @@ fuzz_target!(|input: FuzzTargetInput| {
);
// just dump to standard hashmaps to check equality without order.
// also ignore source locations, which are not preserved in this roundtrip
let roundtripped_anno: HashMap<&AnyId, &SmolStr> = roundtripped
let roundtripped_anno: HashMap<&AnyId, &str> = roundtripped
.annotations()
.map(|(k, v)| (k, &v.val))
.map(|(k, v)| (k, v.val()))
.collect();
let original_anno: HashMap<&AnyId, &SmolStr> =
t.annotations().map(|(k, v)| (k, &v.val)).collect();
let original_anno: HashMap<&AnyId, &str> =
t.annotations().map(|(k, v)| (k, v.val())).collect();
assert_eq!(
original_anno, roundtripped_anno,
"\nannotations should be the same, found:\noriginal: {original_anno:?}\nroundtripped: {roundtripped_anno:?}\n",
Expand Down
7 changes: 2 additions & 5 deletions cedar-drt/fuzz/src/parsing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@

use cedar_policy_core::ast::{AnyId, Template};
use cedar_policy_core::parser::err::{ParseError, ParseErrors, ToASTErrorKind};
use smol_str::SmolStr;
use std::collections::HashMap;

// Check that two policies are equivalent, ignoring policy ids and source
// locations. Panic if the two policies are not the same.
pub fn check_policy_equivalence(p_old: &Template, p_new: &Template) {
// just dump to standard hashmaps to check equality without order.
// also ignore source locations, which are not preserved in general
let new_anno: HashMap<&AnyId, &SmolStr> =
p_new.annotations().map(|(k, v)| (k, &v.val)).collect();
let old_anno: HashMap<&AnyId, &SmolStr> =
p_old.annotations().map(|(k, v)| (k, &v.val)).collect();
let new_anno: HashMap<&AnyId, &str> = p_new.annotations().map(|(k, v)| (k, v.val())).collect();
let old_anno: HashMap<&AnyId, &str> = p_old.annotations().map(|(k, v)| (k, v.val())).collect();
similar_asserts::assert_eq!(new_anno, old_anno);
similar_asserts::assert_eq!(p_new.effect(), p_old.effect());
similar_asserts::assert_eq!(p_new.principal_constraint(), p_old.principal_constraint(),);
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-generators/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl GeneratedPolicy {
fn convert_annotations(annotations: HashMap<AnyId, SmolStr>) -> Annotations {
annotations
.into_iter()
.map(|(k, v)| (k, Annotation { val: v, loc: None }))
.map(|(k, v)| (k, Annotation::new(Some(v), None)))
.collect()
}

Expand Down
Loading