1use std::ops::{Deref, DerefMut};
2
3use gpui::ContextHandle;
4
5use crate::state::Mode;
6
7use super::NeovimBackedTestContext;
8
9pub struct NeovimBackedBindingTestContext<'a, const COUNT: usize> {
10 cx: NeovimBackedTestContext<'a>,
11 keystrokes_under_test: [&'static str; COUNT],
12}
13
14impl<'a, const COUNT: usize> NeovimBackedBindingTestContext<'a, COUNT> {
15 pub fn new(
16 keystrokes_under_test: [&'static str; COUNT],
17 cx: NeovimBackedTestContext<'a>,
18 ) -> Self {
19 Self {
20 cx,
21 keystrokes_under_test,
22 }
23 }
24
25 pub fn consume(self) -> NeovimBackedTestContext<'a> {
26 self.cx
27 }
28
29 pub fn binding<const NEW_COUNT: usize>(
30 self,
31 keystrokes: [&'static str; NEW_COUNT],
32 ) -> NeovimBackedBindingTestContext<'a, NEW_COUNT> {
33 self.consume().binding(keystrokes)
34 }
35
36 pub async fn assert(
37 &mut self,
38 marked_positions: &str,
39 ) -> Option<(ContextHandle, ContextHandle)> {
40 self.cx
41 .assert_binding_matches(self.keystrokes_under_test, marked_positions)
42 .await
43 }
44
45 pub fn assert_manual(
46 &mut self,
47 initial_state: &str,
48 mode_before: Mode,
49 state_after: &str,
50 mode_after: Mode,
51 ) {
52 self.cx.assert_binding(
53 self.keystrokes_under_test,
54 initial_state,
55 mode_before,
56 state_after,
57 mode_after,
58 );
59 }
60
61 pub async fn assert_all(&mut self, marked_positions: &str) {
62 self.cx
63 .assert_binding_matches_all(self.keystrokes_under_test, marked_positions)
64 .await
65 }
66}
67
68impl<'a, const COUNT: usize> Deref for NeovimBackedBindingTestContext<'a, COUNT> {
69 type Target = NeovimBackedTestContext<'a>;
70
71 fn deref(&self) -> &Self::Target {
72 &self.cx
73 }
74}
75
76impl<'a, const COUNT: usize> DerefMut for NeovimBackedBindingTestContext<'a, COUNT> {
77 fn deref_mut(&mut self) -> &mut Self::Target {
78 &mut self.cx
79 }
80}