split out xform
parent
4c7f444887
commit
e1e2ce3eec
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue