-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patharray_test.go
59 lines (52 loc) · 1.22 KB
/
array_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
package jsval_test
import (
"bytes"
"strings"
"testing"
"github.com/lestrrat-go/jsschema"
"github.com/lestrrat-go/jsval"
"github.com/lestrrat-go/jsval/builder"
"github.com/stretchr/testify/assert"
)
// test against github#2
func TestArrayItemsReference(t *testing.T) {
const src = `{
"definitions": {
"uint": {
"type": "integer",
"minimum": 0
}
},
"type": "object",
"properties": {
"numbers": {
"type": "array",
"items": { "$ref": "#/definitions/uint" }
},
"tuple": {
"items": [ { "type": "string" }, { "type": "boolean" }, { "type": "number" } ]
}
}
}`
s, err := schema.Read(strings.NewReader(src))
if !assert.NoError(t, err, "schema.Reader should succeed") {
return
}
b := builder.New()
v, err := b.Build(s)
if !assert.NoError(t, err, "builder.Build should succeed") {
return
}
buf := bytes.Buffer{}
g := jsval.NewGenerator()
if !assert.NoError(t, g.Process(&buf, v), "Generator.Process should succeed") {
return
}
code := buf.String()
if !assert.True(t, strings.Contains(code, "\tItems("), "Generated code chould contain `.Items()`") {
return
}
if !assert.True(t, strings.Contains(code, "\tPositionalItems("), "Generated code should contain `.PositionalItems()`") {
return
}
}