added domains into crates

This commit is contained in:
2026-03-24 13:40:34 +00:00
parent 1135514508
commit bddd588464
222 changed files with 751 additions and 790 deletions
@@ -0,0 +1,69 @@
use prometeu_analysis::{FileDB, LineIndex};
#[test]
fn test_line_index_roundtrip() {
let text = "line 1\nline 2\nline 3";
let index = LineIndex::new(text);
// Roundtrip for each character
for (offset, _) in text.char_indices() {
let (line, col) = index.offset_to_line_col(offset as u32);
let recovered_offset = index.line_col_to_offset(line, col).expect("Should recover offset");
assert_eq!(offset as u32, recovered_offset, "Offset mismatch at line {}, col {}", line, col);
}
}
#[test]
fn test_line_index_boundaries() {
let text = "a\nbc\n";
let index = LineIndex::new(text);
// "a" -> (0, 0)
assert_eq!(index.offset_to_line_col(0), (0, 0));
assert_eq!(index.line_col_to_offset(0, 0), Some(0));
// "\n" -> (0, 1)
assert_eq!(index.offset_to_line_col(1), (0, 1));
assert_eq!(index.line_col_to_offset(0, 1), Some(1));
// "b" -> (1, 0)
assert_eq!(index.offset_to_line_col(2), (1, 0));
assert_eq!(index.line_col_to_offset(1, 0), Some(2));
// "c" -> (1, 1)
assert_eq!(index.offset_to_line_col(3), (1, 1));
assert_eq!(index.line_col_to_offset(1, 1), Some(3));
// "\n" (second) -> (1, 2)
assert_eq!(index.offset_to_line_col(4), (1, 2));
assert_eq!(index.line_col_to_offset(1, 2), Some(4));
// EOF (after last \n) -> (2, 0)
assert_eq!(index.offset_to_line_col(5), (2, 0));
assert_eq!(index.line_col_to_offset(2, 0), Some(5));
// Out of bounds
assert_eq!(index.line_col_to_offset(2, 1), None);
assert_eq!(index.line_col_to_offset(3, 0), None);
}
#[test]
fn test_file_db_upsert_and_access() {
let mut db = FileDB::new();
let uri = "file:///test.txt";
let text = "hello\nworld".to_string();
let id = db.upsert(uri, text.clone());
assert_eq!(db.file_id(uri), Some(id));
assert_eq!(db.uri(id), uri);
assert_eq!(db.text(id), &text);
let index = db.line_index(id);
assert_eq!(index.offset_to_line_col(6), (1, 0)); // 'w' is at offset 6
// Update existing file
let new_text = "new content".to_string();
let same_id = db.upsert(uri, new_text.clone());
assert_eq!(id, same_id);
assert_eq!(db.text(id), &new_text);
}
@@ -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));
}
@@ -0,0 +1,57 @@
use prometeu_analysis::TextIndex;
#[test]
fn text_index_ascii_roundtrip() {
let text = "hello\nworld\nthis is ascii";
let idx = TextIndex::new(text);
// Verify round-trip on all character boundaries
let mut boundaries: Vec<usize> = text.char_indices().map(|(i, _)| i).collect();
boundaries.push(text.len());
for &b in &boundaries {
let (line, col16) = idx.byte_to_lsp(b as u32);
let b2 = idx.lsp_to_byte(line, col16);
assert_eq!(b2, b as u32, "roundtrip failed for byte {} -> (l={},c16={})", b, line, col16);
}
// Some direct checks
// start: (0,0)
assert_eq!(idx.byte_to_lsp(0), (0, 0));
// after "hello" (5), before '\n': line 0, col=5
assert_eq!(idx.byte_to_lsp(5), (0, 5));
// after '\n' (6): line 1, col=0
assert_eq!(idx.byte_to_lsp(6), (1, 0));
}
#[test]
fn text_index_unicode_roundtrip_utf16() {
// "a" (1B, 1u16), "é" (2B, 1u16), "🙂" (4B, 2u16), "b" (1B, 1u16)
let text = "aé🙂b";
let idx = TextIndex::new(text);
// character boundaries + end
let mut boundaries: Vec<usize> = text.char_indices().map(|(i, _)| i).collect();
boundaries.push(text.len());
for &b in &boundaries {
let (line, col16) = idx.byte_to_lsp(b as u32);
let b2 = idx.lsp_to_byte(line, col16);
assert_eq!(b2, b as u32, "unicode roundtrip failed for byte {} -> (l={},c16={})", b, line, col16);
}
// Expected columns on line 0
// bytes: [0:'a'][1..2:'é'][3..6:'🙂'][7:'b'][8:end]
assert_eq!(idx.byte_to_lsp(0), (0, 0)); // before 'a'
assert_eq!(idx.byte_to_lsp(1), (0, 1)); // after 'a'
assert_eq!(idx.byte_to_lsp(3), (0, 2)); // after 'a' + 'é' (1+1 utf16)
assert_eq!(idx.byte_to_lsp(7), (0, 4)); // after '🙂' (2 utf16) => 1+1+2=4
assert_eq!(idx.byte_to_lsp(8), (0, 5)); // after 'b'
// and inverse, specific columns
assert_eq!(idx.lsp_to_byte(0, 0), 0);
assert_eq!(idx.lsp_to_byte(0, 1), 1);
assert_eq!(idx.lsp_to_byte(0, 2), 3);
assert_eq!(idx.lsp_to_byte(0, 4), 7);
assert_eq!(idx.lsp_to_byte(0, 5), 8);
}