浏览代码

Reflect inf/dec changes in integration test

Ben Hood 11 年之前
父节点
当前提交
cc2dfe70ec
共有 3 个文件被更改,包括 7 次插入4 次删除
  1. 3 3
      cassandra_test.go
  2. 3 0
      marshal.go
  3. 1 1
      marshal_test.go

+ 3 - 3
cassandra_test.go

@@ -7,9 +7,9 @@ package gocql
 import (
 	"bytes"
 	"flag"
-	"math/big"
 	"reflect"
 	"sort"
+	"speter.net/go/exp/math/dec/inf"
 	"strings"
 	"sync"
 	"testing"
@@ -303,7 +303,7 @@ type Page struct {
 	Views       int64
 	Protected   bool
 	Modified    time.Time
-	Rating      *big.Rat
+	Rating      *inf.Dec
 	Tags        []string
 	Attachments map[string]Attachment
 }
@@ -315,7 +315,7 @@ var pageTestData = []*Page{
 		Title:    "Frontpage",
 		RevId:    TimeUUID(),
 		Body:     "Welcome to this wiki page!",
-		Rating:   big.NewRat(871298379, 243),
+		Rating:   inf.NewDec(871298379, 243),
 		Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
 		Tags:     []string{"start", "important", "test"},
 		Attachments: map[string]Attachment{

+ 3 - 0
marshal.go

@@ -693,6 +693,9 @@ func marshalDecimal(info *TypeInfo, value interface{}) ([]byte, error) {
 		}
 
 		unscaled := v.UnscaledBig().Bytes()
+		if len(unscaled) == 0 {
+			unscaled = []byte{0}
+		}
 		scale := v.Scale()
 		buf := make([]byte, 4+len(unscaled))
 		binary.BigEndian.PutUint32(buf, uint32(scale))

+ 1 - 1
marshal_test.go

@@ -126,7 +126,7 @@ var marshalTests = []struct {
 	{
 		&TypeInfo{Type: TypeDecimal},
 		[]byte("\x00\x00\x00\x00\x00"),
-		inf.NewDec(0, 1),
+		inf.NewDec(0, 0),
 	},
 	{
 		&TypeInfo{Type: TypeTimestamp},