Skip to content

Commit

Permalink
Merge pull request #322 from goccy/fix-context-reuse
Browse files Browse the repository at this point in the history
Fix resusing process of scanning context
  • Loading branch information
goccy committed Nov 14, 2022
2 parents 33858b4 + 937c167 commit 7b77440
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions decode_test.go
Expand Up @@ -2732,3 +2732,52 @@ bar:
}
})
}

func TestUnmarshalMapSliceParallel(t *testing.T) {
content := `
steps:
req0:
desc: Get /users/1
req:
/users/1:
get: nil
test: |
current.res.status == 200
req1:
desc: Get /private
req:
/private:
get: nil
test: |
current.res.status == 403
req2:
desc: Get /users
req:
/users:
get: nil
test: |
current.res.status == 200
`
type mappedSteps struct {
Steps yaml.MapSlice `yaml:"steps,omitempty"`
}
for i := 0; i < 100; i++ {
t.Run(fmt.Sprintf("i=%d", i), func(t *testing.T) {
t.Parallel()
for i := 0; i < 10; i++ {
m := mappedSteps{
Steps: yaml.MapSlice{},
}
if err := yaml.Unmarshal([]byte(content), &m); err != nil {
t.Fatal(err)
}
for _, s := range m.Steps {
_, ok := s.Value.(map[string]interface{})
if !ok {
t.Fatal("unexpected error")
}
}
}
})
}
}
4 changes: 4 additions & 0 deletions scanner/context.go
Expand Up @@ -55,7 +55,11 @@ func (c *Context) reset(src []rune) {
c.src = src
c.tokens = c.tokens[:0]
c.resetBuffer()
c.isRawFolded = false
c.isSingleLine = true
c.isLiteral = false
c.isFolded = false
c.literalOpt = ""
}

func (c *Context) resetBuffer() {
Expand Down

0 comments on commit 7b77440

Please sign in to comment.