-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using DotNetGraph.Compilation; | ||
using DotNetGraph.Core; | ||
using DotNetGraph.Extensions; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DotNetGraph.Tests.Core; | ||
|
||
[TestClass] | ||
public class DotGroupTests | ||
{ | ||
[TestMethod] | ||
public async Task EmptyGroupElements() | ||
{ | ||
var group = new DotGroup(); | ||
|
||
await using var writer = new StringWriter(); | ||
var context = new CompilationContext(writer, new CompilationOptions()); | ||
await group.CompileAsync(context); | ||
|
||
var result = writer.GetStringBuilder().ToString(); | ||
result.Should().Be("{\n}\n"); | ||
} | ||
[TestMethod] | ||
public async Task GroupElementsAndAttributes() | ||
{ | ||
var group = new DotGroup().WithAttribute("rank", "same"); | ||
group.Add(new DotNode().WithIdentifier("node-1")); | ||
group.Add(new DotNode().WithIdentifier("node-2")); | ||
|
||
|
||
await using var writer = new StringWriter(); | ||
var context = new CompilationContext(writer, new CompilationOptions()); | ||
await group.CompileAsync(context); | ||
|
||
var result = writer.GetStringBuilder().ToString(); | ||
result.Should().Be("{\n\t\"rank\"=same\n\t\"node-1\"\n\t\"node-2\"\n}\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading.Tasks; | ||
using DotNetGraph.Compilation; | ||
|
||
namespace DotNetGraph.Core | ||
{ | ||
public class DotGroup : DotBaseGraph | ||
{ | ||
public override async Task CompileAsync(CompilationContext context) | ||
{ | ||
await context.WriteIndentationAsync(); | ||
await context.WriteLineAsync("{"); | ||
++context.IndentationLevel; | ||
await CompileAttributesAsync(context); | ||
foreach (var element in Elements) | ||
await element.CompileAsync(context); | ||
--context.IndentationLevel; | ||
await context.WriteIndentationAsync(); | ||
await context.WriteLineAsync("}"); | ||
} | ||
} | ||
} |