nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goccy/go-yaml
Pull request #178 (2020-11-12 10:18:52)

Support encoding for array type
fix https://github.com/goccy/go-yaml/issues/175



Patch:
diff --git a/encode.go b/encode.go
index d6c53d7..4d65d1a 100644
--- a/encode.go
+++ b/encode.go
@@ -276,6 +276,8 @@ func (e *Encoder) encodeValue(ctx context.Context, v reflect.Value, column int)
 			return e.encodeMapSlice(ctx, mapSlice, column)
 		}
 		return e.encodeSlice(ctx, v)
+	case reflect.Array:
+		return e.encodeArray(ctx, v)
 	case reflect.Struct:
 		if v.CanInterface() {
 			if mapItem, ok := v.Interface().(MapItem); ok {
@@ -370,6 +372,18 @@ func (e *Encoder) encodeSlice(ctx context.Context, value reflect.Value) (ast.Nod
 	return sequence, nil
 }
 
+func (e *Encoder) encodeArray(ctx context.Context, value reflect.Value) (ast.Node, error) {
+	sequence := ast.Sequence(token.New("-", "-", e.pos(e.column)), e.isFlowStyle)
+	for i := 0; i < value.Len(); i++ {
+		node, err := e.encodeValue(ctx, value.Index(i), e.column)
+		if err != nil {
+			return nil, errors.Wrapf(err, "failed to encode value for array")
+		}
+		sequence.Values = append(sequence.Values, node)
+	}
+	return sequence, nil
+}
+
 func (e *Encoder) encodeMapItem(ctx context.Context, item MapItem, column int) (*ast.MappingValueNode, error) {
 	k := reflect.ValueOf(item.Key)
 	v := reflect.ValueOf(item.Value)


Test patch:
diff --git a/encode_test.go b/encode_test.go
index 4cf4393..43d009c 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -97,6 +97,10 @@ func TestEncoder(t *testing.T) {
 			"v:\n- A\n- B\n",
 			map[string][]string{"v": {"A", "B"}},
 		},
+		{
+			"v:\n- A\n- B\n",
+			map[string][2]string{"v": {"A", "B"}},
+		},
 		{
 			"a: -\n",
 			map[string]string{"a": "-"},
Repository: goccy/go-yaml
Pull request #190 (2021-01-19 16:25:43)

Allow ending document delimiter within tag values
closes https://github.com/goccy/go-yaml/issues/189


Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index b2d718f..f1d19c7 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -551,7 +551,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
 				return
 			}
 		case '.':
-			if s.indentNum == 0 && ctx.repeatNum('.') == 3 {
+			if s.indentNum == 0 && s.column == 1 && ctx.repeatNum('.') == 3 {
 				ctx.addToken(token.DocumentEnd(s.pos()))
 				s.progressColumn(ctx, 3)
 				pos += 2
@@ -566,7 +566,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
 				return
 			}
 		case '-':
-			if s.indentNum == 0 && ctx.repeatNum('-') == 3 {
+			if s.indentNum == 0 && s.column == 1 && ctx.repeatNum('-') == 3 {
 				s.addBufferedTokenIfExists(ctx)
 				ctx.addToken(token.DocumentHeader(s.pos()))
 				s.progressColumn(ctx, 3)


Test patch:
diff --git a/decode_test.go b/decode_test.go
index 439988e..e211532 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -798,6 +798,22 @@ func TestDecoder(t *testing.T) {
 			"---\n",
 			(*struct{})(nil),
 		},
+		{
+			"...",
+			(*struct{})(nil),
+		},
+		{
+			"v: go test ./...",
+			map[string]string{"v": "go test ./..."},
+		},
+		{
+			"v: echo ---",
+			map[string]string{"v": "echo ---"},
+		},
+		{
+			"v: |\n  hello\n  ...\n  world\n",
+			map[string]string{"v": "hello\n...\nworld\n"},
+		},
 		{
 			"a: !!binary gIGC\n",
 			map[string]string{"a": "\x80\x81\x82"},
@@ -975,6 +991,33 @@ c:
 				"c": nil,
 			},
 		},
+		{
+			`---
+a: go test ./...
+b:
+c:
+`,
+			map[string]interface{}{
+				"a": "go test ./...",
+				"b": nil,
+				"c": nil,
+			},
+		},
+		{
+			`---
+a: |
+  hello
+  ...
+  world
+b:
+c:
+`,
+			map[string]interface{}{
+				"a": "hello\n...\nworld\n",
+				"b": nil,
+				"c": nil,
+			},
+		},
 
 		// Multi bytes
 		{
Repository: goccy/go-yaml
Pull request #204 (2021-03-01 07:30:33)

Fix encoding of float value
fix https://github.com/goccy/go-yaml/issues/166

Use `strconv.FormatFloat` to distinguish between float32 and float64


Patch:
diff --git a/encode.go b/encode.go
index 3599a85..116999c 100644
--- a/encode.go
+++ b/encode.go
@@ -255,8 +255,10 @@ func (e *Encoder) encodeValue(ctx context.Context, v reflect.Value, column int)
 		return e.encodeInt(v.Int()), nil
 	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
 		return e.encodeUint(v.Uint()), nil
-	case reflect.Float32, reflect.Float64:
-		return e.encodeFloat(v.Float()), nil
+	case reflect.Float32:
+		return e.encodeFloat(v.Float(), 32), nil
+	case reflect.Float64:
+		return e.encodeFloat(v.Float(), 64), nil
 	case reflect.Ptr:
 		anchorName := e.anchorPtrToNameMap[v.Pointer()]
 		if anchorName != "" {
@@ -322,7 +324,7 @@ func (e *Encoder) encodeUint(v uint64) ast.Node {
 	return ast.Integer(token.New(value, value, e.pos(e.column)))
 }
 
-func (e *Encoder) encodeFloat(v float64) ast.Node {
+func (e *Encoder) encodeFloat(v float64, bitSize int) ast.Node {
 	if v == math.Inf(0) {
 		value := ".inf"
 		return ast.Infinity(token.New(value, value, e.pos(e.column)))
@@ -333,18 +335,10 @@ func (e *Encoder) encodeFloat(v float64) ast.Node {
 		value := ".nan"
 		return ast.Nan(token.New(value, value, e.pos(e.column)))
 	}
-	value := fmt.Sprintf("%f", v)
-	fvalue := strings.Split(value, ".")
-	if len(fvalue) > 1 {
-		precision := fvalue[1]
-		precisionNum := 1
-		for i := len(precision) - 1; i >= 0; i-- {
-			if precision[i] != '0' {
-				precisionNum = i + 1
-				break
-			}
-		}
-		value = strconv.FormatFloat(v, 'f', precisionNum, 64)
+	value := strconv.FormatFloat(v, 'g', -1, bitSize)
+	if !strings.Contains(value, ".") {
+		// append x.0 suffix to keep float value context
+		value = fmt.Sprintf("%s.0", value)
 	}
 	return ast.Float(token.New(value, value, e.pos(e.column)))
 }


Test patch:
diff --git a/encode_test.go b/encode_test.go
index db795ba..503b95e 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -78,6 +78,11 @@ func TestEncoder(t *testing.T) {
 			map[string]float32{"v": 0.99},
 			nil,
 		},
+		{
+			"v: 0.123456789\n",
+			map[string]float64{"v": 0.123456789},
+			nil,
+		},
 		{
 			"v: -0.1\n",
 			map[string]float64{"v": -0.1},
Repository: goccy/go-yaml
Pull request #205 (2021-03-01 08:37:04)

Fix parsing MergeKey ( '<<' ) characters
fix https://github.com/goccy/go-yaml/issues/184

Should be Merge Key only when `<<(\s+):[\s|\n|\r]`



Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index 465c3a7..4c99612 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -379,6 +379,30 @@ func (s *Scanner) scanQuote(ctx *Context, ch rune) (tk *token.Token, pos int) {
 	return s.scanDoubleQuote(ctx)
 }
 
+func (s *Scanner) isMergeKey(ctx *Context) bool {
+	if ctx.repeatNum('<') != 2 {
+		return false
+	}
+	src := ctx.src
+	size := len(src)
+	for idx := ctx.idx + 2; idx < size; idx++ {
+		c := src[idx]
+		if c == ' ' {
+			continue
+		}
+		if c != ':' {
+			return false
+		}
+		if idx+1 < size {
+			nc := src[idx+1]
+			if nc == ' ' || s.isNewLineChar(nc) {
+				return true
+			}
+		}
+	}
+	return false
+}
+
 func (s *Scanner) scanTag(ctx *Context) (tk *token.Token, pos int) {
 	ctx.addOriginBuf('!')
 	ctx.progress(1) // skip '!' character
@@ -560,7 +584,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
 				return
 			}
 		case '<':
-			if ctx.repeatNum('<') == 2 {
+			if s.isMergeKey(ctx) {
 				s.prevIndentColumn = s.column
 				ctx.addToken(token.MergeKey(string(ctx.obuf)+"<<", s.pos()))
 				s.progressColumn(ctx, 1)


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index da4950e..e4a7665 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -51,6 +51,10 @@ func TestParser(t *testing.T) {
 		"a: \"2015-02-24T18:19:39Z\"\n",
 		"a: 'b: c'\n",
 		"a: 'Hello #comment'\n",
+		"a: abc <<def>> ghi",
+		"a: <<abcd",
+		"a: <<:abcd",
+		"a: <<  :abcd",
 		"a: 100.5\n",
 		"a: bogus\n",
 		"a: \"\\0\"\n",