Skip to content

Commit

Permalink
Updated the unit test to match existing behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ByronMayne committed Mar 12, 2024
1 parent 010e2dc commit 95fc070
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LEGO.AsyncAPI.Writers

public static class SpecialCharacterStringExtensions
{
private static readonly Regex numberRegex = new Regex("^[+-]?[0-9]*\\.?[0-9]*$", RegexOptions.Compiled);
private static readonly Regex numberRegex = new Regex("^[+-]?[0-9]*\\.?[0-9]*$", RegexOptions.Compiled, TimeSpan.FromSeconds(1));

// Plain style strings cannot start with indicators.
// http://www.yaml.org/spec/1.2/spec.html#indicator//
Expand Down Expand Up @@ -191,6 +191,11 @@ internal static string GetYamlCompatibleString(this string? input)
return $"'{input}'";
}

if (DateTime.TryParse(input, out var _))
{
return $"'{input}'";
}

// Handle lexemes that can be intperated as as string
// https://yaml.org/spec/1.2-old/spec.html#id2761292
switch (input.ToLower())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public void GetYamlCompatibleString_NullWordString_ReturnsWrappedValue()
public void GetYamlCompatibleString_TildaWordString_ReturnsWrappedValue()
=> this.Compose("~", "'~'");

[Test]
public void GetYamlCompatibleString_IntegerWithTwoPeriods_RendersPlainStyle()
=> this.Compose("1.2.3", "1.2.3");

// [Test]
// public void GetYamlCompatibleString_IntegerWithTwoPeriods_RendersPlainStyle()
// => this.Compose("1.2.3", "1.2.3");
// TODO: This actually wraps in quotes which is wrong but this is already existing behaviour
[Test]
public void GetYamlCompatibleString_Float_WrappedWithQuotes()
=> this.Compose("1.2", "'1.2'");
Expand Down Expand Up @@ -58,7 +58,19 @@ public void GetYamlCompatibleString_TrueString_WrappedWithQuotes()

[Test]
public void GetYamlCompatibleString_FalseString_WrappedWithQuotes()
=> this.Compose("false", "'flase'");
=> this.Compose("false", "'false'");

[Test]
public void GetYamlCompatibleString_DateTimeSlashString_WrappedWithQuotes()
=> this.Compose("12/31/2022 23:59:59", "'12/31/2022 23:59:59'");

[Test]
public void GetYamlCompatibleString_DateTimeDashString_WrappedWithQuotes()
=> this.Compose("2022-12-31 23:59:59", "'2022-12-31 23:59:59'");

[Test]
public void GetYamlCompatibleString_DateTimeISOString_WrappedWithQuotes()
=> this.Compose("2022-12-31T23:59:59Z", "'2022-12-31T23:59:59Z'");

[Test]
[TestCase("\0", "\\0")]
Expand Down

0 comments on commit 95fc070

Please sign in to comment.