Skip to content
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

Improve YAML spec conformance by three tests #400

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions YamlDotNet.Test/Spec/SpecTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public sealed class SpecTests

private static readonly string specFixtureDirectory = GetTestFixtureDirectory();

// Note: all of these (43) tests are failing the assertion on line 65
// Note: all of these (40) tests are failing the assertion on line 65
private static readonly List<string> ignoredSuites = new List<string>
{
"DK3J", "6M2F", "NJ66", "4MUZ", "NHX8", "WZ62", "RTP8", "W5VH", "27NA", "UDM2",
"DK3J", "6M2F", "NJ66", "4MUZ", "NHX8", "WZ62", "RTP8", "W5VH", "UDM2", "M7A3",
"8XYN", "4ABK", "KZN9", "Q5MG", "Y2GN", "2JQS", "S3PD", "R4YG", "9SA2", "UT92",
"HWV9", "6ZKB", "9MMW", "6BCT", "W4TN", "S4JQ", "K3WX", "8MK2", "52DL", "2SXE",
"FP8R", "9DXL", "FRK4", "2LFX", "7Z25", "3UYS", "QT73", "A2M4", "6LVF", "DBG4",
"M7A3", "BEC7", "5MUD"
"FP8R", "9DXL", "FRK4", "2LFX", "7Z25", "QT73", "A2M4", "6LVF", "DBG4", "5MUD"
};

[Theory, MemberData(nameof(GetYamlSpecDataSuites))]
public void ConformsWithYamlSpec(string name, string description, string inputFile, string expectedEventFile, bool error)
{
var expectedResult = File.ReadAllText(expectedEventFile);
using (var writer = new StringWriter())
{
try
Expand All @@ -62,13 +62,13 @@ public void ConformsWithYamlSpec(string name, string description, string inputFi
}
catch (Exception ex)
{
Assert.True(error, "Unexpected spec failure. Writer: " + writer + ", Exception: " + ex);
Assert.True(error, "Unexpected spec failure.\nExpected:\n" + expectedResult + "\nActual:\n[Writer Output]\n" + writer + "\n[Exception]\n" + ex);
return;
}

try
{
Assert.Equal(File.ReadAllText(expectedEventFile), writer.ToString(), ignoreLineEndingDifferences: true);
Assert.Equal(expectedResult, writer.ToString(), ignoreLineEndingDifferences: true);
}
catch (EqualException)
{
Expand Down
5 changes: 2 additions & 3 deletions YamlDotNet/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using YamlDotNet.Core.Tokens;

namespace YamlDotNet.Core
Expand All @@ -36,9 +35,9 @@ public static class Constants
};

public const int MajorVersion = 1;
public const int MinorVersion = 1;
public const int MinorVersion = 3;

public const char HandleCharacter = '!';
public const string DefaultHandle = "!";
}
}
}
5 changes: 3 additions & 2 deletions YamlDotNet/Core/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,11 @@ private void EmitDocumentStart(ParsingEvent evt, bool isFirst)
{
AnalyzeVersionDirective(documentStart.Version);

var documentVersion = documentStart.Version.Version;
isImplicit = false;
WriteIndicator("%YAML", true, false, false);
WriteIndicator(string.Format(CultureInfo.InvariantCulture,
"{0}.{1}", Constants.MajorVersion, Constants.MinorVersion),
"{0}.{1}", documentVersion.Major, documentVersion.Minor),
true, false, false);
WriteIndent();
}
Expand Down Expand Up @@ -780,7 +781,7 @@ private TagDirectiveCollection NonDefaultTagsAmong(IEnumerable<TagDirective> tag
// ReSharper disable UnusedParameter.Local
private void AnalyzeVersionDirective(VersionDirective versionDirective)
{
if (versionDirective.Version.Major != Constants.MajorVersion || versionDirective.Version.Minor != Constants.MinorVersion)
if (versionDirective.Version.Major != Constants.MajorVersion || versionDirective.Version.Minor > Constants.MinorVersion)
{
throw new YamlException("Incompatible %YAML directive");
}
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private VersionDirective ProcessDirectives(TagDirectiveCollection tags)
throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found duplicate %YAML directive.");
}

if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)
if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor > Constants.MinorVersion)
{
throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found incompatible YAML document.");
}
Expand Down Expand Up @@ -472,7 +472,7 @@ private ParsingEvent ParseNode(bool isBlock, bool isIndentlessSequence)
}
else
{
throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle.");
throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, found undefined tag handle.");
}
}
if (string.IsNullOrEmpty(tagName))
Expand Down
33 changes: 17 additions & 16 deletions YamlDotNet/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Scanner : IScanner
{ '"', '"' },
{ '\'', '\'' },
{ '\\', '\\' },
{ '/', '/' },
{ 'N', '\x85' },
{ '_', '\xA0' },
{ 'L', '\x2028' },
Expand Down Expand Up @@ -485,7 +486,7 @@ private void FetchNextToken()
Skip();
var end = cursor.Mark();

throw new SyntaxErrorException(start, end, "While scanning for the next token, find character that cannot start any token.");
throw new SyntaxErrorException(start, end, "While scanning for the next token, found character that cannot start any token.");
}

private bool CheckWhiteSpace()
Expand Down Expand Up @@ -740,7 +741,7 @@ private Token ScanDirective()
break;

default:
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, find unknown directive name.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, found unknown directive name.");
}

// Eat the rest of the line including any comments.
Expand Down Expand Up @@ -1351,7 +1352,7 @@ Token ScanBlockScalar(bool isLiteral)

if (analyzer.Check('0'))
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, find an indentation indicator equal to 0.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, found an indentation indicator equal to 0.");
}

// Get the indentation level and eat the indicator.
Expand All @@ -1368,7 +1369,7 @@ Token ScanBlockScalar(bool isLiteral)
{
if (analyzer.Check('0'))
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, find an indentation indicator equal to 0.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, found an indentation indicator equal to 0.");
}

increment = analyzer.AsDigit();
Expand Down Expand Up @@ -1526,7 +1527,7 @@ private int ScanBlockScalarBreaks(int currentIndent, StringBuilder breaks, Mark

if ((currentIndent == 0 || cursor.LineOffset < currentIndent) && analyzer.IsTab())
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, find a tab character where an indentation space is expected.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a block scalar, found a tab character where an found space is expected.");
}

// Have we find a non-empty line?
Expand Down Expand Up @@ -1596,14 +1597,14 @@ private Token ScanFlowScalar(bool isSingleQuoted)

if (IsDocumentIndicator())
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a quoted scalar, find unexpected document indicator.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a quoted scalar, found unexpected document indicator.");
}

// Check for EOF.

if (analyzer.IsZero())
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a quoted scalar, find unexpected end of stream.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a quoted scalar, found unexpected end of stream.");
}

// Consume non-blank characters.
Expand Down Expand Up @@ -1669,7 +1670,7 @@ private Token ScanFlowScalar(bool isSingleQuoted)
}
else
{
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, find unknown escape character.");
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, found unknown escape character.");
}
break;
}
Expand Down Expand Up @@ -1698,7 +1699,7 @@ private Token ScanFlowScalar(bool isSingleQuoted)

if ((character >= 0xD800 && character <= 0xDFFF) || character > 0x10FFFF)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, find invalid Unicode character escape code.");
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, found invalid Unicode character escape code.");
}

value.Append(char.ConvertFromUtf32(character));
Expand Down Expand Up @@ -1858,7 +1859,7 @@ private Token ScanPlainScalar()

if (flowLevel > 0 && analyzer.Check(':') && !analyzer.IsWhiteBreakOrZero(1))
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a plain scalar, find unexpected ':'.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a plain scalar, found unexpected ':'.");
}

// Check for indicators that may end a plain scalar.
Expand Down Expand Up @@ -1929,7 +1930,7 @@ private Token ScanPlainScalar()

if (hasLeadingBlanks && cursor.LineOffset < currentIndent && analyzer.IsTab())
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a plain scalar, find a tab character that violate indentation.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a plain scalar, found a tab character that violate indentation.");
}

// Consume a space or a tab character.
Expand Down Expand Up @@ -2032,7 +2033,7 @@ private string ScanDirectiveName(Mark start)

if (!analyzer.IsWhiteBreakOrZero())
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, find unexpected non-alphabetical character.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, found unexpected non-alphabetical character.");
}

return name.ToString();
Expand Down Expand Up @@ -2202,7 +2203,7 @@ private string ScanUriEscapes(Mark start)

if (width == 0)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, find an incorrect leading UTF-8 octet.");
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, found an incorrect leading UTF-8 octet.");
}

charBytes = new byte[width];
Expand All @@ -2213,7 +2214,7 @@ private string ScanUriEscapes(Mark start)

if ((octet & 0xC0) != 0x80)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, find an incorrect trailing UTF-8 octet.");
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, found an incorrect trailing UTF-8 octet.");
}
}

Expand All @@ -2231,7 +2232,7 @@ private string ScanUriEscapes(Mark start)

if (result.Length == 0 || result.Length > 2)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, find an incorrect UTF-8 sequence.");
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, found an incorrect UTF-8 sequence.");
}

return result;
Expand Down Expand Up @@ -2308,7 +2309,7 @@ private int ScanVersionDirectiveNumber(Mark start)

if (++length > MaxVersionNumberLength)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a %YAML directive, find extremely long version number.");
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a %YAML directive, found extremely long version number.");
}

value = value * 10 + analyzer.AsDigit();
Expand Down