github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/internal/lzss/decoder_test.go (about) 1 package lzss 2 3 import ( 4 "bytes" 5 "os" 6 "testing" 7 ) 8 9 func TestDecode(t *testing.T) { 10 tests := []struct { 11 name string 12 infile string 13 outfile string 14 }{ 15 { 16 name: "blink", 17 infile: "testdata/blink.lzss", 18 outfile: "testdata/blink.bin", 19 }, 20 { 21 name: "cloud sketch", 22 infile: "testdata/cloud.lzss", 23 outfile: "testdata/cloud.bin", 24 }, 25 { 26 name: "empty binary", 27 infile: "testdata/empty.lzss", 28 outfile: "testdata/empty.bin", 29 }, 30 } 31 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 input, err := os.ReadFile(tt.infile) 35 if err != nil { 36 t.Fatal("couldn't open test file") 37 } 38 39 want, err := os.ReadFile(tt.outfile) 40 if err != nil { 41 t.Fatal("couldn't open test file") 42 } 43 44 got := Decompress(input) 45 if !bytes.Equal(want, got) { 46 t.Error("decoding failed", want, got) 47 } 48 }) 49 } 50 }