Skip to content

Commit

Permalink
Update parsein tests
Browse files Browse the repository at this point in the history
- Length shouldn't include the terminating null
- Just null should return a length of zero, those zero for expected
- Added Test for trailing space
  • Loading branch information
enusbaum committed Aug 27, 2024
1 parent 7300d59 commit 178d5ed
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/parsin_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ public class parsin_Tests : ExportedModuleTestBase
private const ushort PARSIN_ORDINAL = 467;

[Theory]
[InlineData("TEST1 TEST2 TEST3\0", 3, 18)]
[InlineData("TEST1 TEST2 TEST3\0", 3, 17)]
[InlineData("\0", 0, 0)]
[InlineData("A B\0", 2, 4)]
[InlineData("A TEST B\0", 3, 9)]
[InlineData("A TEST B\0", 3, 20)]
[InlineData("A TEST B\0", 3, 34)]
[InlineData("A B\0", 2, 3)]
[InlineData("A TEST B\0", 3, 8)]
[InlineData("A TEST B\0", 3, 19)]
[InlineData("A TEST B\0", 3, 33)]
[InlineData("TEST \0", 1, 5)]
public void parsin_Test(string inputCommand, int expectedMargc, int expectedInputLength)
{
//Reset State
Reset();

//Set Input Values
mbbsEmuMemoryCore.SetArray("INPUT", Encoding.ASCII.GetBytes(inputCommand));
mbbsEmuMemoryCore.SetWord("INPLEN", (ushort)inputCommand.Length);
mbbsEmuMemoryCore.SetWord("INPLEN", (ushort)inputCommand.Replace("\0", string.Empty).Length);

ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, PARSIN_ORDINAL, new List<FarPtr>());

//Verify Results
var expectedParsedInput = Encoding.ASCII.GetBytes(inputCommand.Replace(' ', '\0'));
var expectedParsedInput = Encoding.ASCII.GetBytes(inputCommand.Replace(' ', '\0')[..expectedInputLength]);
var actualInputLength = mbbsEmuMemoryCore.GetWord("INPLEN");
var actualMargc = mbbsEmuMemoryCore.GetWord("MARGC");

//Just NULL returns a length of 0, but we'll grab & verify the null at that position if the length is zero
var actualInput = mbbsEmuMemoryCore.GetArray("INPUT", actualInputLength == 0 ? (ushort)1 : actualInputLength).ToArray();
var actualInput = mbbsEmuMemoryCore.GetArray("INPUT", actualInputLength).ToArray();

Assert.Equal(expectedMargc, actualMargc); //Verify Correct Number of Commands Parsed
Assert.Equal(expectedInputLength, actualInputLength); //Verify Length is Correct
Expand Down

0 comments on commit 178d5ed

Please sign in to comment.