From 7a15f983fc1a4a7c2daf8b0802fccbc5a4a76401 Mon Sep 17 00:00:00 2001 From: caran Date: Tue, 28 May 2024 16:09:09 +0200 Subject: [PATCH] Augment test --- Compiler.Tests/ParsingTests.cs | 43 ++++++++++++++++------------ YangParser/SemanticModel/Augment.cs | 4 --- YangParser/SemanticModel/Grouping.cs | 5 ---- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/Compiler.Tests/ParsingTests.cs b/Compiler.Tests/ParsingTests.cs index 8244ef6..6b80b9b 100644 --- a/Compiler.Tests/ParsingTests.cs +++ b/Compiler.Tests/ParsingTests.cs @@ -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(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("ietf-inet-types@2013-07-15.yang")); var statements = StatementFactory.Create(result); @@ -148,9 +170,8 @@ public void GroupingTest() { Assert.IsNotType(statement); } + Log.Clear(); - output.WriteLine(Log.Content); - output.WriteLine(Clean(compilationUnit.ToCode())); } [Fact] @@ -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))); diff --git a/YangParser/SemanticModel/Augment.cs b/YangParser/SemanticModel/Augment.cs index 0dd0e7e..0edce35 100644 --- a/YangParser/SemanticModel/Augment.cs +++ b/YangParser/SemanticModel/Augment.cs @@ -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); - } } \ No newline at end of file diff --git a/YangParser/SemanticModel/Grouping.cs b/YangParser/SemanticModel/Grouping.cs index 38b83f6..0d01b78 100644 --- a/YangParser/SemanticModel/Grouping.cs +++ b/YangParser/SemanticModel/Grouping.cs @@ -109,9 +109,4 @@ public IStatement[] WithUse(Uses use) return Children; } - - protected override void ValidateParent() - { - this.GetModule()?.Groupings.Add(this); - } } \ No newline at end of file