From 65788659c6785a0601623f95165c744a35499edd Mon Sep 17 00:00:00 2001 From: Roman Paska Date: Mon, 13 Jan 2020 23:57:25 +0200 Subject: [PATCH 1/2] Add test coverage for the new line matching mechanism --- tests/TestComments.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/TestComments.php b/tests/TestComments.php index 5911ed4..258e234 100644 --- a/tests/TestComments.php +++ b/tests/TestComments.php @@ -51,6 +51,42 @@ function commentTestData() two: EOT; + $duplicate_comments = <<< 'EOT' +# Top comments +top: + # Top one + one: + # Top two + two: +# Bottom comments +bottom: + # Bottom one + one: + # Bottom two + two: two +EOT; + + $duplicate_altered_without_comments = <<< 'EOT' +top: + one: + two: 2 +bottom: + one: 1 +EOT; + + $duplicate_altered_with_comments = <<< 'EOT' +# Top comments +top: + # Top one + one: + # Top two + two: 2 +# Bottom comments +bottom: + # Bottom one + one: 1 +EOT; + $travis_yaml_with_comments = <<< 'EOT' dist: trusty language: php @@ -128,6 +164,7 @@ function commentTestData() return [ [ $simple_yaml, $simple_yaml_reordered, $simple_yaml_expected, ], [ $indented_comments, $indented_without_comments, $indented_comments, ], + [ $duplicate_comments, $duplicate_altered_without_comments, $duplicate_altered_with_comments, ], [ $travis_yaml_with_comments, $travis_yaml_without_comments, $travis_yaml_with_comments ], ]; } From 0923aed335a6ef8c9a5b9a670f95788efa6b2ccb Mon Sep 17 00:00:00 2001 From: Roman Paska Date: Mon, 20 Jan 2020 10:46:29 +0200 Subject: [PATCH 2/2] Ensure that passed args are valid YAML # Conflicts: # tests/TestComments.php --- tests/TestComments.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/TestComments.php b/tests/TestComments.php index 258e234..b3f0db8 100644 --- a/tests/TestComments.php +++ b/tests/TestComments.php @@ -2,6 +2,7 @@ namespace Consolidation\Comments; use PHPUnit\Framework\TestCase; +use Symfony\Component\Yaml\Parser; class TestComments extends TestCase { @@ -176,6 +177,13 @@ function commentTestData() */ function testCommentParsing($original_contents, $altered_contents, $expected) { + // Ensure that passed args are valid YAML. + + $parser = new Parser(); + foreach (func_get_args() as $arg) { + $parser->parse($arg); + } + // Second step: collect comments from original document and inject them into result. $commentManager = new Comments();