Files
deckrotate/cmd/deckrotate/cli_test.go
T
Ziad ArafatandClaude Opus 5.5 81d2a986b6 Add deckrotate: Steam Deck screen rotation for Plasma
Go daemon reads the controller's accelerometer from hidraw (re-enabling
the IMU that Steam switches off), debounces it into an orientation and
rotates eDP-1 through kscreen-doctor in auto mode, or offers a
layer-shell tap-to-rotate button in manual mode, with a persistent lock.

Includes a D-Bus service, a CLI for global shortcuts (kglobalaccel
service file), a Plasma system tray applet, a systemd user unit and
hardware notes from probing the Deck OLED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:18:17 -07:00

54 lines
1.6 KiB
Go

package main
import (
"reflect"
"strings"
"testing"
)
func TestParseCommand(t *testing.T) {
cases := []struct {
args string
method string
params []any
}{
{"lock", "SetLocked", []any{true}},
{"unlock", "SetLocked", []any{false}},
{"toggle-lock", "ToggleLock", nil},
{"mode auto", "SetMode", []any{"auto"}},
{"mode manual", "SetMode", []any{"manual"}},
{"mode toggle", "ToggleMode", nil},
{"rotate cw", "RotateBy", []any{int32(1)}},
{"rotate ccw", "RotateBy", []any{int32(-1)}},
{"rotate flip", "RotateBy", []any{int32(2)}},
{"rotate landscape", "RotateTo", []any{"landscape"}},
{"rotate portrait-cw", "RotateTo", []any{"portrait-cw"}},
{"rotate portrait-ccw", "RotateTo", []any{"portrait-ccw"}},
{"rotate landscape-flipped", "RotateTo", []any{"landscape-flipped"}},
{"accept", "Accept", nil},
{"dismiss", "Dismiss", nil},
}
for _, c := range cases {
m, p, err := parseCommand(strings.Fields(c.args))
if err != nil || m != c.method || !reflect.DeepEqual(p, c.params) {
t.Errorf("parseCommand(%q) = %q %v %v; want %q %v", c.args, m, p, err, c.method, c.params)
}
}
}
func TestParseCommandErrors(t *testing.T) {
for _, args := range []string{"", "spin", "mode", "mode sometimes", "rotate", "rotate diagonal", "lock now"} {
if _, _, err := parseCommand(strings.Fields(args)); err == nil {
t.Errorf("parseCommand(%q) should fail", args)
}
}
}
func TestFormatStatus(t *testing.T) {
got := formatStatus(statusFixture)
want := "mode: manual\nlocked: yes\ndevice: portrait-cw\nscreen: landscape\nsuggested: portrait-cw\nimu: ok\n"
if got != want {
t.Errorf("formatStatus =\n%s\nwant\n%s", got, want)
}
}