neovim_backed_binding_test_context.rs

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