This commit is contained in:
2026-03-24 13:40:28 +00:00
parent adb4dad14b
commit 07f986df5b
23 changed files with 286 additions and 237 deletions
+17
View File
@@ -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));
}