Add some additional tests for AxisToButton.

This commit is contained in:
Anna Rose Wiggins 2025-07-12 17:55:44 -04:00
parent ed2627e113
commit 8bbb84da85

View file

@ -1,6 +1,9 @@
package mappingrules package mappingrules
import ( import (
"testing"
"time"
"github.com/holoplot/go-evdev" "github.com/holoplot/go-evdev"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
@ -51,9 +54,34 @@ func (t *MappingRuleAxisToButtonTests) TestMatchEvent() {
}, t.mode) }, t.mode)
t.Equal(NoNextEvent, testRule.nextEvent) 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() { // TODO: to add TimerEvent tests we need to use an interface to mock time.
// STUB // func (t *MappingRuleAxisToButtonTests) TestTimerEvent() {
// // STUB
// }
func TestRunnerMappingRuleAxisToButtonTests(t *testing.T) {
suite.Run(t, new(MappingRuleAxisToButtonTests))
} }