Skip to content

Commit

Permalink
Merge branch 'updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jan 13, 2025
2 parents 5726fb4 + 936e981 commit 22df188
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 74 deletions.
6 changes: 3 additions & 3 deletions Broccolini.Test/Broccolini.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<FunckyImplicitUsings>enable</FunckyImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FsCheck.Xunit" Version="2.16.4" />
<PackageReference Include="Funcky" Version="3.3.0" />
<PackageReference Include="FsCheck.Xunit" Version="3.0.0" />
<PackageReference Include="Funcky" Version="3.4.0" />
<PackageReference Include="Funcky.Analyzers" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="Funcky.Xunit" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using FsCheck;
using FsCheck.Fluent;

namespace Broccolini.Test;

internal static class BroccoliniGenerators
internal static class BroccoliniArbMap
{
private static readonly char[] WhitespaceChars =
Enumerable.Range(0, count: ' ' + 1)
Expand All @@ -12,43 +13,48 @@ internal static class BroccoliniGenerators

private static readonly char[] NewLineChars = ['\r', '\n'];

public static void Register()
{
Arb.Register(typeof(BroccoliniGenerators));
}

public static Arbitrary<SectionName> ArbitrarySectionName()
=> Arb.From<string>()
public static IArbMap Default { get; } =
ArbMap.Default
.MergeArbFactory(ArbitrarySectionName)
.MergeArbFactory(ArbitrarySectionNameNoNulls)
.MergeArb(ArbitraryWhitespaceChar())
.MergeArbFactory(ArbitraryWhitespace)
.MergeArbFactory(ArbitraryWhitespaceNoNulls)
.MergeArbFactory(ArbitraryInlineText)
.MergeArbFactory(ArbitraryInlineTextNoNulls);

private static Arbitrary<SectionName> ArbitrarySectionName(IArbMap arbMap)
=> arbMap.ArbFor<string>()
.Filter(x => x is not null)
.Filter(x => !x.Contains(']') && !x.ContainsAny(NewLineChars))
.Filter(x => x.Trim(WhitespaceChars) == x)
.Convert(x => new SectionName(x), x => x.Value);

public static Arbitrary<SectionNameNoNulls> ArbitrarySectionNameNoNulls()
=> ArbitrarySectionName()
private static Arbitrary<SectionNameNoNulls> ArbitrarySectionNameNoNulls(IArbMap arbMap)
=> arbMap.ArbFor<SectionName>()
.Filter(x => !x.Value.Contains('\0'))
.Convert(s => new SectionNameNoNulls(s.Value), s => new SectionName(s.Value));

public static Arbitrary<Whitespace> ArbitraryWhitespace()
=> Arb.From<List<WhitespaceChar>>()
.Convert(l => new Whitespace(l.Select(c => c.Value).ConcatToString()), w => w.Value.Select(c => new WhitespaceChar(c)).ToList());

public static Arbitrary<WhitespaceNoNulls> ArbitraryWhitespaceNoNulls()
=> Arb.From<Whitespace>()
public static Arbitrary<WhitespaceNoNulls> ArbitraryWhitespaceNoNulls(IArbMap arbMap)
=> arbMap.ArbFor<Whitespace>()
.Filter(w => !w.Value.Contains('\0'))
.Convert(w => new WhitespaceNoNulls(w.Value), w => new Whitespace(w.Value));

public static Arbitrary<WhitespaceChar> ArbitraryWhitespaceChar()
private static Arbitrary<Whitespace> ArbitraryWhitespace(IArbMap arbMap)
=> arbMap.ArbFor<List<WhitespaceChar>>()
.Convert(l => new Whitespace(l.Select(c => c.Value).ConcatToString()), w => w.Value.Select(c => new WhitespaceChar(c)).ToList());

private static Arbitrary<WhitespaceChar> ArbitraryWhitespaceChar()
=> Arb.From(Gen.OneOf(WhitespaceChars.Select(Gen.Constant)).Select(c => new WhitespaceChar(c)));

public static Arbitrary<InlineText> ArbitraryInlineText()
=> Arb.From<string>()
private static Arbitrary<InlineText> ArbitraryInlineText(IArbMap arbMap)
=> arbMap.ArbFor<string>()
.Filter(x => x is not null)
.Filter(x => !x.ContainsAny(NewLineChars))
.Convert(s => new InlineText(s), t => t.Value);

public static Arbitrary<InlineTextNoNulls> ArbitraryInlineTextNoNulls()
=> Arb.From<InlineText>()
private static Arbitrary<InlineTextNoNulls> ArbitraryInlineTextNoNulls(IArbMap arbMap)
=> arbMap.ArbFor<InlineText>()
.Filter(w => !w.Value.Contains('\0'))
.Convert(t => new InlineTextNoNulls(t.Value), t => new InlineText(t.Value));

Expand Down
11 changes: 11 additions & 0 deletions Broccolini.Test/BroccoliniPropertyAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FsCheck.Xunit;

namespace Broccolini.Test;

public sealed class BroccoliniPropertyAttribute : PropertyAttribute
{
public BroccoliniPropertyAttribute()
{
Arbitrary = [typeof(BroccoliniArbMap)];
}
}
13 changes: 4 additions & 9 deletions Broccolini.Test/ParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Broccolini.Syntax;
using FsCheck;
using FsCheck.Xunit;
using FsCheck.Fluent;
using Xunit;
using static Broccolini.IniParser;
using static Broccolini.Test.TestData;
Expand All @@ -9,11 +9,6 @@ namespace Broccolini.Test;

public sealed class ParserTest
{
public ParserTest()
{
BroccoliniGenerators.Register();
}

[Theory]
[MemberData(nameof(GetCommentsData))]
public void ParsesCommentNode(string input, string leadingNode)
Expand All @@ -23,7 +18,7 @@ public void ParsesCommentNode(string input, string leadingNode)
Assert.Equal(input, node.ToString());
}

[Property]
[BroccoliniProperty]
public Property ParsesArbitraryComment(string commentValue)
{
var input = $"; {commentValue}";
Expand Down Expand Up @@ -61,14 +56,14 @@ public void ParsesSectionNames(string name, string input)
Assert.Equal(name, node.Name);
}

[Property]
[BroccoliniProperty]
public bool ParsesArbitrarySectionName(SectionName name, Whitespace ws1, Whitespace ws2, Whitespace ws3, InlineText trailing)
{
var document = Parse($"{ws1.Value}[{ws2.Value}{name.Value}{ws3.Value}]{trailing.Value}");
return document.Sections is [{ Name: var actualName }] && actualName == name.Value;
}

[Property]
[BroccoliniProperty]
public bool ParsesArbitrarySectionNameWithoutClosingBracket(SectionName name, Whitespace ws1, Whitespace ws2, Whitespace ws3)
{
var document = Parse($"{ws1.Value}[{ws2.Value}{name.Value}{ws3.Value}");
Expand Down
22 changes: 10 additions & 12 deletions Broccolini.Test/ReferenceTest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using Broccolini.SemanticModel;
using FsCheck;
using FsCheck.Fluent;
using FsCheck.Xunit;
using System.ComponentModel;
using System.Runtime.Versioning;
using System.Text;
using FsCheck;
using Xunit;
using Xunit.Abstractions;
using static Broccolini.Test.Kernel32;
using static Broccolini.Test.TestData;

namespace Broccolini.Test;

public sealed class ReferenceTest
public sealed class ReferenceTest(ITestOutputHelper testOutputHelper)
{
private readonly ITestOutputHelper _testOutputHelper;

public ReferenceTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
BroccoliniGenerators.Register();
}
private Config QuickThrowOnFailureConfig
=> Config.QuickThrowOnFailure
.WithRunner(new TestOutputRunner(testOutputHelper))
.WithArbitrary([typeof(BroccoliniArbMap)]);

[SkippableTheory]
[MemberData(nameof(GetSectionNameData))]
Expand Down Expand Up @@ -49,7 +47,7 @@ public void ParsesArbitrarySectionName()
return (sectionNames.Length == 1 && sectionNames[0] == sectionName.Value).ToProperty();
});

property.QuickCheckThrowOnFailure(_testOutputHelper);
Check.One(QuickThrowOnFailureConfig, property);
}

[SkippableFact]
Expand All @@ -65,7 +63,7 @@ public void ParsesArbitrarySectionNameWithoutClosingBracket()
return (sectionNames.Length == 1 && sectionNames[0] == sectionName.Value).ToProperty();
});

property.QuickCheckThrowOnFailure(_testOutputHelper);
Check.One(QuickThrowOnFailureConfig, property);
}

public static TheoryData<string, string> GetSectionNameData()
Expand Down Expand Up @@ -151,7 +149,7 @@ public void RecognizesWhitespace(char whitespace)
Assert.Equal(arbitraryValue, GetPrivateProfileString(temporaryFile.Path, arbitrarySection, arbitraryKey, "DEFAULT VALUE"));
}

private static TheoryData<char> GetWhiteSpaceData() => WhiteSpace.ToTheoryData();
public static TheoryData<char> GetWhiteSpaceData() => WhiteSpace.ToTheoryData();

public static TheoryData<string, string, bool> KeysData()
=> CaseSensitivityInputs.Select(input => (input.Variant1, input.Variant2, input.ShouldBeEqual)).ToTheoryData();
Expand Down
4 changes: 2 additions & 2 deletions Broccolini.Test/RoundtripTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FsCheck;
using FsCheck.Xunit;
using FsCheck.Fluent;
using Xunit;
using static Broccolini.IniParser;
using static Broccolini.Test.TestData;
Expand Down Expand Up @@ -33,7 +33,7 @@ public static TheoryData<string> PreservesFormattingData()
SectionsWithNames.Select(s => s.Input),
KeyValuePairsWithKeyAndValue.Select(s => s.Input)).ToTheoryData();

[Property]
[BroccoliniProperty]
public Property PreservesFormattingOfArbitraryInput(NonNull<string> input)
{
var document = Parse(input.Get);
Expand Down
21 changes: 8 additions & 13 deletions Broccolini.Test/SyntaxFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Broccolini.Syntax;
using Broccolini.Tokenization;
using FsCheck;
using FsCheck.Xunit;
using FsCheck.Fluent;
using Xunit;
using static Broccolini.Syntax.IniSyntaxFactory;
using static Broccolini.Test.TestData;
Expand All @@ -10,20 +10,15 @@ namespace Broccolini.Test;

public sealed class SyntaxFactoryTests
{
public SyntaxFactoryTests()
{
BroccoliniGenerators.Register();
}

[Property]
[BroccoliniProperty]
public Property ParsesCreatedSectionNodeOrThrows(NonNull<string> value)
{
try
{
var node = Section(value.Get);
var parsedNode = IniParser.Parse(node.ToString());
return (parsedNode.Sections.Count == 1
&& parsedNode.Sections.Single() is SectionIniNode sectionNode
&& parsedNode.Sections.Single() is { } sectionNode
&& sectionNode.Name == value.Get).ToProperty();
}
catch (ArgumentException)
Expand All @@ -44,7 +39,7 @@ public void ThrowsWhenSectionNameWouldNotBePreserved(string value)
Assert.Throws<ArgumentException>(() => Section(value));
}

[Property]
[BroccoliniProperty]
public Property ParsesCreatedKeyValueNodeOrThrows(NonNull<string> key, NonNull<string> value)
{
try
Expand Down Expand Up @@ -83,7 +78,7 @@ public void ParsesCreatedKeyValueNode(string key, string value)
Assert.Equal(value, parsedNode.Value);
}

[Property]
[BroccoliniProperty]
public Property ParsesCreatedKeyValueNodeWithEmptyKeyOrThrows(NonNull<string> value)
{
try
Expand Down Expand Up @@ -126,7 +121,7 @@ public void ThrowsWhenNewLineIsUsedAsWhiteSpace(string newLine)
Assert.Throws<ArgumentException>(() => WhiteSpace(newLine));
}

[Property]
[BroccoliniProperty]
public Property TokenizerAndFactoryAcceptSameWhiteSpace(WhitespaceNoNulls whitespace)
{
var tokenFromFactory = Option<IniToken>.None;
Expand All @@ -142,7 +137,7 @@ public Property TokenizerAndFactoryAcceptSameWhiteSpace(WhitespaceNoNulls whites
return (tokenized.SingleOrNone() == tokenFromFactory).ToProperty();
}

private static TheoryData<string> NewLinesData() => NewLines.ToTheoryData();
public static TheoryData<string> NewLinesData() => NewLines.ToTheoryData();

private static TheoryData<string> WhiteSpaceData() => TestData.WhiteSpace.Select(static c => c.ToString()).ToTheoryData();
public static TheoryData<string> WhiteSpaceData() => TestData.WhiteSpace.Select(static c => c.ToString()).ToTheoryData();
}
6 changes: 3 additions & 3 deletions Broccolini.Test/TokenizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void TokenizeNewLines(string input)
Assert.Single(Tokenize(input), new IniToken.NewLine(input));
}

private static TheoryData<string> GetNewLinesData() => NewLines.ToTheoryData();
public static TheoryData<string> GetNewLinesData() => NewLines.ToTheoryData();

[Theory]
[MemberData(nameof(GetConsecutiveNewLinesData))]
Expand All @@ -36,9 +36,9 @@ public void CorrectlyTokenizesNewLineFollowingWhitesSpace()
Assert.Equal([new IniToken.WhiteSpace("\t"), new IniToken.NewLine("\n")], Tokenize("\t\n"));
}

private static TheoryData<char> GetWhiteSpaceData() => WhiteSpace.ToTheoryData();
public static TheoryData<char> GetWhiteSpaceData() => WhiteSpace.ToTheoryData();

private static TheoryData<string, string> GetConsecutiveNewLinesData()
public static TheoryData<string, string> GetConsecutiveNewLinesData()
=> NewLines.SelectMany(_ => NewLines, ValueTuple.Create)
.Except(Sequence.Return(("\r", "\n")))
.ToTheoryData();
Expand Down
5 changes: 2 additions & 3 deletions Broccolini.Test/TriviaTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Diagnostics;
using Broccolini.Editing;
using Broccolini.Syntax;
using FsCheck;
using Xunit;
using static Broccolini.IniParser;
using static Broccolini.Test.TestData;
Expand Down Expand Up @@ -89,7 +88,7 @@ public void RecognizedTrailingWhitespaceAndNewLinesAsTrivia(IniNode node)
Assert.Equal(expectedDocument, parsedDocument);
}

private static TheoryData<IniNode> TrailingTriviaData()
public static TheoryData<IniNode> TrailingTriviaData()
=> (from node in ExampleNodes
from inline in InlineTrivia
from breaking in LineBreakingTrivia
Expand All @@ -107,7 +106,7 @@ public void RecognizedWhitespaceAndNewLinesAsTriviaForConsecutiveNodes(IniNode a
Assert.Equal(expectedDocument, parsedDocument);
}

private static TheoryData<IniNode, IniNode> TriviaForConsecutiveNodes()
public static TheoryData<IniNode, IniNode> TriviaForConsecutiveNodes()
=> (from node1 in ExampleNodes
from node2 in ExampleNodes
from inline in InlineTrivia
Expand Down
14 changes: 7 additions & 7 deletions Broccolini/Broccolini.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<PropertyGroup Label="NuGet Packing">
<Version>2.0.0</Version>
<Description>Broccolini is a non-destructive parser for INI files compatible with GetPrivateProfileString.</Description>
Expand All @@ -20,9 +23,6 @@
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup Label="Deterministic Builds and Source Link">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="..\readme.md" Pack="true" PackagePath="\" />
</ItemGroup>
Expand All @@ -31,12 +31,12 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="PolySharp" Version="1.14.0" PrivateAssets="all" />
<PackageReference Include="IsExternalInit" Version="1.0.2" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.IsExternalInit</PolySharpExcludeGeneratedTypes>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "9.0.101",
"rollForward": "feature"
}
}

0 comments on commit 22df188

Please # to comment.