From 8bbb84da85f3a50fc1ccde84867ba76d2ddaf8c5 Mon Sep 17 00:00:00 2001 From: Anna Rose Wiggins Date: Sat, 12 Jul 2025 17:55:44 -0400 Subject: [PATCH] Add some additional tests for AxisToButton. --- .../mapping_rule_axis_to_button_test.go | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/mappingrules/mapping_rule_axis_to_button_test.go b/internal/mappingrules/mapping_rule_axis_to_button_test.go index a79f64f..5a3193b 100644 --- a/internal/mappingrules/mapping_rule_axis_to_button_test.go +++ b/internal/mappingrules/mapping_rule_axis_to_button_test.go @@ -1,6 +1,9 @@ package mappingrules import ( + "testing" + "time" + "github.com/holoplot/go-evdev" "github.com/stretchr/testify/suite" ) @@ -51,9 +54,34 @@ func (t *MappingRuleAxisToButtonTests) TestMatchEvent() { }, t.mode) t.Equal(NoNextEvent, testRule.nextEvent) - // TODO: more tests here... check repeats + testRule = NewMappingRuleAxisToButton(t.base, t.inputRule, t.outputRule, 750, 250) + testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{ + Type: evdev.EV_ABS, + Code: evdev.ABS_X, + Value: 10000, + }, t.mode) + t.Equal(time.Duration(250*time.Millisecond), testRule.nextEvent) + + testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{ + Type: evdev.EV_ABS, + Code: evdev.ABS_X, + Value: 1001, + }, t.mode) + t.True(testRule.nextEvent > time.Duration(700*time.Millisecond)) + + testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{ + Type: evdev.EV_ABS, + Code: evdev.ABS_X, + Value: 5500, + }, t.mode) + t.Equal(time.Duration(500*time.Millisecond), testRule.nextEvent) } -func (t *MappingRuleAxisToButtonTests) TestTimerEvent() { - // STUB +// TODO: to add TimerEvent tests we need to use an interface to mock time. +// func (t *MappingRuleAxisToButtonTests) TestTimerEvent() { +// // STUB +// } + +func TestRunnerMappingRuleAxisToButtonTests(t *testing.T) { + suite.Run(t, new(MappingRuleAxisToButtonTests)) }