59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package menu
|
|
|
|
import "testing"
|
|
|
|
// Example usage
|
|
type testDisplaySettings struct {
|
|
Brightness uint8 `icon:"☀️" menu:"Brightness"`
|
|
Contrast uint8 `icon:"🔆" menu:"Contrast level" step:"8"`
|
|
}
|
|
|
|
type testAudioSettings struct {
|
|
Volume uint8 `icon:"🔊" menu:"Volume" min:"1" max:"100"`
|
|
Mute bool `icon:"🔇" menu:"Mute"`
|
|
}
|
|
|
|
type testSpectrumSettings struct {
|
|
Waterfall bool `menu:"Waterfall display"`
|
|
Stereo bool `menu:"Use stereo channels"`
|
|
MinFrequency int `menu:"High pass frequency" min:"0" max:"22050" step:"50"`
|
|
MaxFrequency int `menu:"Low pass frequency" min:"0" max:"22050" step:"50"`
|
|
}
|
|
|
|
type testSettings struct {
|
|
Display testDisplaySettings `icon:"🖥️" menu:"Display"`
|
|
Audio testAudioSettings `icon:"🎧" menu:"Audio"`
|
|
Language string `icon:"🌐" menu:"Language"`
|
|
Spectrum testSpectrumSettings `menu:"Spectrum analyzer"`
|
|
Ignored float64 `menu:"-"`
|
|
}
|
|
|
|
func TestMenu(t *testing.T) {
|
|
var settings testSettings
|
|
menu, err := New(&settings, 4, nil)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Logf("menu: %#+v", menu)
|
|
}
|
|
|
|
func TestMenuNil(t *testing.T) {
|
|
_, err := New(nil, 4, nil)
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
return
|
|
}
|
|
t.Logf("expected error from nil, got %q", err)
|
|
}
|
|
|
|
func TestMenuNotPointer(t *testing.T) {
|
|
var settings testSettings
|
|
menu, err := New(settings, 4, nil)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Logf("menu: %#+v", menu)
|
|
}
|