1use std::ops::{Deref, DerefMut};
2
3use crate::state::Mode;
4
5use super::{ExemptionFeatures, NeovimBackedTestContext, SUPPORTED_FEATURES};
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 async fn assert_exempted(&mut self, marked_positions: &str, feature: ExemptionFeatures) {
41 if SUPPORTED_FEATURES.contains(&feature) {
42 self.cx
43 .assert_binding_matches(self.keystrokes_under_test, marked_positions)
44 .await
45 }
46 }
47
48 pub fn assert_manual(
49 &mut self,
50 initial_state: &str,
51 mode_before: Mode,
52 state_after: &str,
53 mode_after: Mode,
54 ) {
55 self.cx.assert_binding(
56 self.keystrokes_under_test,
57 initial_state,
58 mode_before,
59 state_after,
60 mode_after,
61 );
62 }
63
64 pub async fn assert_all(&mut self, marked_positions: &str) {
65 self.cx
66 .assert_binding_matches_all(self.keystrokes_under_test, marked_positions)
67 .await
68 }
69
70 pub async fn assert_all_exempted(
71 &mut self,
72 marked_positions: &str,
73 feature: ExemptionFeatures,
74 ) {
75 if SUPPORTED_FEATURES.contains(&feature) {
76 self.cx
77 .assert_binding_matches_all(self.keystrokes_under_test, marked_positions)
78 .await
79 }
80 }
81}
82
83impl<'a, const COUNT: usize> Deref for NeovimBackedBindingTestContext<'a, COUNT> {
84 type Target = NeovimBackedTestContext<'a>;
85
86 fn deref(&self) -> &Self::Target {
87 &self.cx
88 }
89}
90
91impl<'a, const COUNT: usize> DerefMut for NeovimBackedBindingTestContext<'a, COUNT> {
92 fn deref_mut(&mut self) -> &mut Self::Target {
93 &mut self.cx
94 }
95}