-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8c5259d
commit 7a15f98
Showing
3 changed files
with
24 additions
and
28 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 |
---|---|---|
|
@@ -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); | ||
|
@@ -148,9 +170,8 @@ public void GroupingTest() | |
{ | ||
Assert.IsNotType<Uses>(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))); | ||
|
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
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