package communication import ( "reflect" "testing" ) func TestUnslip(t *testing.T) { input := []byte{ 0xFF, 0x12, SLIP_END, 0xFF, SLIP_ESC, SLIP_ESC_END, 0x12, SLIP_END, 0xFF, SLIP_ESC, SLIP_ESC_ESC, 0x12, SLIP_END, } output := [][]byte{ {0xFF, 0x12}, {0xFF, SLIP_END, 0x12}, {0xFF, SLIP_ESC, 0x12}, } bytes := make(chan byte) frames := make(chan []byte) go func() { for _, v := range input { bytes <- v } }() go func() { for { frames <- unslip(bytes) } }() for _, v := range output { frame := <-frames if !reflect.DeepEqual(frame, v) { t.Fatalf("Frame '%v' does not match expected '%v'\n", frame, v); } } }