File: dec_go1_2_test.go

package info (click to toggle)
golang-gopkg-inf.v0 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-proposed-updates, sid
  • size: 128 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 677 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// +build go1.2

package inf

import (
	"encoding"
	"encoding/json"
	"testing"
)

var _ encoding.TextMarshaler = new(Dec)
var _ encoding.TextUnmarshaler = new(Dec)

type Obj struct {
	Val *Dec
}

func TestDecJsonMarshalUnmarshal(t *testing.T) {
	o := Obj{Val: NewDec(123, 2)}
	js, err := json.Marshal(o)
	if err != nil {
		t.Fatalf("json.Marshal(%v): got %v, want ok", o, err)
	}
	o2 := &Obj{}
	err = json.Unmarshal(js, o2)
	if err != nil {
		t.Fatalf("json.Unmarshal(%#q): got %v, want ok", js, err)
	}
	if o.Val.Scale() != o2.Val.Scale() ||
		o.Val.UnscaledBig().Cmp(o2.Val.UnscaledBig()) != 0 {
		t.Fatalf("json.Unmarshal(json.Marshal(%v)): want %v, got %v", o, o, o2)
	}
}