Add tests

This commit is contained in:
andig 2020-05-28 11:37:59 +02:00
parent 2d1b7a32fc
commit 0309f19ff9

View file

@ -0,0 +1,30 @@
package modbus
import "testing"
func TestParsePoint(t *testing.T) {
tc := []struct {
in string
model, block int
point string
err bool
}{
{"103:W", 103, 0, "W", false},
{"802:1:V", 802, 1, "V", false},
{"802::V", 802, 1, "V", true},
}
for _, tc := range tc {
t.Log(tc)
model, block, point, err := ParsePoint(tc.in)
if (err != nil) != tc.err {
t.Errorf("unexpected error: %d:%d:%s %v", model, block, point, err)
}
if !tc.err && (model != tc.model || block != tc.block || point != tc.point) {
t.Errorf("unexpected result: %d:%d:%s", model, block, point)
}
}
}