From d4738888bc71e7aaa45d911b3fc3e3f6905ce9fd Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 23 Mar 2025 14:15:43 +0200 Subject: initial unit test --- internal/file/file.go | 1 - internal/file/file_test.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 internal/file/file_test.go (limited to 'internal') diff --git a/internal/file/file.go b/internal/file/file.go index 7d9d7e8..513212b 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -155,6 +155,5 @@ func (f pathnameFile) String() string { // As data comes in from arrays, converted to slices, there will be null-bytes at the end.. func stringValue(byteStr []byte) string { - // TODO: Hopefully, this won't cause a panic when the filename is as long as the array itself. Unit test this! return string(byteStr[:bytes.IndexByte(byteStr, 0)]) } diff --git a/internal/file/file_test.go b/internal/file/file_test.go new file mode 100644 index 0000000..dc59738 --- /dev/null +++ b/internal/file/file_test.go @@ -0,0 +1,14 @@ +package file + +import ( + "testing" +) + +func TestStringValue(t *testing.T) { + var array [128]byte + copy(array[:], "test string") + + if str := stringValue(array[:]); str != "test string" { + t.Errorf("epxected 'test string' but got '%s' with bytes '%v'", str, []byte(str)) + } +} -- cgit v1.2.3