-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtype_test.go
63 lines (57 loc) · 1.17 KB
/
type_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package openapi
import (
"fmt"
"testing"
"gopkg.in/yaml.v3"
)
func TestTypesUnmarshalYAML(t *testing.T) {
single := `string`
multi := `
- string
- number
`
var st Types
err := yaml.Unmarshal([]byte(single), &st)
if err != nil {
t.Error(err)
}
if len(st) != 1 {
t.Errorf("expected 1 type, got %d", len(st))
}
if st[0] != TypeString {
t.Errorf("expected %q, got %q", TypeString, st[0])
}
var mt Types
err = yaml.Unmarshal([]byte(multi), &mt)
if err != nil {
t.Error(err)
}
if len(mt) != 2 {
t.Errorf("expected 2 types, got %d", len(mt))
}
if mt[0] != TypeString {
t.Errorf("expected %q, got %q", TypeString, mt[0])
}
if mt[1] != TypeNumber {
t.Errorf("expected %q, got %q", TypeNumber, mt[1])
}
}
func TestTypesMarshalYAML(t *testing.T) {
st := Types{TypeString}
b, err := yaml.Marshal(st)
if err != nil {
t.Error(err)
}
if string(b) != "string\n" {
t.Errorf("expected %q, got %q", "string", string(b))
}
mt := Types{TypeString, TypeNumber}
b, err = yaml.Marshal(mt)
if err != nil {
t.Error(err)
}
fmt.Println(string(b))
if string(b) != "- string\n- number\n" {
t.Errorf("expected %q, got %q", "- string\n- number", string(b))
}
}