split v01 into its own pkg
parent
9902684990
commit
0311fc56a3
|
|
@ -3,6 +3,7 @@ package parse
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"mayhem-party/src/device/input/button"
|
"mayhem-party/src/device/input/button"
|
||||||
|
v01 "mayhem-party/src/device/input/parse/v01"
|
||||||
"mayhem-party/src/device/input/raw"
|
"mayhem-party/src/device/input/raw"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
@ -19,7 +20,7 @@ type Parser interface {
|
||||||
|
|
||||||
func New(ctx context.Context, src raw.Raw) Parser {
|
func New(ctx context.Context, src raw.Raw) Parser {
|
||||||
if FlagParseV01 {
|
if FlagParseV01 {
|
||||||
return NewV01(ctx, src)
|
return v01.NewV01(ctx, src)
|
||||||
}
|
}
|
||||||
return NewPlaintext(src)
|
return NewPlaintext(src)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ package parse_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mayhem-party/src/device/input/parse"
|
"mayhem-party/src/device/input/parse"
|
||||||
|
v01 "mayhem-party/src/device/input/parse/v01"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
func TestParser(t *testing.T) {
|
||||||
var _ parse.Parser = parse.Plaintext{}
|
var _ parse.Parser = parse.Plaintext{}
|
||||||
var _ parse.Parser = &parse.V01{}
|
var _ parse.Parser = &v01.V01{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package parse
|
package v01
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package parse_test
|
package v01_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mayhem-party/src/device/input/button"
|
"mayhem-party/src/device/input/button"
|
||||||
"mayhem-party/src/device/input/parse"
|
v01 "mayhem-party/src/device/input/parse/v01"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
func TestV01(t *testing.T) {
|
func TestV01(t *testing.T) {
|
||||||
src := constSrc(fmt.Sprintf(`{"T":%v,"U":"bel","Y":"abc","N":"cde"}`, time.Now().UnixNano()/int64(time.Millisecond)-50))
|
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())
|
t.Logf("(%v) %s", len(src), src.Read())
|
||||||
v01 := parse.NewV01(context.Background(), src)
|
v01 := v01.NewV01(context.Background(), src)
|
||||||
defer v01.Close()
|
defer v01.Close()
|
||||||
got := v01.Read()
|
got := v01.Read()
|
||||||
want := []button.Button{
|
want := []button.Button{
|
||||||
|
|
@ -51,10 +51,10 @@ func TestV01WithCfg(t *testing.T) {
|
||||||
- transformation:
|
- transformation:
|
||||||
w: i
|
w: i
|
||||||
`), os.ModePerm)
|
`), os.ModePerm)
|
||||||
parse.FlagParseV01Config = p
|
v01.FlagParseV01Config = p
|
||||||
|
|
||||||
t.Run("unknown user ignored", func(t *testing.T) {
|
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()
|
defer v01.Close()
|
||||||
got := v01.Read()
|
got := v01.Read()
|
||||||
if len(got) != 0 {
|
if len(got) != 0 {
|
||||||
|
|
@ -63,7 +63,7 @@ func TestV01WithCfg(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("player2", func(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()
|
defer v01.Close()
|
||||||
got := v01.Read()
|
got := v01.Read()
|
||||||
if len(got) != 2 {
|
if len(got) != 2 {
|
||||||
|
|
@ -96,11 +96,11 @@ func TestV01Feedback(t *testing.T) {
|
||||||
- transformation:
|
- transformation:
|
||||||
w: i
|
w: i
|
||||||
`), os.ModePerm)
|
`), os.ModePerm)
|
||||||
parse.FlagParseV01Config = p
|
v01.FlagParseV01Config = p
|
||||||
ctx, can := context.WithCancel(context.Background())
|
ctx, can := context.WithCancel(context.Background())
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
v01 := parse.NewV01(ctx, constSrc(`{"U":"qt","Y":"w"}`))
|
v01 := v01.NewV01(ctx, constSrc(`{"U":"qt","Y":"w"}`))
|
||||||
defer v01.Close()
|
defer v01.Close()
|
||||||
|
|
||||||
for {
|
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)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package parse
|
package v01
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
Loading…
Reference in New Issue