summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/doc.rs b/src/doc.rs
index b7b1eacd..5f62506a 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -591,6 +591,12 @@ impl Region {
}
}
+impl PartialEq<&str> for Region {
+ fn eq(&self, other: &&str) -> bool {
+ self.as_str() == *other
+ }
+}
+
impl FromStr for Region {
type Err = &'static str;
@@ -688,3 +694,23 @@ cast_to_value! {
"y" => Value::Length(v.point.y.into()),
})
}
+
+#[cfg(test)]
+mod tests {
+ use crate::{doc::Region, util::option_eq};
+
+ #[test]
+ fn test_partialeq_str() {
+ let region = Region([b'U', b'S']);
+ assert_eq!(region, "US");
+ assert_ne!(region, "AB");
+ }
+
+ #[test]
+ fn test_region_option_eq() {
+ let region = Some(Region([b'U', b'S']));
+
+ assert!(option_eq(region, "US"));
+ assert!(!option_eq(region, "AB"));
+ }
+}