Skip to content

Commit

Permalink
assert no sequential chunks are smaller than max
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jul 3, 2024
1 parent d60a826 commit 9c6f93e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions swiftide/src/integrations/treesitter/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ mod test {
"#};
let chunks = splitter.split(text).unwrap();

dbg!(&chunks);
assert!(chunks.iter().all(|chunk| chunk.len() <= 50));
assert!(chunks
.windows(2)
.all(|pair| pair.iter().map(|chunk| chunk.len()).sum::<usize>() >= 50));

assert_eq!(
chunks,
vec![
"fn main()",
"{\n println!(\"Hello, World!\");",
"fn main() {\n println!(\"Hello, World!\");",
"\n println!(\"Goodbye, World!\");\n}",
]
)
Expand Down Expand Up @@ -321,6 +324,13 @@ mod test {
}
"#};
let chunks = splitter.split(text).unwrap();

assert!(chunks.iter().all(|chunk| chunk.len() <= 50));
assert!(chunks
.windows(2)
.all(|pair| pair.iter().map(|chunk| chunk.len()).sum::<usize>() <= 50));
assert!(chunks.iter().all(|chunk| chunk.len() >= 20));

assert_eq!(
chunks,
vec![
Expand Down Expand Up @@ -363,7 +373,14 @@ mod test {

let chunks = splitter.split(code).unwrap();

// assert no chunks smaller than min
assert!(chunks.iter().all(|chunk| chunk.len() <= max));
assert!(chunks.windows(2).all(|pair| pair
.iter()
.map(|chunk| chunk.len())
.sum::<usize>()
>= max));
assert!(chunks.iter().all(|chunk| chunk.len() >= min));

assert!(
chunks.iter().all(|chunk| chunk.len() >= min),
"{:?}",
Expand Down

0 comments on commit 9c6f93e

Please sign in to comment.