neovim_backed_binding_test_context.rs

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