From 37050f3d87f099fdf1ebfb0f6f66a6423f8378d7 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 26 Mar 2023 10:06:22 -0600 Subject: [PATCH] test quiet mode --- src/device/input/parse/v01/v01_test.go | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/device/input/parse/v01/v01_test.go b/src/device/input/parse/v01/v01_test.go index c21ba70..b286d82 100644 --- a/src/device/input/parse/v01/v01_test.go +++ b/src/device/input/parse/v01/v01_test.go @@ -1,6 +1,7 @@ package v01 import ( + "context" "testing" ) @@ -49,3 +50,43 @@ func TestV01TransformationPipe(t *testing.T) { }) } } + +func TestV01Quiet(t *testing.T) { + ctx, can := context.WithCancel(context.Background()) + defer can() + v01 := NewV01(ctx, constSrc(`{"Y":"a", "N":"b"}`)) + + v01.cfg.Quiet = false + if got := v01.Read(); len(got) != 2 { + t.Error(len(got)) + } else if got[0].Char != 'a' { + t.Error(got[0].Char) + } else if got[0].Down != true { + t.Error(got[0].Down) + } else if got[1].Char != 'b' { + t.Error(got[1].Char) + } else if got[1].Down != false { + t.Error(got[1].Down) + } + + v01.cfg.Quiet = true + if got := v01.Read(); len(got) != 2 { + t.Error(len(got)) + } else if got[0].Char != 'a' { + t.Error(got[0].Char) + } else if got[0].Down != false { + t.Error(got[0].Down) + } else if got[1].Char != 'b' { + t.Error(got[1].Char) + } else if got[1].Down != false { + t.Error(got[1].Down) + } +} + +type constSrc string + +func (c constSrc) Close() {} + +func (c constSrc) Read() []byte { + return []byte(c) +}