From 47fb6dc218193aaf3a06e0a19225f4bad554caec Mon Sep 17 00:00:00 2001 From: Ryan Jones-Ward Date: Wed, 5 Feb 2025 12:25:09 +0000 Subject: [PATCH] Move some of the tests around and add some tests for the case insensitve section parsing. --- redox-core/src/parsing/asm_parser.rs | 69 ++++++++++++++++++---------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/redox-core/src/parsing/asm_parser.rs b/redox-core/src/parsing/asm_parser.rs index 784a119..e07c4e7 100644 --- a/redox-core/src/parsing/asm_parser.rs +++ b/redox-core/src/parsing/asm_parser.rs @@ -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(); } @@ -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.", ), ];