+
Skip to content

Improve line matching mechanism by introducing line ids [test only] #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/TestComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Consolidation\Comments;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Parser;

class TestComments extends TestCase
{
Expand Down Expand Up @@ -51,6 +52,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
Expand Down Expand Up @@ -128,6 +165,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 ],
];
}
Expand All @@ -139,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();
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载