pr 02
This commit is contained in:
@@ -6,3 +6,20 @@ pub struct Span {
|
||||
pub start: u32, // byte offset
|
||||
pub end: u32, // byte offset, exclusive
|
||||
}
|
||||
|
||||
impl Span {
|
||||
#[inline]
|
||||
pub fn new(file: FileId, start: u32, end: u32) -> Self {
|
||||
Self { file, start, end }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> u32 {
|
||||
self.end.saturating_sub(self.start)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains(&self, byte: u32) -> bool {
|
||||
self.start <= byte && byte < self.end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
use prometeu_analysis::{ids::FileId, span::Span};
|
||||
|
||||
#[test]
|
||||
fn span_end_is_exclusive() {
|
||||
let file = FileId(1);
|
||||
let s = Span::new(file, 2, 5);
|
||||
// len = end - start
|
||||
assert_eq!(s.len(), 3);
|
||||
// contains is [start, end)
|
||||
assert!(s.contains(2));
|
||||
assert!(s.contains(3));
|
||||
assert!(s.contains(4));
|
||||
assert!(!s.contains(5));
|
||||
}
|
||||
Reference in New Issue
Block a user