github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/encoding/plain/plain_test.go (about) 1 package plain_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/vc42/parquet-go/encoding/plain" 8 ) 9 10 func TestAppendBoolean(t *testing.T) { 11 values := []byte{} 12 13 for i := 0; i < 100; i++ { 14 values = plain.AppendBoolean(values, i, (i%2) != 0) 15 } 16 17 if !bytes.Equal(values, []byte{ 18 0b10101010, 19 0b10101010, 20 0b10101010, 21 0b10101010, 22 0b10101010, 23 0b10101010, 24 0b10101010, 25 0b10101010, 26 0b10101010, 27 0b10101010, 28 0b10101010, 29 0b10101010, 30 0b00001010, 31 }) { 32 t.Errorf("%08b\n", values) 33 } 34 } 35 36 func TestValidateByteArray(t *testing.T) { 37 t.Run("ok", func(t *testing.T) { 38 var b []byte 39 b = plain.AppendByteArrayString(b, "Hello") 40 b = plain.AppendByteArrayString(b, "World") 41 b = plain.AppendByteArrayString(b, "!") 42 43 if err := plain.ValidateByteArray(b); err != nil { 44 t.Error(err) 45 } 46 }) 47 48 t.Run("errTooShort", func(t *testing.T) { 49 var b []byte 50 b = plain.AppendByteArrayString(b, "Hello") 51 b = plain.AppendByteArrayString(b, "World") 52 b = plain.AppendByteArrayString(b, "!") 53 54 if plain.ValidateByteArray(b[:len(b)-1]) == nil { 55 t.Error("expected non-nil error") 56 } 57 }) 58 }