From 649fb5e377fe5d39c8fbf734405060aa913d0556 Mon Sep 17 00:00:00 2001 From: Anna Rose Wiggins Date: Fri, 4 Jul 2025 20:28:38 -0400 Subject: [PATCH] An single test. --- internal/mappingrules/matching_test.go | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 internal/mappingrules/matching_test.go diff --git a/internal/mappingrules/matching_test.go b/internal/mappingrules/matching_test.go new file mode 100644 index 0000000..e7e6e3b --- /dev/null +++ b/internal/mappingrules/matching_test.go @@ -0,0 +1,66 @@ +package mappingrules + +import ( + "testing" + + "github.com/holoplot/go-evdev" +) + +func TestSimpleRuleMatchEvent(t *testing.T) { + inputDevice := &evdev.InputDevice{} + wrongInputDevice := &evdev.InputDevice{} + outputDevice := &evdev.InputDevice{} + + rule := &SimpleMappingRule{ + MappingRuleBase: MappingRuleBase{ + Output: &RuleTargetButton{ + RuleTargetBase{ + DeviceName: "test_output", + Device: outputDevice, + Code: evdev.BTN_TRIGGER, + }, + }, + Modes: []string{"*"}, + }, + Input: &RuleTargetButton{ + RuleTargetBase{ + DeviceName: "test_input", + Device: inputDevice, + Code: evdev.BTN_TRIGGER, + }, + }, + } + mode := "*" + + // A matching input event should produce an output event + event := rule.MatchEvent(inputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode) + outputEvent := &evdev.InputEvent{ + Type: evdev.EV_KEY, + Code: evdev.BTN_TRIGGER, + Value: 1, + } + + if event == nil || *event != *outputEvent { + t.Errorf("Expected event to match %v, but got %v", outputEvent, event) + } + + // if event.Type != outputEvent.Type || + // event.Code != outputEvent.Code || + // event.Value != outputEvent.Value { + // t.Errorf("Expected event to match %v, but got %v", outputEvent, event) + // } + + // An input event from the wrong device should produce a nil event + event = rule.MatchEvent(wrongInputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode) + if event != nil { + t.Errorf("Expected event not to match, but got non-nil event %v", event) + } + + // An input event from the wrong device should produce a nil event + event = rule.MatchEvent(wrongInputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode) + if event != nil { + t.Errorf("Expected event not to match, but got non-nil event %v", event) + } + + // TODO: test inversion, and everything else... +}