OLD | NEW |
(Empty) | |
| 1 package model |
| 2 |
| 3 import ( |
| 4 "encoding/json" |
| 5 "testing" |
| 6 |
| 7 . "github.com/smartystreets/goconvey/convey" |
| 8 ) |
| 9 |
| 10 func TestCommon(t *testing.T) { |
| 11 t.Parallel() |
| 12 |
| 13 Convey("Number", t, func() { |
| 14 Convey("UnmarshalJSON", func() { |
| 15 Convey("fails on non integers", func() { |
| 16 Convey("string", func() { |
| 17 input := []byte("foo") |
| 18 var num Number |
| 19 So(json.Unmarshal(input, &num), ShouldNo
tBeNil) |
| 20 }) |
| 21 |
| 22 Convey("float", func() { |
| 23 input := []byte("2.0") |
| 24 var num Number |
| 25 So(json.Unmarshal(input, &num), ShouldNo
tBeNil) |
| 26 }) |
| 27 }) |
| 28 |
| 29 Convey("succeeds for integer", func() { |
| 30 input := []byte("-400") |
| 31 var num Number |
| 32 So(json.Unmarshal(input, &num), ShouldBeNil) |
| 33 So(num, ShouldEqual, -400) |
| 34 }) |
| 35 }) |
| 36 |
| 37 Convey("MarshalJSON", func() { |
| 38 Convey("basic", func() { |
| 39 num := Number(-400) |
| 40 b, err := json.Marshal(&num) |
| 41 So(err, ShouldBeNil) |
| 42 So(string(b), ShouldEqual, "-400") |
| 43 }) |
| 44 }) |
| 45 }) |
| 46 } |
OLD | NEW |