Skip to content

Commit 6939dd3

Browse files
the-mikedavisarchseer
authored andcommitted
Add tests for select-mode TS textobjects
1 parent c253139 commit 6939dd3

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

helix-term/tests/test/movement.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,131 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
8585

8686
Ok(())
8787
}
88+
89+
#[tokio::test]
90+
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
91+
test_with_config(
92+
Args {
93+
files: vec![(PathBuf::from("foo.rs"), Position::default())],
94+
..Default::default()
95+
},
96+
Config::default(),
97+
(
98+
helpers::platform_line(indoc! {"\
99+
#[/|]#// Increments
100+
fn inc(x: usize) -> usize { x + 1 }
101+
/// Decrements
102+
fn dec(x: usize) -> usize { x - 1 }
103+
"})
104+
.as_ref(),
105+
"]fv]f",
106+
helpers::platform_line(indoc! {"\
107+
/// Increments
108+
#[fn inc(x: usize) -> usize { x + 1 }
109+
/// Decrements
110+
fn dec(x: usize) -> usize { x - 1 }|]#
111+
"})
112+
.as_ref(),
113+
),
114+
)
115+
.await?;
116+
117+
Ok(())
118+
}
119+
120+
#[tokio::test]
121+
async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
122+
test_with_config(
123+
Args {
124+
files: vec![(PathBuf::from("foo.rs"), Position::default())],
125+
..Default::default()
126+
},
127+
Config::default(),
128+
(
129+
helpers::platform_line(indoc! {"\
130+
/// Increments
131+
#[fn inc(x: usize) -> usize { x + 1 }
132+
/// Decrements
133+
fn dec(x: usize) -> usize { x - 1 }|]#
134+
"})
135+
.as_ref(),
136+
"v[f",
137+
helpers::platform_line(indoc! {"\
138+
/// Increments
139+
#[fn inc(x: usize) -> usize { x + 1 }|]#
140+
/// Decrements
141+
fn dec(x: usize) -> usize { x - 1 }
142+
"})
143+
.as_ref(),
144+
),
145+
)
146+
.await?;
147+
148+
Ok(())
149+
}
150+
151+
#[tokio::test]
152+
async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
153+
// Note: the anchor stays put and the head moves back.
154+
test_with_config(
155+
Args {
156+
files: vec![(PathBuf::from("foo.rs"), Position::default())],
157+
..Default::default()
158+
},
159+
Config::default(),
160+
(
161+
helpers::platform_line(indoc! {"\
162+
/// Increments
163+
fn inc(x: usize) -> usize { x + 1 }
164+
/// Decrements
165+
fn dec(x: usize) -> usize { x - 1 }
166+
/// Identity
167+
#[fn ident(x: usize) -> usize { x }|]#
168+
"})
169+
.as_ref(),
170+
"v[f",
171+
helpers::platform_line(indoc! {"\
172+
/// Increments
173+
fn inc(x: usize) -> usize { x + 1 }
174+
/// Decrements
175+
#[|fn dec(x: usize) -> usize { x - 1 }
176+
/// Identity
177+
]#fn ident(x: usize) -> usize { x }
178+
"})
179+
.as_ref(),
180+
),
181+
)
182+
.await?;
183+
184+
test_with_config(
185+
Args {
186+
files: vec![(PathBuf::from("foo.rs"), Position::default())],
187+
..Default::default()
188+
},
189+
Config::default(),
190+
(
191+
helpers::platform_line(indoc! {"\
192+
/// Increments
193+
fn inc(x: usize) -> usize { x + 1 }
194+
/// Decrements
195+
fn dec(x: usize) -> usize { x - 1 }
196+
/// Identity
197+
#[fn ident(x: usize) -> usize { x }|]#
198+
"})
199+
.as_ref(),
200+
"v[f[f",
201+
helpers::platform_line(indoc! {"\
202+
/// Increments
203+
#[|fn inc(x: usize) -> usize { x + 1 }
204+
/// Decrements
205+
fn dec(x: usize) -> usize { x - 1 }
206+
/// Identity
207+
]#fn ident(x: usize) -> usize { x }
208+
"})
209+
.as_ref(),
210+
),
211+
)
212+
.await?;
213+
214+
Ok(())
215+
}

0 commit comments

Comments
 (0)