diff options
Diffstat (limited to 'src/marlin.tests')
| -rw-r--r-- | src/marlin.tests/VariableExpanderTests.cs | 39 | ||||
| -rw-r--r-- | src/marlin.tests/marlin.tests.csproj | 27 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/marlin.tests/VariableExpanderTests.cs b/src/marlin.tests/VariableExpanderTests.cs new file mode 100644 index 0000000..c04152e --- /dev/null +++ b/src/marlin.tests/VariableExpanderTests.cs @@ -0,0 +1,39 @@ +namespace marlin.tests; + +using core.util; + +public class VariableExpanderTests +{ + private Dictionary<string, string> _variables = new(); + + [SetUp] + public void Setup() + { + this._variables["name"] = "john"; + this._variables["branch"] = "master"; + } + + [TestCase("hello world", "hello world")] // passthroughs + [TestCase("hi {name}!", "hi john!")] // classic variable expansion + [TestCase("hi {name=bob}!", "hi john!")] // existent variable with fallback + [TestCase("hi {nonvar=bob}!", "hi bob!")] // non-existent variable with fallback + [TestCase("hi {name? plane}!", "hi plane!")] // use value if set + [TestCase("hi {nonvar? plane}!", "hi !")] // omit value if not set + [TestCase("mycommand {--checkout branch}", "mycommand --checkout master")] // inject cli arg when set + [TestCase("mycommand {--checkout nonvar}", "mycommand")] // omit cli arg when not set + [TestCase("i will {{escape}}", "i will {escape}")] // escaping works + public void ExpansionMatches(string input, string output) + { + var result = VariableExpander.Expand(input, this._variables); + Assert.That(result, Is.EqualTo(output)); + } + + [TestCase("un {", typeof(UnmatchedBraceException))] // unmatched leading + [TestCase("un }", typeof(UnmatchedBraceException))] // unmatched trailing + [TestCase("{nonvar}", typeof(VariableNotFoundException))] // non existent variable + public void ExpansionFails(string input, Type exceptionType) + { + Assert.That(() => VariableExpander.Expand(input, this._variables), + Throws.TypeOf(exceptionType)); + } +}
\ No newline at end of file diff --git a/src/marlin.tests/marlin.tests.csproj b/src/marlin.tests/marlin.tests.csproj new file mode 100644 index 0000000..4444823 --- /dev/null +++ b/src/marlin.tests/marlin.tests.csproj @@ -0,0 +1,27 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net10.0</TargetFramework> + <LangVersion>latest</LangVersion> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + <IsPackable>false</IsPackable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="coverlet.collector" Version="6.0.4"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0"/> + <PackageReference Include="NUnit" Version="4.3.2"/> + <PackageReference Include="NUnit.Analyzers" Version="4.7.0"/> + <PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/> + </ItemGroup> + + <ItemGroup> + <Using Include="NUnit.Framework"/> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\marlin.core\marlin.core.csproj" /> + </ItemGroup> + +</Project> |
