From 8de24494e2d6e137ab8559b90ecfd3f53d5a4af6 Mon Sep 17 00:00:00 2001 From: James Hughes Date: Sat, 4 Jan 2025 00:31:53 +0000 Subject: [PATCH] Added test for generated api --- .../PgfPlotsBuilder.fluid.yml | 253 ++++++++++++++++++ .../SourceGenerators/GeneratedBuilderTests.cs | 89 ++++++ src/SuperFluid.Tests/SuperFluid.Tests.csproj | 4 + 3 files changed, 346 insertions(+) create mode 100644 src/SuperFluid.Tests/PgfPlotsBuilder.fluid.yml create mode 100644 src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs diff --git a/src/SuperFluid.Tests/PgfPlotsBuilder.fluid.yml b/src/SuperFluid.Tests/PgfPlotsBuilder.fluid.yml new file mode 100644 index 0000000..b38f204 --- /dev/null +++ b/src/SuperFluid.Tests/PgfPlotsBuilder.fluid.yml @@ -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>" + - 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" + - 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" diff --git a/src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs b/src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs new file mode 100644 index 0000000..94521d9 --- /dev/null +++ b/src/SuperFluid.Tests/SourceGenerators/GeneratedBuilderTests.cs @@ -0,0 +1,89 @@ +using SuperFluid.Tests.Cars; + +namespace SuperFluid.Tests.SourceGenerators; + +public class GeneratedBuilderTests +{ + /// + /// The real test is if this builds + /// + [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 + { + private readonly List _states = []; + + public ICanUnlockOrBuild Lock() + { + _states.Add("Lock"); + return this; + } + + public ICanStartOrExit Enter() + { + _states.Add("Enter"); + return this; + } + + ICanLockOrEnter ICanUnlockOrBuild.Unlock() + { + _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) + { + _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; + } + } +} diff --git a/src/SuperFluid.Tests/SuperFluid.Tests.csproj b/src/SuperFluid.Tests/SuperFluid.Tests.csproj index f7dd90e..ddc247e 100644 --- a/src/SuperFluid.Tests/SuperFluid.Tests.csproj +++ b/src/SuperFluid.Tests/SuperFluid.Tests.csproj @@ -31,4 +31,8 @@ + + + +