nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: decorators-squad/eo-yaml
Pull request #267 (2020-03-31 15:22:30)

#219 fixed YamlLines.line(...)
PR for #219 

* fixed bug in YamlLines.line(int) -- it was matching the index of the line with the provided number, but this was incorrect. It should match the internal number of the line, not its index in the collection.


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlLines.java b/src/main/java/com/amihaiemil/eoyaml/YamlLines.java
index 489491b..d59b810 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlLines.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlLines.java
@@ -76,12 +76,10 @@ interface YamlLines extends Iterable<YamlLine> {
      */
     default YamlLine line(final int number) {
         final Collection<YamlLine> lines = this.lines();
-        int index = 0;
         for(final YamlLine line : lines){
-            if(index == number) {
+            if(line.number() == number) {
                 return line;
             }
-            index++;
         }
         throw new IllegalArgumentException(
             "Couldn't find line " + number


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
index bce62ff..7c69b97 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
@@ -35,7 +35,6 @@ import java.util.Set;
 import org.apache.commons.io.IOUtils;
 import org.hamcrest.MatcherAssert;
 import org.hamcrest.Matchers;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -406,13 +405,8 @@ public final class RtYamlInputTest {
      * A stream of YAML Documents, when the first Start Marker is missing,
      * can be read. The file also contains comments.
      * @throws Exception If something goes wrong.
-     * @todo #211:30min Fix this unit test. The YAML from the file is not
-     *  read properly, most likely because of line-numbering Issues. The first
-     *  actual line of YAML has number 3 because the comments are omitted.
-     *  YamlLines.line(...) is not aware of these possible numbering diffs.
      */
     @Test
-    @Ignore
     public void readsStreamWithoutFirstStartMarkerAndComments()
         throws Exception {
         final YamlInput input = Yaml.createYamlInput(
Repository: decorators-squad/eo-yaml
Pull request #369 (2020-06-26 14:28:45)

#364 fix print with indented comments + test
PR for #364 
A small bugfix regarding printing of YAML mappings which contain indented comments.


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlPrinter.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlPrinter.java
index c7e0f66..a7e57d3 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlPrinter.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlPrinter.java
@@ -127,11 +127,11 @@ final class RtYamlPrinter implements YamlPrinter {
         while(keysIt.hasNext()) {
             final YamlNode key = keysIt.next();
             this.printPossibleComment(key, alignment.toString());
-            this.writer.append(alignment);
             final YamlNode value = mapping.value(key);
             if(!(value instanceof Scalar)) {
                 this.printPossibleComment(value, alignment.toString());
             }
+            this.writer.append(alignment);
             if(key instanceof Scalar) {
                 this.printScalar((Scalar) key, 0);
                 this.writer


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/YamlMappingPrintTest.java b/src/test/java/com/amihaiemil/eoyaml/YamlMappingPrintTest.java
index 541ddac..35f9f8b 100644
--- a/src/test/java/com/amihaiemil/eoyaml/YamlMappingPrintTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/YamlMappingPrintTest.java
@@ -50,6 +50,25 @@ import java.io.IOException;
  * @since 4.0.0
  */
 public final class YamlMappingPrintTest {
+
+    /**
+     * We read a YamlMapping containing indented nodes and comments
+     * and print it.
+     * @throws Exception If something goes wrong.
+     */
+    @Test
+    public void printsReadYamlMappingWithIndentedComment() throws Exception {
+        final YamlMapping read = Yaml.createYamlInput(
+            new File("src/test/resources/printing_tests/yamlMappingIndentedComments.yml")
+        ).readYamlMapping();
+        MatcherAssert.assertThat(
+            read.toString(),
+            Matchers.equalTo(
+                this.readExpected("yamlMappingIndentedComments.yml")
+            )
+        );
+    }
+
     /**
      * We read a YamlMapping containing all types of
      * YamlNode we have so far and print it.
diff --git a/src/test/resources/printing_tests/yamlMappingIndentedComments.yml b/src/test/resources/printing_tests/yamlMappingIndentedComments.yml
new file mode 100644
index 0000000..50f49ff
--- /dev/null
+++ b/src/test/resources/printing_tests/yamlMappingIndentedComments.yml
@@ -0,0 +1,12 @@
+name: "eo-yaml"
+contributors:
+  # Developers here
+  developers:
+    - amihaiemil # Architect
+    - sherif
+    - salijkan
+  # Mostly chatbots
+  devops:
+    - rultor
+    - 0pdd
+    - travis
\ No newline at end of file
Repository: decorators-squad/eo-yaml
Pull request #438 (2021-02-13 08:06:32)

#433 Implemented+tested method Yaml.fromJsonArray(JsonArray).
PR for #433 


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/Yaml.java b/src/main/java/com/amihaiemil/eoyaml/Yaml.java
index 4f7245b..bf4b638 100644
--- a/src/main/java/com/amihaiemil/eoyaml/Yaml.java
+++ b/src/main/java/com/amihaiemil/eoyaml/Yaml.java
@@ -27,6 +27,7 @@
  */
 package com.amihaiemil.eoyaml;
 
+import javax.json.JsonArray;
 import javax.json.JsonObject;
 import java.io.*;
 
@@ -194,4 +195,13 @@ public final class Yaml {
     public static YamlMapping fromJsonObject(final JsonObject object) {
         return new JsonYamlMapping(object);
     }
+
+    /**
+     * Create a YAML sequence from a {@link JsonArray}.
+     * @param array JsonArray in question.
+     * @return YamlSequence.
+     */
+    public static YamlSequence fromJsonArray(final JsonArray array){
+        return new JsonYamlSequence(array);
+    }
 }


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/YamlTest.java b/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
index 20e40aa..e396f2a 100644
--- a/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/YamlTest.java
@@ -35,6 +35,7 @@ import org.hamcrest.Matchers;
 import org.junit.Test;
 
 import javax.json.Json;
+import javax.json.JsonValue;
 
 /**
  * Unit tests for {@link Yaml}.
@@ -131,4 +132,18 @@ public final class YamlTest {
             Matchers.notNullValue()
         );
     }
+
+    /**
+     * Yaml can create an YamlMapping from a json array.
+     */
+    @Test
+    public void createsYamlMappingFromJsonArray() {
+        MatcherAssert.assertThat(
+            Yaml.fromJsonArray(JsonValue.EMPTY_JSON_ARRAY),
+            Matchers.allOf(
+                Matchers.notNullValue(),
+                Matchers.instanceOf(JsonYamlSequence.class)
+            )
+        );
+    }
 }
Repository: decorators-squad/eo-yaml
Pull request #506 (2022-07-23 20:05:40)

Fix YamlReadingException when first key of a  mapping in a compact sequence contains a dash
The bug was introduced in 09795e3.

The fix consists in limiting the number of split pieces of a line on the dash to 2: the part that signal the sequence and interpret the rest as the key name.


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java b/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
index 315e082..10771a4 100644
--- a/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
+++ b/src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java
@@ -160,7 +160,7 @@ final class RtYamlInput implements YamlInput {
                     final String offset = "  ";
                     final String keyValueIndent = seqIndent + offset;
                     final YamlLine keyValueLine = new RtYamlLine(
-                        keyValueIndent + line.split("-")[1].trim(),
+                        keyValueIndent + line.split("-", 2)[1].trim(),
                         ++number
                     );
                     if (!keyValueLine.toString().trim().isEmpty()) {


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
index 4568240..419697a 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
@@ -879,6 +879,27 @@ public final class RtYamlInputTest {
         );
     }
 
+    /**
+     * Corner case when key:value is on the same line as the sequence marker
+     * and key contains dashes (which is the sequence marker itself).
+     *  @throws IOException If something is wrong.
+     */
+    @Test
+    public void shouldReadSequenceWhenFirstKeyWithDashesIsOnTheSameLine()
+        throws IOException {
+        final String fileName = "src/test/resources/"
+            + "compactSequenceWithDashedKey.yml";
+        final YamlMapping root = Yaml.createYamlInput(new File(fileName))
+            .readYamlMapping();
+
+        final YamlSequence sequence = root.yamlSequence("root");
+        MatcherAssert.assertThat(sequence, Matchers.iterableWithSize(2));
+
+        MatcherAssert.assertThat(
+            sequence.yamlMapping(0).string("a-a-a"),
+            Matchers.equalTo("1")
+        );
+    }
 
     /**
      * Do a round-trip test on the bracketed-key sample file.
diff --git a/src/test/resources/compactSequenceWithDashedKey.yml b/src/test/resources/compactSequenceWithDashedKey.yml
new file mode 100644
index 0000000..9db1d13
--- /dev/null
+++ b/src/test/resources/compactSequenceWithDashedKey.yml
@@ -0,0 +1,5 @@
+root:
+  - a-a-a: 1
+    b: 2
+  - a: 3
+    b: 4
Repository: decorators-squad/eo-yaml
Pull request #548 (2023-02-06 08:59:29)

Fix mapStartsAtDash regex for Issue 546
PR for #546 


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java b/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java
index 6d8ef68..916cb3f 100644
--- a/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java
+++ b/src/main/java/com/amihaiemil/eoyaml/SameIndentationLevel.java
@@ -115,7 +115,7 @@ final class SameIndentationLevel implements YamlLines {
         final String trimmed = dashLine.trimmed();
         final boolean escapedScalar = trimmed.matches("^\\s*-\\s*\".*\"$")
             || trimmed.matches("^\\s*-\\s*'.*'$");
-        return trimmed.matches("^\\s*-.*:\\s.+$") && !escapedScalar;
+        return trimmed.matches("^\\s*-.*:(\\s.*)?$") && !escapedScalar;
     }
 
     /**


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
index e489fe8..349512f 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java
@@ -1199,6 +1199,42 @@ public final class RtYamlInputTest {
         );
     }
 
+    /**
+     * Unit test for issue 546.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void shouldIterateKeysWhenMappingStartsAtDash()
+        throws IOException {
+        final String filename = "issue_546_mapping_starts_at_dash.yml";
+
+        final YamlMapping read = new RtYamlInput(
+            new FileInputStream("src/test/resources/" + filename)
+        ).readYamlMapping();
+
+        final YamlMapping holders = read.yamlSequence("holders")
+            .iterator().next().asMapping();
+        MatcherAssert.assertThat(
+            holders.yamlSequence("array").string(0),
+            Matchers.equalTo("arr3")
+        );
+        MatcherAssert.assertThat(
+            holders.string("value"),
+            Matchers.equalTo("test1")
+        );
+
+        final YamlMapping holdersTwo = read.yamlSequence("holders2")
+            .iterator().next().asMapping();
+        MatcherAssert.assertThat(
+            holdersTwo.string("value2"),
+            Matchers.equalTo("test2")
+        );
+        MatcherAssert.assertThat(
+            holdersTwo.yamlSequence("array2").string(0),
+            Matchers.equalTo("arr4")
+        );
+    }
+
     /**
      * Read a test resource file's contents.
      * @param fileName File to read.
diff --git a/src/test/resources/issue_546_mapping_starts_at_dash.yml b/src/test/resources/issue_546_mapping_starts_at_dash.yml
new file mode 100644
index 0000000..77bad5e
--- /dev/null
+++ b/src/test/resources/issue_546_mapping_starts_at_dash.yml
@@ -0,0 +1,8 @@
+holders:
+  - array:
+      - arr3
+    value: test1
+holders2:
+  - value2: test2
+    array2:
+      - arr4
\ No newline at end of file
Repository: decorators-squad/eo-yaml
Pull request #582 (2023-12-06 16:58:59)

Add method YamlSequence.yamlNode
This returns the YamlNode at position `index` without casting it to a subtype.

I tried to mirror the style of the rest of the file, and to add a unit test.


Patch:
diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java b/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
index 32d9833..18ea073 100644
--- a/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
+++ b/src/main/java/com/amihaiemil/eoyaml/YamlSequence.java
@@ -67,6 +67,23 @@ public interface YamlSequence extends YamlNode, Iterable<YamlNode> {
         return this.values().size();
     }
 
+    /**
+     * Get the Yaml node from the given index.
+     * @param index Integer index.
+     * @return Yaml node.
+     */
+    default YamlNode yamlNode(final int index) {
+        YamlNode result = null;
+        int count = 0;
+        for (final YamlNode node : this.values()) {
+            if (count == index) {
+                result = node;
+            }
+            count = count + 1;
+        }
+        return result;
+    }
+
     /**
      * Get the Yaml mapping  from the given index.
      * @param index Integer index.


Test patch:
diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlSequenceTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlSequenceTest.java
index f37b05b..55e8b4e 100644
--- a/src/test/java/com/amihaiemil/eoyaml/RtYamlSequenceTest.java
+++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlSequenceTest.java
@@ -178,6 +178,21 @@ public final class RtYamlSequenceTest {
         );
     }
 
+    /**
+     * RtYamlSequence can return a YamlNode.
+     */
+    @Test
+    public void returnsYamlNode() {
+        List<YamlNode> nodes = new LinkedList<>();
+        nodes.add(new PlainStringScalar("test"));
+        nodes.add(Mockito.mock(YamlMapping.class));
+        nodes.add(new PlainStringScalar("mihai"));
+        YamlSequence seq = new RtYamlSequence(nodes);
+        MatcherAssert.assertThat(
+            seq.yamlNode(1), Matchers.notNullValue()
+        );
+    }
+
     /**
      * RtYamlSequence can return a YamlMapping.
      */