Skip to content

Commit 9d85c85

Browse files
committed
test: add unit tests for stripUTF8BOM
1 parent b36b87a commit 9d85c85

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/arduino/builder/sketch_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,22 @@ func TestCopyAdditionalFiles(t *testing.T) {
106106
require.NoError(t, err)
107107
require.Equal(t, info1.ModTime(), info2.ModTime())
108108
}
109+
110+
func TestStripUTF8BOM(t *testing.T) {
111+
// Case 1: Input with BOM
112+
inputWithBOM := []byte{0xEF, 0xBB, 0xBF, 'H', 'e', 'l', 'l', 'o'}
113+
expected := []byte("Hello")
114+
115+
output := stripUTF8BOM(inputWithBOM)
116+
require.Equal(t, expected, output, "BOM should be stripped")
117+
118+
// Case 2: Input without BOM
119+
inputNoBOM := []byte("Hello")
120+
outputNoBOM := stripUTF8BOM(inputNoBOM)
121+
require.Equal(t, inputNoBOM, outputNoBOM, "Input without BOM should remain unchanged")
122+
123+
// Case 3: Input shorter than 3 bytes (edge case)
124+
shortInput := []byte{0xEF}
125+
outputShort := stripUTF8BOM(shortInput)
126+
require.Equal(t, shortInput, outputShort, "Short input should remain unchanged")
127+
}

0 commit comments

Comments
 (0)