Skip to content

Commit

Permalink
Multi-line scalars need to be indented.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jul 26, 2022
1 parent 144e385 commit 91678a8
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 19 deletions.
112 changes: 112 additions & 0 deletions YamlDotNet.Test/Serialization/DeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Linq;
using FluentAssertions;
using Xunit;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

Expand Down Expand Up @@ -216,6 +217,117 @@ public void NewLinesInKeys()
Assert.Equal($"value\na\nb", dictionary.First().Value);
}

[Fact]
public void DeserializeMultiLineSingleQuoteRequiresCorrectFormatting()
{
var yaml = @"attach_workspace: &attach_workspace
attach_workspace:
at: '.'
deploy_nonprod_job: &deploy_nonprod_job
working_directory: '~/build'
docker: [ {image: 'test.com'} ]
steps:
- *attach_workspace
- run: 'deploy-to-test'
version: 2
jobs:
build_test_image:
working_directory: '~/build
docker:
- image: docker:17.05.0-ce-git
environment:
DOCKER_IMAGE_NAME: testApp
steps:
- run:
name: Install bash and curl
command: |
apk update
apk add -y curl
apk add -y bash
apk update
apk upgrade
deploy_test:
environment:
HAL_TARGETS: '45597'
HAL_BUILD_FILE: '.hal_build_id_test'
workflows:
version: 2
pipeline:
jobs:
- build_test_image
- deploy_test
";
var deserializer = new DeserializerBuilder().Build();
var exception = Assert.Throws<SyntaxErrorException>(() =>
{
var o = deserializer.Deserialize(yaml, typeof(object));
});
Assert.Equal(16, exception.Start.Line);
Assert.Equal(28, exception.Start.Column);
Assert.Equal(338, exception.Start.Index);
Assert.Equal(16, exception.End.Line);
Assert.Equal(36, exception.End.Column);
Assert.Equal(346, exception.End.Index);
}

[Fact]
public void DeserializeMultiLineSingleQuoteWorksWithCorrectFormatting()
{
var yaml = @"attach_workspace: &attach_workspace
attach_workspace:
at: '.'
deploy_nonprod_job: &deploy_nonprod_job
working_directory: '~/build'
docker: [ {image: 'test.com'} ]
steps:
- *attach_workspace
- run: 'deploy-to-test'
version: 2
jobs:
build_test_image:
working_directory: '~/build
hello'
docker:
- image: docker:17.05.0-ce-git
environment:
DOCKER_IMAGE_NAME: testApp
steps:
- run:
name: Install bash and curl
command: |
apk update
apk add -y curl
apk add -y bash
apk update
apk upgrade
deploy_test:
environment:
HAL_TARGETS: '45597'
HAL_BUILD_FILE: '.hal_build_id_test'
workflows:
version: 2
pipeline:
jobs:
- build_test_image
- deploy_test
";
var deserializer = new DeserializerBuilder().Build();
var o = (IDictionary<object, object>)deserializer.Deserialize(yaml, typeof(object));
o = (IDictionary<object, object>)o["jobs"];
o = (IDictionary<object, object>)o["build_test_image"];
Assert.Equal("~/build hello", o["working_directory"]);
}

public class Test
{
public string Value { get; set; }
Expand Down
Loading

0 comments on commit 91678a8

Please sign in to comment.