Add some basic tests to span
module, other minor tweaks
This commit is contained in:
parent
0967ef46a8
commit
5e114c475e
@ -87,7 +87,7 @@ impl Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A contiguous sequence of bytes within some source.
|
/// A contiguous sequence of bytes within some source.
|
||||||
#[derive(Debug, Default, Clone, Hash)]
|
#[derive(Debug, Default, Clone, Eq, Hash)]
|
||||||
pub struct Span {
|
pub struct Span {
|
||||||
bytes: Range<usize>,
|
bytes: Range<usize>,
|
||||||
source: Arc<Source>,
|
source: Arc<Source>,
|
||||||
@ -111,7 +111,6 @@ impl Span {
|
|||||||
/// Extend one span to include another.
|
/// Extend one span to include another.
|
||||||
pub fn extend(&mut self, other: &Self) {
|
pub fn extend(&mut self, other: &Self) {
|
||||||
debug_assert!(self.same_source(other));
|
debug_assert!(self.same_source(other));
|
||||||
|
|
||||||
self.bytes.end = other.bytes.end;
|
self.bytes.end = other.bytes.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +132,7 @@ impl Span {
|
|||||||
Arc::ptr_eq(&self.source, &other.source)
|
Arc::ptr_eq(&self.source, &other.source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub(crate) fn bytes(&self) -> &Range<usize> {
|
pub(crate) fn bytes(&self) -> &Range<usize> {
|
||||||
&self.bytes
|
&self.bytes
|
||||||
}
|
}
|
||||||
@ -143,3 +143,25 @@ impl PartialEq for Span {
|
|||||||
self.same_source(other) && self.bytes == other.bytes
|
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user