Skip to content

Commit 9c69083

Browse files
committed
add failing tests for first_comment_between
1 parent 3ec71f7 commit 9c69083

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

compiler-core/src/parse/extra.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,60 @@ impl<'a> From<(&SrcSpan, &'a str)> for Comment<'a> {
8282
}
8383
}
8484
}
85+
86+
#[cfg(test)]
87+
mod tests {
88+
use crate::{ast::SrcSpan, parse::extra::ModuleExtra};
89+
90+
fn set_up_extra() -> ModuleExtra {
91+
let mut extra = ModuleExtra::new();
92+
extra.comments = vec![
93+
SrcSpan { start: 0, end: 10 },
94+
SrcSpan { start: 20, end: 30 },
95+
SrcSpan { start: 40, end: 50 },
96+
SrcSpan { start: 60, end: 70 },
97+
SrcSpan { start: 80, end: 90 },
98+
SrcSpan {
99+
start: 90,
100+
end: 100,
101+
},
102+
];
103+
extra
104+
}
105+
106+
#[test]
107+
fn first_comment_between() {
108+
let extra = set_up_extra();
109+
assert!(matches!(
110+
extra.first_comment_between(15, 85),
111+
Some(SrcSpan { start: 20, end: 30 })
112+
));
113+
}
114+
115+
#[test]
116+
fn first_comment_between_equal_to_range() {
117+
let extra = set_up_extra();
118+
assert!(matches!(
119+
extra.first_comment_between(40, 50),
120+
Some(SrcSpan { start: 40, end: 50 })
121+
));
122+
}
123+
124+
#[test]
125+
fn first_comment_between_overlapping_start_of_range() {
126+
let extra = set_up_extra();
127+
assert!(matches!(
128+
extra.first_comment_between(45, 80),
129+
Some(SrcSpan { start: 40, end: 50 })
130+
));
131+
}
132+
133+
#[test]
134+
fn first_comment_between_at_end_of_range() {
135+
let extra = set_up_extra();
136+
assert!(matches!(
137+
dbg!(extra.first_comment_between(55, 60)),
138+
Some(SrcSpan { start: 60, end: 70 })
139+
));
140+
}
141+
}

0 commit comments

Comments
 (0)