@@ -705,6 +705,43 @@ func TestDecimalColumnFromStringValidation(t *testing.T) {
705705 })
706706}
707707
708+ func TestNewDecimalUnsafe (t * testing.T ) {
709+ t .Run ("trimsLeadingZeros" , func (t * testing.T ) {
710+ raw := []byte {0x00 , 0x00 , 0x01 , 0x23 }
711+ dec , err := qdb .NewDecimalUnsafe (raw , 2 )
712+ assert .NoError (t , err )
713+
714+ expected := qdb .NewDecimalFromInt64 (0x0123 , 2 )
715+ assert .Equal (t , expected , dec )
716+ })
717+
718+ t .Run ("trimsSignExtensionForNegative" , func (t * testing.T ) {
719+ raw := []byte {0xFF , 0xFF , 0xCF , 0xC7 }
720+ dec , err := qdb .NewDecimalUnsafe (raw , 3 )
721+ assert .NoError (t , err )
722+
723+ expected , err := qdb .NewDecimal (big .NewInt (- 12345 ), 3 )
724+ assert .NoError (t , err )
725+ assert .Equal (t , expected , dec )
726+ })
727+
728+ t .Run ("emptyInputProducesNullDecimal" , func (t * testing.T ) {
729+ dec , err := qdb .NewDecimalUnsafe (nil , 5 )
730+ assert .NoError (t , err )
731+
732+ buf := newTestBuffer ()
733+ err = buf .Table (testTable ).DecimalColumn ("price" , dec ).At (time.Time {}, false )
734+ assert .ErrorContains (t , err , "no symbols or columns" )
735+ assert .Empty (t , buf .Messages ())
736+ })
737+
738+ t .Run ("errorsWhenUnscaledExceeds32Bytes" , func (t * testing.T ) {
739+ tooWide := append ([]byte {0x01 }, make ([]byte , 32 )... )
740+ _ , err := qdb .NewDecimalUnsafe (tooWide , 0 )
741+ assert .ErrorContains (t , err , "exceeds 32 bytes" )
742+ })
743+ }
744+
708745func TestDecimalColumnErrors (t * testing.T ) {
709746 t .Run ("invalid scale" , func (t * testing.T ) {
710747 buf := newTestBuffer ()
0 commit comments