Skip to content

Commit

Permalink
Fix CommonRegexes.String not matching single character strings (#427)
Browse files Browse the repository at this point in the history
* Fix CommonRegexes.String not matching single character strings

* Bump version
  • Loading branch information
IhateTrains authored Apr 21, 2024
1 parent ea9e947 commit 0d0eba4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions commonItems.UnitTests/CommonRegexesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ public void StringRegexDoesntMatchEquals() {
Assert.DoesNotMatch(CommonRegexes.String, "1234-abcd=");
}

[Fact]
public void StringRegexMatchesSingleCharacters() {
Assert.Matches(CommonRegexes.String, "a");
Assert.Matches(CommonRegexes.String, "1");
}

[Fact]
public void QuotedStringRegexMatchesQuotedStrings() {
Assert.Matches(CommonRegexes.QuotedString, @"""1234-abcd""");
Expand Down
12 changes: 12 additions & 0 deletions commonItems.UnitTests/ParserHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ public void GetStringsAddsStringsFromBracedBlock() {
Assert.Equal(["foo", "bar", "baz"], reader.GetStrings());
}

[Fact]
public void GetStringsAddsSingleCharacterStrings() {
var reader = new BufferedReader("a b c x y z");
Assert.Equal(["a", "b", "c", "x", "y", "z"], reader.GetStrings());
}

[Fact]
public void GetStringGetsSingleCharacterString() {
var reader = new BufferedReader(" = f");
Assert.Equal("f", reader.GetString());
}

[Fact]
public void GetStringGetsStringAfterEquals() {
var reader = new BufferedReader(" = foo");
Expand Down
6 changes: 4 additions & 2 deletions commonItems/CommonRegexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static partial class CommonRegexes {
public static Regex QuotedFloat => GetQuotedFloatRegex();

// strings
public static Regex String => new($"^(?!@).+[^{NonStringCharacters}]+$");
public static Regex QuotedString => new(@"^""[^\n\""]+""$");
public static Regex String => new($"^(?!@).*[^{NonStringCharacters}]+$");
public static Regex QuotedString => GetQuotedStringRegex();

// dates
public static Regex Date => GetDateRegex();
Expand All @@ -40,4 +40,6 @@ public static partial class CommonRegexes {
private static partial Regex GetQuotedFloatRegex();
[GeneratedRegex("^\\-?\\d+[.]\\d+[.]\\d+$")]
private static partial Regex GetDateRegex();
[GeneratedRegex(@"^""[^\n\""]+""$")]
private static partial Regex GetQuotedStringRegex();
}
2 changes: 1 addition & 1 deletion commonItems/commonItems.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageId>PGCG.$(AssemblyName)</PackageId>
<Version>12.0.1</Version>
<Version>12.0.2</Version>
<Authors>PGCG</Authors>
<PackageProjectUrl>https://github.com/ParadoxGameConverters/commonItems.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/ParadoxGameConverters/commonItems.NET</RepositoryUrl>
Expand Down

0 comments on commit 0d0eba4

Please sign in to comment.