Skip to content

Commit

Permalink
Augment test
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed May 28, 2024
1 parent 8c5259d commit 7a15f98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
43 changes: 24 additions & 19 deletions Compiler.Tests/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,29 @@ namespace Compiler.Tests;
public class ParsingTests(ITestOutputHelper output)
{
[Fact]
public void IetfYangLibrary()
public void AugmentationIsFoundTest()
{
var top = StatementFactory.Create(Parser.Parse("memory",
"""
module test {
prefix this;
yang-version 1.1;
namespace "urn:ns:test";
augment a;
augment b;
}
"""));
Assert.IsType<Module>(top);
if (top is Module module)
{
Assert.Equal(2, module.Augments.Count);
Assert.Equal("a",module.Augments[0].Argument);
Assert.Equal("b",module.Augments[1].Argument);
}
}

[Fact]
public void BaseParsingTest()
{
var result = Parser.Parse("memory", File.ReadAllText("[email protected]"));
var statements = StatementFactory.Create(result);
Expand Down Expand Up @@ -148,9 +170,8 @@ public void GroupingTest()
{
Assert.IsNotType<Uses>(statement);
}

Log.Clear();
output.WriteLine(Log.Content);
output.WriteLine(Clean(compilationUnit.ToCode()));
}

[Fact]
Expand Down Expand Up @@ -180,22 +201,6 @@ public void UnwrapTest()
}
}

private void Print(YangStatement statement, int indent = 0)
{
var terminator = statement.Children.Count == 0 ? ";" : "";
var tabs = new StringBuilder();
for (var i = 0; i < indent; i++)
{
tabs.Append('\t');
}

output.WriteLine($"{tabs}{statement.Prefix}{statement.Keyword} {statement.Argument}{terminator}");
if (statement.Children.Count <= 0) return;
output.WriteLine($"{tabs}{{");
foreach (var sub in statement.Children) Print(sub, indent + 1);
output.WriteLine($"{tabs}}}");
}

private string Clean(string input)
{
return string.Join("\n", input.Split('\n').Where(line => !string.IsNullOrWhiteSpace(line)));
Expand Down
4 changes: 0 additions & 4 deletions YangParser/SemanticModel/Augment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ public Augment(YangStatement statement) : base(statement)
new ChildRule(Uses.Keyword, Cardinality.ZeroOrMore),
new ChildRule(Keyword, Cardinality.ZeroOrMore)
];
protected override void ValidateParent()
{
this.GetModule()?.Augments.Add(this);
}
}
5 changes: 0 additions & 5 deletions YangParser/SemanticModel/Grouping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,4 @@ public IStatement[] WithUse(Uses use)

return Children;
}

protected override void ValidateParent()
{
this.GetModule()?.Groupings.Add(this);
}
}

0 comments on commit 7a15f98

Please sign in to comment.