diff --git a/onihime/src/span.rs b/onihime/src/span.rs index 22d61c5..197ce5e 100644 --- a/onihime/src/span.rs +++ b/onihime/src/span.rs @@ -87,7 +87,7 @@ impl Source { } /// A contiguous sequence of bytes within some source. -#[derive(Debug, Default, Clone, Hash)] +#[derive(Debug, Default, Clone, Eq, Hash)] pub struct Span { bytes: Range, source: Arc, @@ -111,7 +111,6 @@ impl Span { /// Extend one span to include another. pub fn extend(&mut self, other: &Self) { debug_assert!(self.same_source(other)); - self.bytes.end = other.bytes.end; } @@ -133,6 +132,7 @@ impl Span { Arc::ptr_eq(&self.source, &other.source) } + #[must_use] pub(crate) fn bytes(&self) -> &Range { &self.bytes } @@ -143,3 +143,25 @@ impl PartialEq for Span { self.same_source(other) && self.bytes == other.bytes } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn location_partial_ord() { + assert!(Location::new(1, 1) < Location::new(1, 2)); + assert!(Location::new(1, 10) < Location::new(2, 1)); + assert!(Location::new(5, 5) == Location::new(5, 5)); + assert!(Location::new(10, 1) > Location::new(9, 99)); + } + + #[test] + fn source_get_set_name() { + let mut src = Source::new(None, "".into()); + assert!(src.name().is_none()); + + src.set_name("foo".into()); + assert!(src.name() == Some("foo")); + } +}