Skip to content

Commit

Permalink
Add test for double nested structs
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Nov 25, 2024
1 parent f97e27b commit 62ce8f5
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ MODEL TestModel (de) AT "http://models.geow.cloud" VERSION "1" =
END TestModel.
""";

private const string TestModelDoubleNestedStruct = """
INTERLIS 2.4;
MODEL TestModel (de) AT "http://models.geow.cloud" VERSION "1" =
TOPIC TestTopic =
STRUCTURE TestStructLevel1 =
attr1: TestStructLevel2;
attr2: MANDATORY (value1, value2);
END TestStructLevel1;
STRUCTURE TestStructLevel2 =
attr1: MANDATORY TEXT*50;
attr2: 0..30;
END TestStructLevel2;
CLASS TestClass =
attr1: MANDATORY TestStructLevel1;
attr2: 10..20;
END TestClass;
END TestTopic;
END TestModel.
""";

[TestMethod]
public void TestInterlisFile()
{
Expand Down Expand Up @@ -190,6 +213,65 @@ public void TestInterlisFileNestedStruct()
| attr2 | 1 | (<b>value1</b>, <b>value2</b>) |
""";

Assert.AreEqual(expected.ReplaceLineEndings(), documentation.ReplaceLineEndings());
}

[TestMethod]
public void TestInterlisFileDoubleNestedStruct()
{
var reader = new InterlisReader();
var interlisFile = reader.ReadFile(new StringReader(TestModelDoubleNestedStruct));

var visitor = new MarkdownDocumentationVisitor();
visitor.VisitInterlisFile(interlisFile);
var documentation = visitor.GetDocumentation();

const string structLevel2InlineTable =
"<table>" +
"<thead>" +
"<tr><th>Attributname</th><th>Kardinalität</th><th>Typ</th></tr>" +
"</thead>" +
"<tbody>" +
"<tr><td>attr1</td><td>1</td><td>Text [50]</td></tr>" +
"<tr><td>attr2</td><td>0..1</td><td>0..30</td></tr>" +
"</tbody>" +
"</table>";

const string structLevel1InlineTable =
"<table>" +
"<thead>" +
"<tr><th>Attributname</th><th>Kardinalität</th><th>Typ</th></tr>" +
"</thead>" +
"<tbody>" +
"<tr><td>attr1</td><td>0..1</td><td>TestStructLevel2<br/>" + structLevel2InlineTable + "</td></tr>" +
"<tr><td>attr2</td><td>1</td><td>(<b>value1</b>, <b>value2</b>)</td></tr>" +
"</tbody>" +
"</table>";

var expected = $"""
# TestModel
## TestTopic
### TestStructLevel1
| Attributname | Kardinalität | Typ |
| --- | --- | --- |
| attr1 | 0..1 | TestStructLevel2<br/>{structLevel2InlineTable} |
| attr2 | 1 | (<b>value1</b>, <b>value2</b>) |
### TestStructLevel2
| Attributname | Kardinalität | Typ |
| --- | --- | --- |
| attr1 | 1 | Text [50] |
| attr2 | 0..1 | 0..30 |
### TestClass
| Attributname | Kardinalität | Typ |
| --- | --- | --- |
| attr1 | 1 | TestStructLevel1<br/>{structLevel1InlineTable} |
| attr2 | 0..1 | 10..20 |
""";

Assert.AreEqual(expected.ReplaceLineEndings(), documentation.ReplaceLineEndings());
Expand Down

0 comments on commit 62ce8f5

Please sign in to comment.