Repository: goccy/go-yaml (go)

Issue:
Parsing JSON is whitespace-dependent
When a YAML contains a JSON object that's formatted without whitespace, for example `{"name":"John"}`, the parser gives the following error:
```
[1:2] failed to parse flow mapping value node
    >  1 | {"name":"John"}
```

This does not happen when fields are separated by a space, i.e. `{"name": "John"}`

Playground: https://goplay.space/#5xOT86HOV2L

Pull request description:
Fix processing of mapping value delimiter in flow style
fix #142 

Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index 3a6fbe0..5a379a5 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -625,7 +625,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
 			}
 		case ':':
 			nc := ctx.nextChar()
-			if nc == ' ' || s.isNewLineChar(nc) || ctx.isNextEOS() {
+			if s.startedFlowMapNum > 0 || nc == ' ' || s.isNewLineChar(nc) || ctx.isNextEOS() {
 				// mapping value
 				tk := s.bufferedToken(ctx)
 				if tk != nil {


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index c0451f1..dbd2cc6 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -9,7 +9,6 @@ import (
 	"github.com/goccy/go-yaml/ast"
 	"github.com/goccy/go-yaml/lexer"
 	"github.com/goccy/go-yaml/parser"
-	"github.com/goccy/go-yaml/printer"
 )
 
 func TestParser(t *testing.T) {
@@ -69,17 +68,12 @@ func TestParser(t *testing.T) {
 		"v: |-\n  0\n",
 		"v: |-\n  0\nx: 0",
 		`"a\n1\nb"`,
+		`{"a":"b"}`,
 	}
 	for _, src := range sources {
-		fmt.Printf(src)
-		tokens := lexer.Tokenize(src)
-		var printer printer.Printer
-		fmt.Println(printer.PrintTokens(tokens))
-		ast, err := parser.Parse(tokens, 0)
-		if err != nil {
-			t.Fatalf("%+v", err)
+		if _, err := parser.Parse(lexer.Tokenize(src), 0); err != nil {
+			t.Fatalf("parse error: source [%s]: %+v", src, err)
 		}
-		fmt.Printf("%+v\n", ast)
 	}
 }
 
@@ -547,7 +541,6 @@ b: c
 	}
 	for _, test := range tests {
 		tokens := lexer.Tokenize(test.source)
-		tokens.Dump()
 		f, err := parser.Parse(tokens, 0)
 		if err != nil {
 			t.Fatalf("%+v", err)
@@ -558,6 +551,7 @@ b: c
 		}
 		expect := fmt.Sprintf("\n%+v\n", f)
 		if test.expect != expect {
+			tokens.Dump()
 			t.Fatalf("unexpected output: [%s] != [%s]", test.expect, expect)
 		}
 	}
@@ -592,7 +586,18 @@ func TestSyntaxError(t *testing.T) {
 		if err == nil {
 			t.Fatal("cannot catch syntax error")
 		}
-		fmt.Printf("%v\n", err)
+		expected := `
+[2:3] unexpected key name
+   1 | a:
+>  2 | - b
+   3 |   c: d
+         ^
+   4 |   e: f
+   5 |   g: h`
+		actual := "\n" + err.Error()
+		if expected != actual {
+			t.Fatalf("expected: [%s] but got [%s]", expected, actual)
+		}
 	}
 }