Skip to content

Commit

Permalink
Added test for generated api
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesjs committed Jan 4, 2025
1 parent 094133a commit 8de2449
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 0 deletions.
253 changes: 253 additions & 0 deletions src/SuperFluid.Tests/PgfPlotsBuilder.fluid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
Name: "IPgfPlotBuilder"
Namespace: "PgfPlotsSdk.Public.Generated"
InitialState:
Name: "CreateBuilder"
CanTransitionTo:
- "AddPgfPlotWithAxes"
- "AddPgfPlot"
- "AddFigure"
Methods:
- Name: "AddFigure"
ReturnType: "FigureBuilder"
Arguments:
- Name: "figureOptions"
Type: "FigureOptions?"
CanTransitionTo:
- "AddPgfPlotWithAxes"
- "AddPgfPlot"
- "SetCaption"
- "SetLabel"
- "SetPlacementFlag"
- Name: "AddPgfPlotWithAxes"
Arguments:
- Name: "axisType"
Type: "AxisType"
- Name: "options"
Type: "AxisOptions?"
CanTransitionTo: &AxisSettingsCircular
- "AddPlot"
- "SetXLabel"
- "SetYLabel"
- "SetXMin"
- "SetYMin"
- "SetXMax"
- "SetYMax"
- "SetMinorXTickNumber"
- "SetMinorYTickNumber"
- "SetXTicks"
- "SetYTicks"
- "SetGrid"
- Name: "SetXLabel"
Arguments:
- Name: "label"
Type: "string?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetYLabel"
Arguments:
- Name: "label"
Type: "string?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetXMin"
Arguments:
- Name: "min"
Type: "float?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetYMin"
Arguments:
- Name: "min"
Type: "float?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetXMax"
Arguments:
- Name: "max"
Type: "float?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetYMax"
Arguments:
- Name: "max"
Type: "float?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetMinorXTickNumber"
Arguments:
- Name: "number"
Type: "int?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetMinorYTickNumber"
Arguments:
- Name: "number"
Type: "int?"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetXTicks"
Arguments:
- Name: "ticks"
Type: "params float[]"
CanTransitionTo: *AxisSettingsCircular
- Name: "SetYTicks"
Arguments:
- Name: "ticks"
Type: "params float[]"
CanTransitionTo: *AxisSettingsCircular
- Name: "AddPgfPlot"
CanTransitionTo:
- "AddPie"
- Name: "AddPie"
Arguments:
- Name: "slices"
Type: "IEnumerable<PieChartSliceData<T>>"
- Name: "options"
Type: "PieChartOptions?"
CanTransitionTo: &PieSettingsCircular
- "AddPie"
- "Build"
- "SetRadius"
- "SetHideNumber"
- "SetReferenceSum"
- "SetRotation"
- "SetCentrePosition"
- "SetScaleFont"
- "SetSliceColours"
- "SetTextPosition"
- "SetAfterNumberText"
- "SetBeforeNumberText"
- "SetPieChartType"
- "SetSliceExplosionFactors"
- Name: "SetRadius"
Arguments:
- Name: "radius"
Type: "float?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetHideNumber"
Arguments:
- Name: "enabled"
Type: "bool?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetReferenceSum"
Arguments:
- Name: "referenceSum"
Type: "float?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetRotation"
Arguments:
- Name: "rotation"
Type: "float?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetCentrePosition"
Arguments:
- Name: "x"
Type: "float"
- Name: "y"
Type: "float"
CanTransitionTo: *PieSettingsCircular
- Name: "SetScaleFont"
Arguments:
- Name: "enabled"
Type: "bool?"
- Name: "SetSliceColours"
Arguments:
- Name: "colours"
Type: "params LatexColour[]"
CanTransitionTo: *PieSettingsCircular
- Name: "SetTextPosition"
Arguments:
- Name: "textPosition"
Type: "PieTextOption?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetAfterNumberText"
Arguments:
- Name: "afterText"
Type: "string?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetBeforeNumberText"
Arguments:
- Name: "beforeText"
Type: "string?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetPieChartType"
Arguments:
- Name: "type"
Type: "PieType?"
CanTransitionTo: *PieSettingsCircular
- Name: "SetSliceExplosionFactors"
Arguments:
- Name: "factors"
Type: "params float[]"
CanTransitionTo: *PieSettingsCircular
- Name: "AddPlot"
Arguments:
- Name: "data"
Type: "IEnumerable<LatexData>"
- Name: "options"
Type: "PlotOptions?"
CanTransitionTo: &PlotOptionsCircular
- "AddPlot"
- "Build"
- "SetColour"
- "SetBarType"
- "SetMark"
- "SetSmooth"
- "SetBarWidth"
- "SetFillColour"
- "SetFillOpacity"
- "SetLineStyle"
- "SetLineWidth"
- "SetMarkSize"
- "SetOnlyMarks"
- Name: "SetColour"
Arguments:
- Name: "colour"
Type: "LatexColour?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetBarType"
Arguments:
- Name: "type"
Type: "BarType?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetMark"
Arguments:
- Name: "mark"
Type: "PlotMark?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetSmooth"
Arguments:
- Name: "enabled"
Type: "bool?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetBarWidth"
Arguments:
- Name: "width"
Type: "float?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetFillColour"
Arguments:
- Name: "colour"
Type: "LatexColour?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetFillOpacity"
Arguments:
- Name: "opacity"
Type: "float?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetLineStyle"
Arguments:
- Name: "style"
Type: "LineStyle?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetLineWidth"
Arguments:
- Name: "width"
Type: "float?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetMarkSize"
Arguments:
- Name: "size"
Type: "float?"
CanTransitionTo: *PlotOptionsCircular
- Name: "SetOnlyMarks"
Arguments:
- Name: "enabled"
Type: "bool?"
CanTransitionTo: *PlotOptionsCircular
- Name: "Build"
Arguments: []
CanTransitionTo: []
ReturnType: "string"
89 changes: 89 additions & 0 deletions src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using SuperFluid.Tests.Cars;

namespace SuperFluid.Tests.SourceGenerators;

public class GeneratedBuilderTests
{
/// <summary>
/// The real test is if this builds
/// </summary>
[Fact]
public void CanGenerateDemoApi()
{
string states = CarActor.Initialize()
.Unlock()
.Enter()
.Start(10, "right")
.Stop()
.Start(20, "left")
.Stop()
.Exit()
.Enter()
.Start(30, "right")
.Stop()
.Exit()
.Lock()
.Build("red");

states.ShouldBe("Unlock Enter Start 10 right Stop Start 20 left Stop Exit Enter Start 30 right Stop Exit Lock Build red");
}


private class CarActor : ICarActor

Check failure on line 32 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

'GeneratedBuilderTests.CarActor' does not implement interface member 'ICanLockOrEnter.Lock()'. 'GeneratedBuilderTests.CarActor.Lock()' cannot implement 'ICanLockOrEnter.Lock()' because it does not have the matching return type of 'ICanUnlock'.

Check failure on line 32 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

'GeneratedBuilderTests.CarActor' does not implement interface member 'ICanStartOrExit.Start(int, string)'. 'GeneratedBuilderTests.CarActor.Start(int, string)' cannot implement 'ICanStartOrExit.Start(int, string)' because it does not have the matching return type of 'ICanStopOrBuild'.
{
private readonly List<string> _states = [];

public ICanUnlockOrBuild Lock()

Check failure on line 36 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

The type or namespace name 'ICanUnlockOrBuild' could not be found (are you missing a using directive or an assembly reference?)
{
_states.Add("Lock");
return this;
}

public ICanStartOrExit Enter()
{
_states.Add("Enter");
return this;
}

ICanLockOrEnter ICanUnlockOrBuild.Unlock()

Check failure on line 48 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

The type or namespace name 'ICanUnlockOrBuild' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

'ICanUnlockOrBuild' in explicit interface declaration is not an interface
{
_states.Add("Unlock");
return this;
}

public static ICanUnlock Initialize()
{
return new CarActor();
}

public string Build(string colour)
{
_states.Add($"Build {colour}");
return string.Join(" ", _states);
}

public ICanStop Start(int speed, string direction)

Check failure on line 65 in src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Test Project

The type or namespace name 'ICanStop' could not be found (are you missing a using directive or an assembly reference?)
{
_states.Add($"Start {speed} {direction}");
return this;
}

public ICanLockOrEnter Exit()
{
_states.Add("Exit");
return this;
}

public ICanStartOrExit Stop()
{
_states.Add("Stop");
return this;
}

ICanLockOrEnter ICanUnlock.Unlock()
{
_states.Add("Unlock");
return this;
}
}
}
4 changes: 4 additions & 0 deletions src/SuperFluid.Tests/SuperFluid.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
<ItemGroup>
<ProjectReference Include="../SuperFluid/SuperFluid.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="DemoApiDefinition.fluid.yml" />
</ItemGroup>
</Project>

0 comments on commit 8de2449

Please sign in to comment.