mirror of https://github.com/periph/devices
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
// Copyright 2026 The Periph Authors. All rights reserved.
|
|
// Use of this source code is governed under the Apache License, Version 2.0
|
|
// that can be found in the LICENSE file.
|
|
|
|
package sen6x
|
|
|
|
import "testing"
|
|
|
|
func TestClen(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
b []byte
|
|
want int
|
|
}{
|
|
{
|
|
name: "nil",
|
|
b: nil,
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "empty",
|
|
b: []byte{},
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "null byte at end",
|
|
b: []byte{0xaa, 0xbb, 0xcc, 0x0},
|
|
want: 3,
|
|
},
|
|
{
|
|
name: "null byte in middle",
|
|
b: []byte{0xaa, 0xbb, 0x00, 0xcc},
|
|
want: 2,
|
|
},
|
|
{
|
|
name: "null byte at start",
|
|
b: []byte{0x00, 0xaa, 0xbb, 0xcc},
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "multiple null bytes",
|
|
b: []byte{0xaa, 0x00, 0x00, 0xbb},
|
|
want: 1,
|
|
},
|
|
{
|
|
name: "no null byte",
|
|
b: []byte{0xaa, 0xbb, 0xcc, 0xdd, 0xee},
|
|
want: 5,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := clen(tc.b)
|
|
if got != tc.want {
|
|
t.Errorf("got %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|