Skip to content

Commit 345783e

Browse files
add origin unit tests
1 parent a94c01f commit 345783e

File tree

2 files changed

+64
-30
lines changed

2 files changed

+64
-30
lines changed

decode_test.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ import (
2121
"fmt"
2222
"io"
2323
"math"
24-
"os"
2524
"reflect"
2625
"strings"
2726
"time"
2827

28+
yaml "github.com/oasdiff/yaml3"
2929
. "gopkg.in/check.v1"
30-
"github.com/oasdiff/yaml3"
3130
)
3231

3332
var unmarshalIntTest = 123
@@ -1742,34 +1741,6 @@ func (s *S) TestFuzzCrashers(c *C) {
17421741
}
17431742
}
17441743

1745-
func (s *S) TestLocation(c *C) {
1746-
input := `paths:
1747-
/testpath:
1748-
get:
1749-
responses:
1750-
"200":
1751-
$ref: "#/components/responses/testpath_200_response"
1752-
1753-
components:
1754-
responses:
1755-
testpath_200_response:
1756-
description: a custom response
1757-
content:
1758-
application/json:
1759-
schema:
1760-
type: string
1761-
`
1762-
dec := yaml.NewDecoder(bytes.NewBufferString(input))
1763-
dec.Origin(false)
1764-
var out any
1765-
err := dec.Decode(&out)
1766-
c.Assert(err, IsNil)
1767-
result, err := yaml.Marshal(out)
1768-
c.Assert(err, IsNil)
1769-
fo, _ := os.Create("output.yaml")
1770-
fo.Write(result)
1771-
}
1772-
17731744
//var data []byte
17741745
//func init() {
17751746
// var err error

origin_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package yaml_test
2+
3+
import (
4+
"bytes"
5+
6+
yaml "github.com/oasdiff/yaml3"
7+
. "gopkg.in/check.v1"
8+
)
9+
10+
func (s *S) TestOrigin_Disabled(c *C) {
11+
input := `
12+
root:
13+
hello: world
14+
`
15+
16+
dec := yaml.NewDecoder(bytes.NewBufferString(input[1:]))
17+
dec.Origin(false)
18+
var out any
19+
err := dec.Decode(&out)
20+
c.Assert(err, IsNil)
21+
result, err := yaml.Marshal(out)
22+
c.Assert(err, IsNil)
23+
24+
buf := new(bytes.Buffer)
25+
buf.Write(result)
26+
27+
c.Assert(buf.String(), Equals, input[1:])
28+
}
29+
30+
func (s *S) TestOrigin_Enabled(c *C) {
31+
input := `
32+
root:
33+
hello: world
34+
`
35+
36+
dec := yaml.NewDecoder(bytes.NewBufferString(input[1:]))
37+
dec.Origin(true)
38+
var out any
39+
err := dec.Decode(&out)
40+
c.Assert(err, IsNil)
41+
result, err := yaml.Marshal(out)
42+
c.Assert(err, IsNil)
43+
44+
buf := new(bytes.Buffer)
45+
buf.Write(result)
46+
47+
output := `
48+
root:
49+
hello: world
50+
origin:
51+
fields:
52+
hello:
53+
column: 5
54+
line: 2
55+
name: hello
56+
key:
57+
column: 1
58+
line: 1
59+
name: root
60+
`
61+
62+
c.Assert(buf.String(), Equals, output[1:])
63+
}

0 commit comments

Comments
 (0)