Skip to content

Converter to go from TAML to YAML #42 #81

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions src/dotnet/Taml.sln
Original file line number Diff line number Diff line change
@@ -21,6 +21,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Taml.Configuration", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Taml.Configuration", "Taml.Configuration", "{D8BF9D98-AE40-4736-B471-1A0CD71184C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Yaml.Writer.Taml", "Yaml.Writer.Taml", "{B52120A4-96ED-42B3-8504-69D315916E5F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yaml.Writer.Taml", "Yaml.Writer.Taml\Yaml.Writer.Taml\Yaml.Writer.Taml.csproj", "{80257695-D4DF-4CFB-BCAF-0B9AA559064B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Yaml.Writer.Taml", "Yaml.Writer.Taml\Test.Yaml.Writer.Taml\Test.Yaml.Writer.Taml.csproj", "{6A469558-7825-4D6B-8A19-758C6C2A7C9E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yaml.Writer.Cli", "Yaml.Writer.Taml\Yaml.Writer.Cli\Yaml.Writer.Cli.csproj", "{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -79,13 +87,52 @@ Global
{2CF41FAB-4607-4772-8544-8D2EF8FF9DB8}.Release|x64.Build.0 = Release|Any CPU
{2CF41FAB-4607-4772-8544-8D2EF8FF9DB8}.Release|x86.ActiveCfg = Release|Any CPU
{2CF41FAB-4607-4772-8544-8D2EF8FF9DB8}.Release|x86.Build.0 = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|x64.ActiveCfg = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|x64.Build.0 = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|x86.ActiveCfg = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Debug|x86.Build.0 = Debug|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|Any CPU.Build.0 = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|x64.ActiveCfg = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|x64.Build.0 = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|x86.ActiveCfg = Release|Any CPU
{80257695-D4DF-4CFB-BCAF-0B9AA559064B}.Release|x86.Build.0 = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|x64.Build.0 = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|x86.ActiveCfg = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Debug|x86.Build.0 = Debug|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|Any CPU.Build.0 = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|x64.ActiveCfg = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|x64.Build.0 = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|x86.ActiveCfg = Release|Any CPU
{6A469558-7825-4D6B-8A19-758C6C2A7C9E}.Release|x86.Build.0 = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|x64.ActiveCfg = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|x64.Build.0 = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|x86.ActiveCfg = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Debug|x86.Build.0 = Debug|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|Any CPU.Build.0 = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|x64.ActiveCfg = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|x64.Build.0 = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|x86.ActiveCfg = Release|Any CPU
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{069403C6-DE0A-4043-8D92-88DADE3DB3E2} = {D8BF9D98-AE40-4736-B471-1A0CD71184C7}
{2CF41FAB-4607-4772-8544-8D2EF8FF9DB8} = {D8BF9D98-AE40-4736-B471-1A0CD71184C7}
{80257695-D4DF-4CFB-BCAF-0B9AA559064B} = {B52120A4-96ED-42B3-8504-69D315916E5F}
{6A469558-7825-4D6B-8A19-758C6C2A7C9E} = {B52120A4-96ED-42B3-8504-69D315916E5F}
{20A28BFB-F449-4EB8-9DF2-5732CEC3213C} = {B52120A4-96ED-42B3-8504-69D315916E5F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {407D8799-35B4-4DDC-A878-538CAC2A5CE5}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using TAML;
using TAML.Writer.Yaml;
using Test.Taml;
using Xunit;

namespace Test.Yaml.Writer.Taml.NET.GivenChildArrays
{
public class WhenWriterGivesYaml : BaseFixture
{
protected override string SampleFilename => "GivenChildArrays/childarrays.taml";

[Fact]
public void ShouldFindThreeElements()
{
var tamlDocument = Parser.Parse(base.Sample);
var yamlString = YamlWriter.Write(tamlDocument);

var newLines = yamlString.Split(Environment.NewLine);

Assert.Equal(13, newLines.Length);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
value1
value12
value13
value14
value2
value22
value23
value24
value3
value32
value33
value34
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using TAML;
using TAML.Writer.Yaml;
using Test.Taml;
using Xunit;

namespace Test.Yaml.Writer.Taml.NET.GivenComplexChildDocument
{
public class WhenParsingSampleOne : BaseFixture
{
protected override string SampleFilename => "GivenComplexChildDocument/sample1.taml";

[Fact]
public void ShouldHaveOneRootKey()
{
var result = YamlWriter.Write(Parser.Parse(base.Sample));

var rootLineCount = 0;

foreach (var line in result.Split(Environment.NewLine))
{
if (!line.StartsWith(" ") && line.Length > 2) rootLineCount++;
}

Assert.Equal(1, rootLineCount);
}

[Fact]
public void ShouldHaveCorrectNesting()
{
var expected =
@"root:
- key1: value1
- key2: value2
- key3:
- item1
- item2
- item3
- item4:
- key41: value41
- key42: value42
- key43: value43
- key44: value44
";
var result = YamlWriter.Write(Parser.Parse(base.Sample));

Assert.Equal(expected, result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root
key1 value1
key2 value2
key3
item1
item2
item3
item4
key41 value41
key42 value42
key43 value43
key44 value44
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root1
key1 value1
key2 value2
key3
item1
item2
key4 value4
root2
key41 value41
key42 value42
key43 value43
key44 value44
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Xunit;
using Test.Taml;
using TAML;
using TAML.Writer.Yaml;

namespace Test.Yaml.Writer.Taml.NET.GivenSimpleArray
{
public class WhenWritingYaml : BaseFixture
{
protected override string SampleFilename => "GivenSimpleArray/simple.taml";

[Fact]
public void ThenShouldFindArray()
{
var tamlDocument = Parser.Parse(Sample);

var yamlString = YamlWriter.Write(tamlDocument);

var newLines = yamlString.Split(Environment.NewLine);

Assert.Equal(5, newLines.Length);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
key
value1
value2
value3
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using TAML;
using TAML.Writer.Yaml;
using Test.Taml;
using Xunit;

namespace Test.Yaml.Writer.Taml.NET.Spec_1_1.GivenComments
{
public class WhenReadingComments : BaseFixture
{
protected override string SampleFilename => "Spec_1-1/GivenComments/simple.taml";

[Fact]
public void ThenShouldIgnoreCommentLines()
{
// arrange
var expected = @"key1: value1
key2: value2
";

// act
var result = YamlWriter.Write(Parser.Parse(Sample));

// assert
Assert.Equal(expected, result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
key1 value1
# This is a comment
key2 value2
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Taml\Taml\Taml.csproj" />
<ProjectReference Include="..\..\Taml\Test.Taml\Test.Taml.csproj" />
<ProjectReference Include="..\Yaml.Writer.Taml\Yaml.Writer.Taml.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Spec_1-1\GivenParseDirectives\" />
</ItemGroup>

<ItemGroup>
<None Update="GivenComplexChildDocument\sample1.taml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="GivenComplexChildDocument\sample2.taml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Spec_1-1\GivenComments\simple.taml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions src/dotnet/Yaml.Writer.Taml/Yaml.Writer.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.IO;
using TAML;
using TAML.Writer.Yaml;

namespace Yaml.Writer.Cli
{
internal class Program
{
private static void Main(string[] args)
{
var filename = GetFileName(args);
Console.WriteLine($"Read file: {filename}");
var tamlDoc = Parser.Parse(new StreamReader(File.OpenRead(filename)));

var yaml = YamlWriter.Write(tamlDoc);

Console.WriteLine(yaml);
}

/// <Summary>
/// Find the first file with a `.taml` extension from the command line arguments.
/// If no such file exists then default to `sample1.taml`
/// </Summary>
private static string GetFileName(string[] args)
{
foreach(var arg in args){

if (arg.EndsWith("taml") && File.Exists(arg))
{
return arg;
}
}
return "sample1.taml";
}
}
}
13 changes: 13 additions & 0 deletions src/dotnet/Yaml.Writer.Taml/Yaml.Writer.Cli/Yaml.Writer.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Taml\Taml\Taml.csproj" />
<ProjectReference Include="..\Yaml.Writer.Taml\Yaml.Writer.Taml.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions src/dotnet/Yaml.Writer.Taml/Yaml.Writer.Cli/sample1.taml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root
key1 value1
key2 value2
key3
item1
item2
item3
item4
key41 value41
key42 value42
key43 value43
key44 value44
12 changes: 12 additions & 0 deletions src/dotnet/Yaml.Writer.Taml/Yaml.Writer.Cli/sample2.taml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root1
key1 value1
key2 value2
key3
item1
item2
key4 value4
root2
key41 value41
key42 value42
key43 value43
key44 value44
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.1</Version>
<Authors>Jeffrey T. Fritz and Friends</Authors>
<Description>Yaml writer for TAML</Description>
<Copyright>Copyright Jeffery T. Fritz</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/csharpfritz/TAML</PackageProjectUrl>
<RepositoryUrl>https://github.com/cgleadall/TAML</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<RootNamespace>TAML.Writer.Yaml</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Taml\Taml\Taml.csproj" />
</ItemGroup>

</Project>
Loading