Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions tests/CommonNovel.Tests/Noder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@ namespace CommonNovel.Tests;

public partial class CompilerUnitTest
{
[Fact]
public void TestNoder()
[Theory]
[MemberData(nameof(NoderTestData))]
public void TestNoder(string input, string[] expectedNodes)
{
// Arrange
string input =
"""
- Alice
[Hi, Bob!]

- Bob
[Alice!]

""";

string[] expectedNodes =
[
"""
- Alice
[Hi, Bob!]
""",
"""
- Bob
[Alice!]
"""
];

// Act
string[] nodes = Compiler.Noder(input);

Expand All @@ -38,4 +16,32 @@ public void TestNoder()
Assert.Equal(expectedNodes[i], nodes[i]);
}
}

private static readonly string Nl = Environment.NewLine;

public static IEnumerable<object[]> NoderTestData =>
new List<object[]>
{
new object[] // CRLF
{
"- Alice\r\n[Hi, Bob!]\r\n\r\n- Bob\r\n[Alice!]\r\n\r\n",
(string[])[
$"- Alice{Nl}[Hi, Bob!]", // Future -> "\r\n"
$"- Bob{Nl}[Alice!]" // Future -> "\r\n"
]
},
new object[] // LF
{
"- Alice\n[Hi, Bob!]\n\n- Bob\n[Alice!]\n\n",
(string[])[
$"- Alice{Nl}[Hi, Bob!]", // Future -> '\n'
$"- Bob{Nl}[Alice!]" // Future -> '\n'
]
},
new object[] // three enters
{
"\r\n\r\n\r\n",
(string[])[] // Future -> [ "", "" ]
}
};
}
76 changes: 31 additions & 45 deletions tests/CommonNovel.Tests/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@

public partial class CompilerUnitTest
{
[Fact]
public void TestParser()
[Theory]
[MemberData(nameof(ParserTestData))]
public void TestParser(string inputNode, string[][] expectedAST)
{
// Arrange
string inputNode =
"""
- Alice
[Hi, there.]
""";

// [<type>, <arg>]
string[][] expectedAST =
[
["CharacterName", "Alice"],
["Messages", "Hi, there."]
];

// Act
string[][] ast = Compiler.Parse(inputNode);

Expand All @@ -33,35 +20,34 @@ public void TestParser()
}
}

// This is an example for deplication of same command
[Fact]
public void TestParser_Ex3()
{
// Arrange
string inputNode =
"""
- Alice
[Hi, there.]
[Welcome!]
""";

// [<type>, <arg>]
string[][] expectedAST =
[
["CharacterName", "Alice"],
["Messages", "Welcome!"]
];

// Act
string[][] ast = Compiler.Parse(inputNode);

// Assert
// Assert.Equal(expectedAST.Length, ast.Length);
// for (int i = 0; i < expectedAST.Length; i++)
// {
// Assert.Equal(expectedAST[i], ast[i]);
// }
}
public static IEnumerable<object[]> ParserTestData =>
new List<object[]>
{
new object[] // CRLF
{
"- Alice\r\n[Hi, there.]",
(string[][])[
["CharacterName", "Alice"],
["Messages", "Hi, there."]
]
},
new object[] // LF
{
"- Alice\n[Hi, there.]",
(string[][])[
["CharacterName", "Alice"],
["Messages", "Hi, there."]
]
},
// new object[] // Example3 (Future)
// {
// "- Alice\r\n[Hi, there.]\r\n[Welcome!]",
// (string[][])[
// ["CharacterName", "Alice"],
// ["Messages", "Welcome!"]
// ]
// }
};

[Theory]
[InlineData("- Alice", new[] { "CharacterName", "Alice" })]
Expand Down
Loading