Skip to content

Commit

Permalink
Merge pull request #20 from hughesjs/enable-cd
Browse files Browse the repository at this point in the history
Enable cd
  • Loading branch information
hughesjs authored Jun 13, 2023
2 parents cdaa64d + 07d7f8a commit 574efc0
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 17 deletions.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/DemoProject/DemoProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="SuperFluid" Version="0.0.2" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions src/DemoProject/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using SuperFluid.Tests.Cars;

string builtString = Test.Initialize()
.Unlock()
.Enter()
.Start()
.Stop()
.Exit()
.Lock()
.Unlock()
.Enter()
.Start()
.Build();

Console.WriteLine(builtString);

public class Test : ICarActor
{

private readonly List<string> _calls = new();

public ICanUnlock Lock()
{
_calls.Add("Lock!");
return this;
}

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


public ICanLockOrEnter Unlock()
{
_calls.Add("Unlock!");
return this;
}

public ICanStopOrBuild Start()
{
_calls.Add("Start!");
return this;
}

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

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

public string Build() => string.Join('\n', _calls);

public static ICanUnlock Initialize() => new Test();
}
7 changes: 0 additions & 7 deletions src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ public class FluidApiDefinitionParserTests
CanTransitionTo = new()
};

private readonly FluidApiMethodDefinition _build = new()
{
Name = "Build",
ReturnType = "string",
CanTransitionTo = new()
};

[Fact]
public void CanDeserializeSimpleCase()
{
Expand Down
7 changes: 0 additions & 7 deletions src/SuperFluid.Tests/SuperFluid.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
<OutputType>Library</OutputType>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,10 +30,4 @@
<ItemGroup>
<ProjectReference Include="../SuperFluid/SuperFluid.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
</ItemGroup>


<ItemGroup>
<AdditionalFiles Include="**/*.fluid.yml" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/SuperFluid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperFluid", "SuperFluid\Su
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperFluid.Tests", "SuperFluid.Tests\SuperFluid.Tests.csproj", "{6C2B21F8-301C-4062-9C12-608DAF4C0E16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoProject", "DemoProject\DemoProject.csproj", "{FA0C7E98-6910-4226-A706-B9B0A0D529A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,5 +24,9 @@ Global
{F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Release|Any CPU.Build.0 = Release|Any CPU
{FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions src/SuperFluid/Internal/Model/FluidApiMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public FluidApiMethod(string name, string? returnType, IEnumerable<FluidApiMetho
CanTransitionTo = transitions.ToHashSet();
}

internal string Name { get; init; }
internal string? ReturnType { get; init; }
internal string Name { get; init; }

internal string? ReturnType { get; init; }
internal HashSet<FluidApiMethod> CanTransitionTo { get; init; } = new();
}
15 changes: 15 additions & 0 deletions src/SuperFluid/Internal/Services/FluidGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,25 @@ public Dictionary<string, string> Generate(string rawYml)
FluidApiModel model = _definitionParser.Parse(definition);

Dictionary<string, string> newSourceFiles = model.States.ToDictionary(s => $"{s.Name}.fluid.g.cs", s => GenerateStateSource(s, model));

newSourceFiles.Add($"{model.Name}.fluid.g.cs", GenerateCompoundInterface(model));

return newSourceFiles;
}

private string GenerateCompoundInterface(FluidApiModel model)
{
string source = $$"""
namespace {{model.Namespace}};
public interface {{model.Name}}: {{string.Join(',', model.States.Select(s => s.Name))}}
{
public static abstract {{model.InitializerMethodReturnState.Name}} {{model.InitialMethod.Name}}();
}
""";
return source;
}

private string GenerateStateSource(FluidApiState fluidApiState, FluidApiModel model)
{
IEnumerable<string> methodDeclarations = fluidApiState.MethodTransitions.Select(kvp
Expand Down

0 comments on commit 574efc0

Please sign in to comment.