Skip to content

Commit

Permalink
Move some of the tests around and add some tests for the case insensi…
Browse files Browse the repository at this point in the history
…tve section parsing.
  • Loading branch information
sciguyryan committed Feb 5, 2025
1 parent b8732fb commit 47fb6dc
Showing 1 changed file with 46 additions and 23 deletions.
69 changes: 46 additions & 23 deletions redox-core/src/parsing/asm_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,19 +1249,56 @@ mod tests_asm_parsing {
}
}

#[test]
fn section_parser_tests() {
let tests = [
// The text section is a valid section.
ParserTest::new(
"section .text",
&[],
false,
"failed to parse valid section.",
),
// The section label should be automatically converted to lowercase, which renders it correct.
ParserTest::new(
"section .TEXT",
&[],
false,
"failed to parse valid section.",
),
// This is invalid because there must be something after the section marker.
ParserTest::new(
"section",
&[],
true,
"succeeded in parsing invalid section marker.",
),
// This is invalid because the section marker isn't valid.
ParserTest::new(
"section abc",
&[],
true,
"succeeded in parsing invalid section marker.",
),
];

ParserTests::new(&tests).run_all();
}

#[test]
fn code_misc_tests() {
let tests = [
// Testing line continuation.
ParserTest::new(
"mov eax,\\\r\nebx",
&[Instruction::MovU32RegU32Reg(
RegisterId::EAX,
RegisterId::EBX,
)],
false,
"failed to correctly parse instruction.",
)];
"mov eax,\\\r\nebx",
&[Instruction::MovU32RegU32Reg(
RegisterId::EAX,
RegisterId::EBX,
)],
false,
"failed to correctly parse instruction.",
),
];

ParserTests::new(&tests).run_all();
}
Expand Down Expand Up @@ -1474,27 +1511,13 @@ mod tests_asm_parsing {
true,
"succeeded in parsing instruction with invalid arguments.",
),
// This is invalid because there must be something after the section marker.
ParserTest::new(
"section",
&[],
true,
"succeeded in parsing invalid section marker.",
),
// This is invalid because the section marker isn't valid.
ParserTest::new(
"section abc",
&[],
true,
"succeeded in parsing invalid section marker.",
),
// This is invalid because there should be a second function argument on the next line,
// which is made inline by the \ symbol.
ParserTest::new(
"mov eax,\\\n",
&[],
true,
"succeeded in parsing invalid section marker.",
"succeeded in parsing of continuation operator with nothing following it.",
),
];

Expand Down

0 comments on commit 47fb6dc

Please sign in to comment.