Skip to content
Snippets Groups Projects
Commit c2631da8 authored by Tom Lambert's avatar Tom Lambert
Browse files

TestWriter scaffold

parent 628c85d9
Branches
No related merge requests found
/obj/
/bin/
/.vs/
/output/
\ No newline at end of file
namespace compiler
{
public interface IWriter
{
void Write(string path, TestParser.Node rootNode);
}
}
using System.IO;
namespace compiler
{
public class MonitorPyWriter : IWriter
{
public void Write(string path, TestParser.Node rootNode)
{
var targetFile = Path.Combine(path, "monitor.py");
File.WriteAllText(targetFile, $@"
# ToDo: Add Python Code
");
}
}
}
using System.IO;
namespace compiler
{
public class ObstaclePyWriter : IWriter
{
public void Write(string path, TestParser.Node rootNode)
{
var targetFile = Path.Combine(path, "obstacle.py");
File.WriteAllText(targetFile, $@"
# ToDo: Add Python Code
");
}
}
}
using System;
using System.IO;
using System.Linq;
namespace compiler
......@@ -16,23 +17,27 @@ namespace compiler
}
var sourceDirectory = args[0];
var sourceFiles = System.IO.Directory.GetFiles(sourceDirectory, "*.uml");
var targetDirectory = args[1];
if (Directory.Exists(targetDirectory))
{
Directory.Delete(targetDirectory, true);
}
var sourceFiles = Directory.GetFiles(sourceDirectory, "*.uml", SearchOption.AllDirectories);
foreach (var sourceFile in sourceFiles)
{
Console.WriteLine("New file: " + sourceFile);
var baseName = sourceFile.Substring(sourceDirectory.Length + 1);
Console.WriteLine("Processing file: " + baseName);
var rootNodes = TestParser.ReadFile(sourceFile).ToList();
// thw following is just for testing
foreach (var rootNode in rootNodes)
for (var i = 0; i < rootNodes.Count; i++)
{
Console.WriteLine("New rootNode");
var node = rootNode;
while (node != null)
{
Console.WriteLine(node.Text);
Console.WriteLine(node.Data?.Select(x => " " + x)?.Aggregate((x, y) => x + "\n" + y));
node = node.Next;
}
var rootNode = rootNodes[i];
var path = Path.Combine(targetDirectory, @$"{baseName}-{i}");
Directory.CreateDirectory(path);
TestWriter.WriteAll(path, rootNode);
}
}
}
......
......@@ -2,7 +2,7 @@
"profiles": {
"compiler": {
"commandName": "Project",
"commandLineArgs": "../../../tests ../../../output"
"commandLineArgs": "../../../TestSpec ../../../output"
}
}
}
\ No newline at end of file
namespace compiler
using System.Collections.Generic;
namespace compiler
{
public static class TestWriter
{
public static void WriteAll(string path, TestParser.Node rootNode)
{
var writers = new List<IWriter>();
writers.Add(new MonitorPyWriter());
writers.Add(new ObstaclePyWriter());
writers.Add(new WorldWriter());
foreach (var writer in writers)
{
writer.Write(path, rootNode);
}
}
}
}
using System.IO;
namespace compiler
{
public class WorldWriter : IWriter
{
public void Write(string path, TestParser.Node rootNode)
{
var targetFile = Path.Combine(path, "test.world");
File.WriteAllText(targetFile, $@"
");
}
}
}
......@@ -5,4 +5,17 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Tests\**" />
<EmbeddedResource Remove="Tests\**" />
<None Remove="Tests\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment