use prometeu_analysis::TextIndex; #[test] fn text_index_ascii_roundtrip() { let text = "hello\nworld\nthis is ascii"; let idx = TextIndex::new(text); // Verifica round-trip em todas as fronteiras de char let mut boundaries: Vec = 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 falhou para byte {} -> (l={},c16={})", b, line, col16); } // Alguns checks diretos // in铆cio: (0,0) assert_eq!(idx.byte_to_lsp(0), (0, 0)); // ap贸s "hello" (5), antes do '\n': linha 0, col=5 assert_eq!(idx.byte_to_lsp(5), (0, 5)); // ap贸s '\n' (6): linha 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); // fronteiras de char + fim let mut boundaries: Vec = 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 unicode falhou para byte {} -> (l={},c16={})", b, line, col16); } // Checagens de colunas esperadas na linha 0 // bytes: [0:'a'][1..2:'茅'][3..6:'馃檪'][7:'b'][8:end] assert_eq!(idx.byte_to_lsp(0), (0, 0)); // antes de 'a' assert_eq!(idx.byte_to_lsp(1), (0, 1)); // ap贸s 'a' assert_eq!(idx.byte_to_lsp(3), (0, 2)); // ap贸s 'a' + '茅' (1+1 utf16) assert_eq!(idx.byte_to_lsp(7), (0, 4)); // ap贸s '馃檪' (2 utf16) => 1+1+2=4 assert_eq!(idx.byte_to_lsp(8), (0, 5)); // ap贸s 'b' // e inverso, colunas espec铆ficas 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); }