Skip to content

Use Bogus to generate symbol data #1043

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

Merged
merged 1 commit into from
Aug 17, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(MsExtensionNugetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(MsExtensionNugetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MsExtensionNugetVersion)" />
<PackageVersion Include="Bogus" Version="34.0.2" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.TypeReso
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.DotnetTool", "src\generators\Silk.NET.SilkTouch.DotnetTool\Silk.NET.SilkTouch.DotnetTool.csproj", "{50F2BCCC-BDC8-4694-B55E-583A6A77E1CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.Tests.Common", "tests\Silk.NET.SilkTouch.Tests.Common\Silk.NET.SilkTouch.Tests.Common.csproj", "{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -302,6 +304,18 @@ Global
{50F2BCCC-BDC8-4694-B55E-583A6A77E1CF}.Release|x64.Build.0 = Release|Any CPU
{50F2BCCC-BDC8-4694-B55E-583A6A77E1CF}.Release|x86.ActiveCfg = Release|Any CPU
{50F2BCCC-BDC8-4694-B55E-583A6A77E1CF}.Release|x86.Build.0 = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|x64.ActiveCfg = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|x64.Build.0 = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|x86.ActiveCfg = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Debug|x86.Build.0 = Debug|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|Any CPU.Build.0 = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|x64.ActiveCfg = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|x64.Build.0 = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|x86.ActiveCfg = Release|Any CPU
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -331,6 +345,7 @@ Global
{7D181E77-CAD4-4288-AC0A-9C4D55ED1EC2} = {8238D9F3-E158-4633-8017-B29AA3AD61F7}
{89E8EDA4-EB19-45FC-AFA1-B6A16211A9EE} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
{50F2BCCC-BDC8-4694-B55E-583A6A77E1CF} = {8238D9F3-E158-4633-8017-B29AA3AD61F7}
{F46AC88E-8A7E-4B6F-BC8F-8848B3DD3CCF} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Expand Down
8 changes: 8 additions & 0 deletions src/generators/Silk.NET.SilkTouch.Symbols/TypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ private TypeId(Guid guid)
/// <returns>The new instance</returns>
public static TypeId CreateNew() => new TypeId(Guid.NewGuid());

/// <summary>
/// Creates a new TypeID from a GUID. This is not a stable interface. DO NOT USE
/// </summary>
/// <param name="guid">The Guid to use for underlying identity</param>
/// <returns>The Type ID</returns>
[Obsolete("DO NOT USE. THIS IS NOT A STABLE INTERFACE")]
public static TypeId From(Guid guid) => new TypeId(guid);

/// <inheritdoc />
public bool Equals(TypeId other) => _guid.Equals(other._guid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Symbols\Silk.NET.SilkTouch.Symbols.csproj" />
<ProjectReference Include="..\Silk.NET.SilkTouch.TestFramework\Silk.NET.SilkTouch.TestFramework.csproj" />
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Symbols\Silk.NET.SilkTouch.Symbols.csproj" />
<ProjectReference Include="..\Silk.NET.SilkTouch.TestFramework\Silk.NET.SilkTouch.TestFramework.csproj" />
<ProjectReference Include="..\Silk.NET.SilkTouch.Tests.Common\Silk.NET.SilkTouch.Tests.Common.csproj" />
<PackageReference Include="Bogus" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Collections.Generic;
using System.Linq;
using Moq;
using Moq.Protected;
using Silk.NET.SilkTouch.Tests.Common;
using Xunit;

namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests;

public class ClassSymbolTests
{
[Fact, Trait("Category", "Symbols")]
public void IsVisitedAsSelf()
public static IEnumerable<object[]> BogusData => Fakers.ClassSymbol.Generate(Fakers.StandardGenerateCount)
.Select(x => new[] { (object)x });

[Theory, MemberData(nameof(BogusData)), Trait("Category", "Symbols")]
public void IsVisitedAsSelf(ClassSymbol symbol)
{
var symbol = new ClassSymbol(TypeId.CreateNew(), new IdentifierSymbol(""), ImmutableArray<MethodSymbol>.Empty);

var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<ClassSymbol>("VisitClass", Times.Once(), ItExpr.IsAny<ClassSymbol>());
}

[Fact, Trait("Category", "Symbols")]
public void IsVisitedAsType()
[Theory, MemberData(nameof(BogusData)), Trait("Category", "Symbols")]
public void IsVisitedAsType(ClassSymbol symbol)
{
var symbol = new ClassSymbol(TypeId.CreateNew(), new IdentifierSymbol(""), ImmutableArray<MethodSymbol>.Empty);

var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Moq;
using Moq.Protected;
using Silk.NET.SilkTouch.Tests.Common;
using Xunit;

namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests;

public class ExternalTypeReferenceTests
{
[Fact,
public static IEnumerable<object[]> BogusData => Fakers.ExternalTypeReference.Generate(Fakers.StandardGenerateCount)
.Select(x => new[] { (object)x });

[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void RefIsVisitedAsRef()
public void RefIsVisitedAsRef(ExternalTypeReference symbol)
{
var symbol = new ExternalTypeReference(null, new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<ExternalTypeReference>("VisitExternalTypeReference", Times.Once(), ItExpr.IsAny<ExternalTypeReference>());
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void RefIsVisitedAsGenericRef()
public void RefIsVisitedAsGenericRef(ExternalTypeReference symbol)
{
var symbol = new ExternalTypeReference(null, new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<TypeReference>("VisitTypeReference", Times.Once(), ItExpr.IsAny<TypeReference>());
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void RefTypeIdentifierIsVisitedAsIdentifier()
public void RefTypeIdentifierIsVisitedAsIdentifier(ExternalTypeReference symbol)
{
var symbol = new ExternalTypeReference(null, new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<IdentifierSymbol>("VisitIdentifier", Times.Once(), ItExpr.IsAny<IdentifierSymbol>());
.Verify<IdentifierSymbol>
(
"VisitIdentifier",
Times.Once(),
ItExpr.Is<IdentifierSymbol>(x => ReferenceEquals(x, symbol.TypeIdentifier))
);
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void RefNamespaceIsVisitedAsIdentifier()
public void RefNamespaceIsVisitedAsIdentifier(ExternalTypeReference symbol)
{
var symbol = new ExternalTypeReference(new IdentifierSymbol(""), new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<IdentifierSymbol>("VisitIdentifier", Times.Exactly(2), ItExpr.IsAny<IdentifierSymbol>());
.Verify<IdentifierSymbol>
(
"VisitIdentifier",
symbol.Namespace is null ? Times.Never() : Times.Once(),
ItExpr.Is<IdentifierSymbol>(x => ReferenceEquals(x, symbol.Namespace))
);
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Collections.Generic;
using System.Linq;
using Moq;
using Moq.Protected;
using Silk.NET.SilkTouch.Tests.Common;
using Xunit;

namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests;

public class FieldTests
{
[Fact,
public static IEnumerable<object[]> BogusData => Fakers.FieldSymbol.Generate(Fakers.StandardGenerateCount)
.Select(x => new[] { (object)x });

[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols"),
Trait("Feature", "Fields")]
public void FieldIsVisitedAsField()
public void FieldIsVisitedAsField(FieldSymbol symbol)
{
var symbol = new FieldSymbol(new ExternalTypeReference(null, new IdentifierSymbol("")), new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<FieldSymbol>("VisitField", Times.Once(), ItExpr.IsAny<FieldSymbol>());
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols"),
Trait("Feature", "Fields")]
public void FieldIsVisitedAsMember()
public void FieldIsVisitedAsMember(FieldSymbol symbol)
{
var symbol = new FieldSymbol(new ExternalTypeReference(null, new IdentifierSymbol("")), new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<MemberSymbol>("VisitMember", Times.Once(), ItExpr.IsAny<MemberSymbol>());
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols"),
Trait("Feature", "Fields")]
public void FieldTypeIsVisited()
public void FieldTypeIsVisited(FieldSymbol symbol)
{
var symbol = new FieldSymbol(new ExternalTypeReference(null, new IdentifierSymbol("")), new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<IdentifierSymbol>("VisitIdentifier", Times.Exactly(2), ItExpr.IsAny<IdentifierSymbol>());
.Verify<TypeReference>
("VisitTypeReference", Times.Once(), ItExpr.Is<TypeReference>(x => ReferenceEquals(x, symbol.Type)));
}

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols"),
Trait("Feature", "Fields")]
public void FieldIdentifierIsVisited()
public void FieldIdentifierIsVisited(FieldSymbol symbol)
{
var symbol = new FieldSymbol(new ExternalTypeReference(null, new IdentifierSymbol("")), new IdentifierSymbol(""));
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

visitor.Protected()
.Verify<IdentifierSymbol>
("VisitIdentifier", Times.Exactly(1), ItExpr.Is<IdentifierSymbol>(x => object.ReferenceEquals(x, symbol.Identifier)));
(
"VisitIdentifier",
Times.Once(),
ItExpr.Is<IdentifierSymbol>(x => ReferenceEquals(x, symbol.Identifier))
);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Collections.Generic;
using System.Linq;
using Moq;
using Moq.Protected;
using Silk.NET.SilkTouch.Tests.Common;
using Xunit;

namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests;

public class FunctionPointerTypeReferenceTests
{
[Fact, Trait("Category", "Symbols")]
public void VisitedAsSelf()
public static IEnumerable<object[]> BogusData => Fakers.FunctionPointerTypeReference.Generate(Fakers.StandardGenerateCount)
.Select(x => new[] { (object)x });

[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void VisitedAsSelf(FunctionPointerTypeReference symbol)
{
var symbol = new FunctionPointerTypeReference(new InternalTypeReference(TypeId.CreateNew()), ImmutableArray<TypeReference>.Empty);
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

Expand All @@ -22,10 +28,11 @@ public void VisitedAsSelf()
("VisitFunctionPointerTypeReference", Times.Once(), ItExpr.IsAny<FunctionPointerTypeReference>());
}

[Fact, Trait("Category", "Symbols")]
public void VisitedAsRef()
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void VisitedAsRef(FunctionPointerTypeReference symbol)
{
var symbol = new FunctionPointerTypeReference(new InternalTypeReference(TypeId.CreateNew()), ImmutableArray<TypeReference>.Empty);
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Moq;
using Moq.Protected;
using Silk.NET.SilkTouch.Tests.Common;
using Xunit;

namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests;

public class IdentifierTests
{
public static IEnumerable<object[]> BogusData => Fakers.IdentifierSymbol.Generate(Fakers.StandardGenerateCount)
.Select(x => new[] { (object)x });

[Fact,
[Theory,
MemberData(nameof(BogusData)),
Trait("Category", "Symbols")]
public void IdentifierIsVisitedAsIdentifier()
public void IdentifierIsVisitedAsIdentifier(IdentifierSymbol symbol)
{
var symbol = new IdentifierSymbol("");
var visitor = new Mock<MockSymbolVisitor> { CallBase = true };
visitor.Object.Visit(symbol);

Expand Down
Loading