Skip to content

Commit c17ddab

Browse files
move test mod
1 parent 070a66f commit c17ddab

File tree

1 file changed

+33
-33
lines changed
  • crates/djls-template-ast/src

1 file changed

+33
-33
lines changed

crates/djls-template-ast/src/ast.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,6 @@ impl LineOffsets {
6868
}
6969
}
7070

71-
#[cfg(test)]
72-
mod tests {
73-
use super::*;
74-
75-
#[test]
76-
fn test_line_offsets() {
77-
let mut offsets = LineOffsets::new();
78-
offsets.add_line(10); // Line 1 starts at offset 10
79-
offsets.add_line(25); // Line 2 starts at offset 25
80-
offsets.add_line(40); // Line 3 starts at offset 40
81-
82-
// Test position_to_line_col
83-
assert_eq!(offsets.position_to_line_col(0), (0, 0)); // Start of first line
84-
assert_eq!(offsets.position_to_line_col(5), (0, 5)); // Middle of first line
85-
assert_eq!(offsets.position_to_line_col(10), (1, 0)); // Start of second line
86-
assert_eq!(offsets.position_to_line_col(15), (1, 5)); // Middle of second line
87-
assert_eq!(offsets.position_to_line_col(25), (2, 0)); // Start of third line
88-
assert_eq!(offsets.position_to_line_col(35), (2, 10)); // Middle of third line
89-
assert_eq!(offsets.position_to_line_col(40), (3, 0)); // Start of fourth line
90-
assert_eq!(offsets.position_to_line_col(45), (3, 5)); // Middle of fourth line
91-
92-
// Test line_col_to_position
93-
assert_eq!(offsets.line_col_to_position(0, 0), 0); // Start of first line
94-
assert_eq!(offsets.line_col_to_position(0, 5), 5); // Middle of first line
95-
assert_eq!(offsets.line_col_to_position(1, 0), 10); // Start of second line
96-
assert_eq!(offsets.line_col_to_position(1, 5), 15); // Middle of second line
97-
assert_eq!(offsets.line_col_to_position(2, 0), 25); // Start of third line
98-
assert_eq!(offsets.line_col_to_position(2, 10), 35); // Middle of third line
99-
assert_eq!(offsets.line_col_to_position(3, 0), 40); // Start of fourth line
100-
assert_eq!(offsets.line_col_to_position(3, 5), 45); // Middle of fourth line
101-
}
102-
}
103-
10471
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
10572
pub struct Span {
10673
start: u32,
@@ -183,3 +150,36 @@ pub enum AstError {
183150
#[error("stream error: {0}")]
184151
StreamError(String),
185152
}
153+
154+
#[cfg(test)]
155+
mod tests {
156+
use super::*;
157+
158+
#[test]
159+
fn test_line_offsets() {
160+
let mut offsets = LineOffsets::new();
161+
offsets.add_line(10); // Line 1 starts at offset 10
162+
offsets.add_line(25); // Line 2 starts at offset 25
163+
offsets.add_line(40); // Line 3 starts at offset 40
164+
165+
// Test position_to_line_col
166+
assert_eq!(offsets.position_to_line_col(0), (0, 0)); // Start of first line
167+
assert_eq!(offsets.position_to_line_col(5), (0, 5)); // Middle of first line
168+
assert_eq!(offsets.position_to_line_col(10), (1, 0)); // Start of second line
169+
assert_eq!(offsets.position_to_line_col(15), (1, 5)); // Middle of second line
170+
assert_eq!(offsets.position_to_line_col(25), (2, 0)); // Start of third line
171+
assert_eq!(offsets.position_to_line_col(35), (2, 10)); // Middle of third line
172+
assert_eq!(offsets.position_to_line_col(40), (3, 0)); // Start of fourth line
173+
assert_eq!(offsets.position_to_line_col(45), (3, 5)); // Middle of fourth line
174+
175+
// Test line_col_to_position
176+
assert_eq!(offsets.line_col_to_position(0, 0), 0); // Start of first line
177+
assert_eq!(offsets.line_col_to_position(0, 5), 5); // Middle of first line
178+
assert_eq!(offsets.line_col_to_position(1, 0), 10); // Start of second line
179+
assert_eq!(offsets.line_col_to_position(1, 5), 15); // Middle of second line
180+
assert_eq!(offsets.line_col_to_position(2, 0), 25); // Start of third line
181+
assert_eq!(offsets.line_col_to_position(2, 10), 35); // Middle of third line
182+
assert_eq!(offsets.line_col_to_position(3, 0), 40); // Start of fourth line
183+
assert_eq!(offsets.line_col_to_position(3, 5), 45); // Middle of fourth line
184+
}
185+
}

0 commit comments

Comments
 (0)