split out xform

master
bel 2023-03-26 08:39:50 -06:00
parent 4c7f444887
commit e1e2ce3eec
3 changed files with 16 additions and 12 deletions

View File

@ -0,0 +1,14 @@
package v01
type (
transformation map[string]string
)
func (t transformation) pipe(s string) string {
for i := range s {
if v := t[s[i:i+1]]; v != "" {
s = s[:i] + v[:1] + s[i+1:]
}
}
return s
}

View File

@ -40,10 +40,9 @@ type (
Message string
}
Players []struct {
Transformation v01Transformation
Transformation transformation
}
}
v01Transformation map[string]string
)
func NewV01(ctx context.Context, src raw.Raw) *V01 {
@ -98,15 +97,6 @@ func (cfg v01Cfg) transform(msg v01Msg) v01Msg {
return msg
}
func (t v01Transformation) pipe(s string) string {
for i := range s {
if v := t[s[i:i+1]]; v != "" {
s = s[:i] + v[:1] + s[i+1:]
}
}
return s
}
func (v01 *V01) telemetry(msg v01Msg) {
if FlagDebug {
log.Printf("%s|%dms", msg.U, time.Now().UnixNano()/int64(time.Millisecond)-msg.T)

View File

@ -42,7 +42,7 @@ func TestV01TransformationPipe(t *testing.T) {
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
got := v01Transformation(c.xform).pipe(c.input)
got := transformation(c.xform).pipe(c.input)
if got != c.want {
t.Errorf("%+v(%s) want %s got %s", c.xform, c.input, c.want, got)
}