Skip to content

Commit ace49ea

Browse files
committed
Simplify tests
1 parent 138dec6 commit ace49ea

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

ucan/src/delegation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ mod tests {
486486
issuer: iss,
487487
audience: aud,
488488
subject: DelegatedSubject::Any,
489-
command: Command::parse("/").expect("root command"),
489+
command: Command::parse("/")?,
490490
policy: vec![],
491491
expiration: None,
492492
not_before: None,

ucan/src/delegation/policy/predicate.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,20 @@ impl Serialize for Predicate {
110110
triple.serialize_element(rhs)?;
111111
triple.end()
112112
}
113-
Self::Not(inner) => match inner.as_ref() {
114-
Predicate::Equal(lhs, rhs) => {
113+
Self::Not(inner) => {
114+
if let Predicate::Equal(lhs, rhs) = inner.as_ref() {
115115
let mut triple = serializer.serialize_tuple(3)?;
116116
triple.serialize_element(&"!=")?;
117117
triple.serialize_element(lhs)?;
118118
triple.serialize_element(rhs)?;
119119
triple.end()
120-
}
121-
_ => {
120+
} else {
122121
let mut tuple = serializer.serialize_tuple(2)?;
123122
tuple.serialize_element(&"not")?;
124123
tuple.serialize_element(inner)?;
125124
tuple.end()
126125
}
127-
},
126+
}
128127
Self::And(inner) => {
129128
let mut tuple = serializer.serialize_tuple(2)?;
130129
tuple.serialize_element(&"and")?;
@@ -655,7 +654,18 @@ impl From<Predicate> for Ipld {
655654
Predicate::Equal(lhs, rhs) => {
656655
Ipld::List(vec![Ipld::String("!=".to_string()), lhs.into(), rhs])
657656
}
658-
other => Ipld::List(vec![Ipld::String("not".to_string()), other.into()]),
657+
other @ (Predicate::GreaterThan(_, _)
658+
| Predicate::GreaterThanOrEqual(_, _)
659+
| Predicate::LessThan(_, _)
660+
| Predicate::LessThanOrEqual(_, _)
661+
| Predicate::Like(_, _)
662+
| Predicate::Not(_)
663+
| Predicate::And(_)
664+
| Predicate::Or(_)
665+
| Predicate::All(_, _)
666+
| Predicate::Any(_, _)) => {
667+
Ipld::List(vec![Ipld::String("not".to_string()), other.into()])
668+
}
659669
},
660670
Predicate::And(inner) => {
661671
let inner_ipld: Vec<Ipld> = inner.into_iter().map(Into::into).collect();

0 commit comments

Comments
 (0)