From 0311fc56a36f9f1c3850b6e022fc23ffb3aafb30 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 26 Mar 2023 08:37:13 -0600 Subject: [PATCH] split v01 into its own pkg --- src/device/input/parse/parser.go | 3 ++- src/device/input/parse/parser_test.go | 3 ++- .../input/parse/{ => v01}/testdata/v01.yaml | 0 src/device/input/parse/{ => v01}/v01.go | 2 +- .../parse/{ => v01}/v01_exported_test.go | 24 ++++++++++++------- src/device/input/parse/{ => v01}/v01_test.go | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) rename src/device/input/parse/{ => v01}/testdata/v01.yaml (100%) rename src/device/input/parse/{ => v01}/v01.go (99%) rename src/device/input/parse/{ => v01}/v01_exported_test.go (86%) rename src/device/input/parse/{ => v01}/v01_test.go (98%) diff --git a/src/device/input/parse/parser.go b/src/device/input/parse/parser.go index 4d27bbf..d81c7bb 100644 --- a/src/device/input/parse/parser.go +++ b/src/device/input/parse/parser.go @@ -3,6 +3,7 @@ package parse import ( "context" "mayhem-party/src/device/input/button" + v01 "mayhem-party/src/device/input/parse/v01" "mayhem-party/src/device/input/raw" "os" ) @@ -19,7 +20,7 @@ type Parser interface { func New(ctx context.Context, src raw.Raw) Parser { if FlagParseV01 { - return NewV01(ctx, src) + return v01.NewV01(ctx, src) } return NewPlaintext(src) } diff --git a/src/device/input/parse/parser_test.go b/src/device/input/parse/parser_test.go index f7676a4..9b2f79c 100644 --- a/src/device/input/parse/parser_test.go +++ b/src/device/input/parse/parser_test.go @@ -2,10 +2,11 @@ package parse_test import ( "mayhem-party/src/device/input/parse" + v01 "mayhem-party/src/device/input/parse/v01" "testing" ) func TestParser(t *testing.T) { var _ parse.Parser = parse.Plaintext{} - var _ parse.Parser = &parse.V01{} + var _ parse.Parser = &v01.V01{} } diff --git a/src/device/input/parse/testdata/v01.yaml b/src/device/input/parse/v01/testdata/v01.yaml similarity index 100% rename from src/device/input/parse/testdata/v01.yaml rename to src/device/input/parse/v01/testdata/v01.yaml diff --git a/src/device/input/parse/v01.go b/src/device/input/parse/v01/v01.go similarity index 99% rename from src/device/input/parse/v01.go rename to src/device/input/parse/v01/v01.go index 529162c..2b84a6d 100644 --- a/src/device/input/parse/v01.go +++ b/src/device/input/parse/v01/v01.go @@ -1,4 +1,4 @@ -package parse +package v01 import ( "context" diff --git a/src/device/input/parse/v01_exported_test.go b/src/device/input/parse/v01/v01_exported_test.go similarity index 86% rename from src/device/input/parse/v01_exported_test.go rename to src/device/input/parse/v01/v01_exported_test.go index 7c44ba4..26ebdb3 100644 --- a/src/device/input/parse/v01_exported_test.go +++ b/src/device/input/parse/v01/v01_exported_test.go @@ -1,11 +1,11 @@ -package parse_test +package v01_test import ( "context" "fmt" "io" "mayhem-party/src/device/input/button" - "mayhem-party/src/device/input/parse" + v01 "mayhem-party/src/device/input/parse/v01" "net/http" "os" "path" @@ -17,7 +17,7 @@ import ( func TestV01(t *testing.T) { src := constSrc(fmt.Sprintf(`{"T":%v,"U":"bel","Y":"abc","N":"cde"}`, time.Now().UnixNano()/int64(time.Millisecond)-50)) t.Logf("(%v) %s", len(src), src.Read()) - v01 := parse.NewV01(context.Background(), src) + v01 := v01.NewV01(context.Background(), src) defer v01.Close() got := v01.Read() want := []button.Button{ @@ -51,10 +51,10 @@ func TestV01WithCfg(t *testing.T) { - transformation: w: i `), os.ModePerm) - parse.FlagParseV01Config = p + v01.FlagParseV01Config = p t.Run("unknown user ignored", func(t *testing.T) { - v01 := parse.NewV01(context.Background(), constSrc(`{"U":"qt","Y":"w"}`)) + v01 := v01.NewV01(context.Background(), constSrc(`{"U":"qt","Y":"w"}`)) defer v01.Close() got := v01.Read() if len(got) != 0 { @@ -63,7 +63,7 @@ func TestV01WithCfg(t *testing.T) { }) t.Run("player2", func(t *testing.T) { - v01 := parse.NewV01(context.Background(), constSrc(`{"U":"bel","Y":"w","N":"w"}`)) + v01 := v01.NewV01(context.Background(), constSrc(`{"U":"bel","Y":"w","N":"w"}`)) defer v01.Close() got := v01.Read() if len(got) != 2 { @@ -96,11 +96,11 @@ func TestV01Feedback(t *testing.T) { - transformation: w: i `), os.ModePerm) - parse.FlagParseV01Config = p + v01.FlagParseV01Config = p ctx, can := context.WithCancel(context.Background()) defer can() - v01 := parse.NewV01(ctx, constSrc(`{"U":"qt","Y":"w"}`)) + v01 := v01.NewV01(ctx, constSrc(`{"U":"qt","Y":"w"}`)) defer v01.Close() for { @@ -157,3 +157,11 @@ func TestV01Feedback(t *testing.T) { } }) } + +type constSrc string + +func (c constSrc) Close() {} + +func (c constSrc) Read() []byte { + return []byte(c) +} diff --git a/src/device/input/parse/v01_test.go b/src/device/input/parse/v01/v01_test.go similarity index 98% rename from src/device/input/parse/v01_test.go rename to src/device/input/parse/v01/v01_test.go index 42dd776..b81d3e1 100644 --- a/src/device/input/parse/v01_test.go +++ b/src/device/input/parse/v01/v01_test.go @@ -1,4 +1,4 @@ -package parse +package v01 import ( "testing"