-
Notifications
You must be signed in to change notification settings - Fork 121
/
numbers_test.go
46 lines (37 loc) · 1.2 KB
/
numbers_test.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
package openrtb_test
import (
"encoding/json"
"testing"
. "github.com/bsm/openrtb/v3"
)
func TestNumberOrString(t *testing.T) {
var v NumberOrString
if err := json.Unmarshal([]byte(`33`), &v); err != nil {
t.Errorf("expected no error, got %v", err)
} else if exp := NumberOrString(33); exp != v {
t.Errorf("expected %#v, got %#v", exp, v)
}
if err := json.Unmarshal([]byte(`"34"`), &v); err != nil {
t.Errorf("expected no error, got %v", err)
} else if exp := NumberOrString(34); exp != v {
t.Errorf("expected %#v, got %#v", exp, v)
}
}
func TestStringOrNumber(t *testing.T) {
var v StringOrNumber
if err := json.Unmarshal([]byte(`33`), &v); err != nil {
t.Errorf("expected no error, got %v", err)
} else if exp := StringOrNumber("33"); exp != v {
t.Errorf("expected %#v, got %#v", exp, v)
}
if err := json.Unmarshal([]byte(`"34"`), &v); err != nil {
t.Errorf("expected no error, got %v", err)
} else if exp := StringOrNumber("34"); exp != v {
t.Errorf("expected %#v, got %#v", exp, v)
}
if err := json.Unmarshal([]byte(`""`), &v); err != nil {
t.Errorf("expected no error, got %v", err)
} else if exp := StringOrNumber(""); exp != v {
t.Errorf("expected %#v, got %#v", exp, v)
}
}