summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-23 14:15:43 +0200
committerPaul Buetow <paul@buetow.org>2025-03-23 14:15:43 +0200
commitd4738888bc71e7aaa45d911b3fc3e3f6905ce9fd (patch)
treec2afa69389aa80ecea79ff787085f99439469c38
parentacb50fbc6f5ea2b97613593c7aea21304f3fb459 (diff)
initial unit test
-rw-r--r--internal/file/file.go1
-rw-r--r--internal/file/file_test.go14
2 files changed, 14 insertions, 1 deletions
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))
+ }
+}