Skip to content

Commit

Permalink
Refactor tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sciguyryan committed Feb 9, 2025
1 parent d27d760 commit a6c087d
Showing 1 changed file with 70 additions and 34 deletions.
104 changes: 70 additions & 34 deletions redox-core/src/parsing/asm_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,26 +1242,89 @@ mod tests_asm_parsing {
}

#[test]
fn section_parser_tests() {
fn test_escape_sequences() {
// I don't know -why- you would write these like this... but you can!
let tests = [
// The text section is a valid section.
// The text section is a valid section, but the escape sequences are escaped.
ParserTest::new(
"section .text",
"section \\u002E\\u0074\\u0065\\u0078\\u0074",
&[],
false,
"failed to parse valid section.",
),
// The section label should be automatically converted to lowercase, which renders it correct.
// The text section is a valid section.
ParserTest::new(
"section .TEXT",
"section \u{002E}\u{0074}\u{0065}\u{0078}\u{0074}",
&[],
false,
"failed to parse valid section.",
),
// This is equitant to the unescaped string.
ParserTest::new(
"\\u006E\\u006F\\u0070",
&[Instruction::Nop],
false,
"failed to escaped NOP instruction.",
),
// This is equitant to the unescaped string.
ParserTest::new(
"\u{006E}\u{006F}\u{0070}",
&[Instruction::Nop],
false,
"failed to escaped NOP instruction.",
),

// This is equitant to the unescaped string.
ParserTest::new(
"nop\n:\\u004C\\u0041\\u0042\\u0045\\u004C\\u005F\\u0031",
&[
Instruction::Nop,
Instruction::Label(String::from(":LABEL_1")),
],
false,
"failed to parse label instruction.",
),
ParserTest::new(
"nop\n:\u{004C}\u{0041}\u{0042}\u{0045}\u{004C}\u{005F}\u{0031}",
&[
Instruction::Nop,
Instruction::Label(String::from(":LABEL_1")),
],
false,
"failed to parse label instruction.",
),
// This is equitant to the unescaped string.
ParserTest::new(
"nop\n:\\u00f0\\u009f\\u008f\\u00b4\\u00f3\\u00a0\\u0081\\u00a7\\u00f3\\u00a0\\u0081\\u00a2\\u00f3\\u00a0\\u0081\\u00b7\\u00f3\\u00a0\\u0081\\u00ac\\u00f3\\u00a0\\u0081\\u00b3\\u00f3\\u00a0\\u0081\\u00bf",
&[Instruction::Nop, Instruction::Label(String::from(":🏴󠁧󠁢󠁷󠁬󠁳󠁿"))],
false,
"failed to correctly parse label instruction.",
),
// This is equitant to the unescaped string.
ParserTest::new(
"nop\n:\u{00f0}\u{009f}\u{008f}\u{00b4}\u{00f3}\u{00a0}\u{0081}\u{00a7}\u{00f3}\u{00a0}\u{0081}\u{00a2}\u{00f3}\u{00a0}\u{0081}\u{00b7}\u{00f3}\u{00a0}\u{0081}\u{00ac}\u{00f3}\u{00a0}\u{0081}\u{00b3}\u{00f3}\u{00a0}\u{0081}\u{00bf}",
&[Instruction::Nop, Instruction::Label(String::from(":🏴󠁧󠁢󠁷󠁬󠁳󠁿"))],
false,
"failed to correctly parse label instruction.",
),
];

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

#[test]
fn section_parser_tests() {
let tests = [
// The text section is a valid section.
// I don't know -why- you would write it like this... but you can.
ParserTest::new(
"section \\u002E\\u0074\\u0065\\u0078\\u0074",
"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.",
Expand Down Expand Up @@ -1298,14 +1361,6 @@ mod tests_asm_parsing {
false,
"failed to correctly parse instruction.",
),
// I don't know -why- you would write it like this... but you can.
// This is equitant to the unescaped string.
ParserTest::new(
"\\u006E\\u006F\\u0070",
&[Instruction::Nop],
false,
"failed to escaped NOP instruction.",
),
];

ParserTests::new(&tests).run_all();
Expand All @@ -1323,31 +1378,12 @@ mod tests_asm_parsing {
false,
"failed to correctly parse label instruction.",
),
// I don't know -why- you would write it like this... but you can.
// This is equitant to the unescaped string.
ParserTest::new(
"nop\n:\\u004C\\u0041\\u0042\\u0045\\u004C\\u005F\\u0031",
&[
Instruction::Nop,
Instruction::Label(String::from(":LABEL_1")),
],
false,
"failed to parse label instruction.",
),
ParserTest::new(
"nop\n:🏴󠁧󠁢󠁷󠁬󠁳󠁿",
&[Instruction::Nop, Instruction::Label(String::from(":🏴󠁧󠁢󠁷󠁬󠁳󠁿"))],
false,
"failed to correctly parse label instruction.",
),
// I don't know -why- you would write it like this... but you can.
// This is equitant to the unescaped string.
ParserTest::new(
"nop\n:\\u00f0\\u009f\\u008f\\u00b4\\u00f3\\u00a0\\u0081\\u00a7\\u00f3\\u00a0\\u0081\\u00a2\\u00f3\\u00a0\\u0081\\u00b7\\u00f3\\u00a0\\u0081\\u00ac\\u00f3\\u00a0\\u0081\\u00b3\\u00f3\\u00a0\\u0081\\u00bf",
&[Instruction::Nop, Instruction::Label(String::from(":🏴󠁧󠁢󠁷󠁬󠁳󠁿"))],
false,
"failed to correctly parse label instruction.",
),
ParserTest::new(
"call :LABEL_1\n:LABEL_1",
&[
Expand Down

0 comments on commit a6c087d

Please sign in to comment.