Skip to content

Commit 840f1cb

Browse files
committed
[assembler] Add test for inconsistent tags inside a macro body.
1 parent 0709115 commit 840f1cb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

assembler/src/asmlib/driver/tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,3 +937,37 @@ fn test_minus_hash_config_evaluation() {
937937

938938
assert_eq!(&program_a, &program_b);
939939
}
940+
941+
#[test]
942+
fn test_diagnose_duplicate_tags_in_macro_body() {
943+
let input = concat!(
944+
"☛☛DEF MYMACRO≡\n",
945+
// First tag assignment
946+
" T-> 2\n",
947+
// Second tag assignment (which is not allowed for the
948+
// same tag name, even inside a macro body).
949+
" T-> 3\n",
950+
"☛☛EMD",
951+
"\n",
952+
// Expand the macro just once.
953+
"MYMACRO≡\n",
954+
);
955+
let mut errors = Default::default();
956+
let expected_msg = "T is defined more than once";
957+
match dbg!(assemble_pass1(input, &mut errors)) {
958+
Ok((_source_file, _options)) => {
959+
dbg!(&errors);
960+
assert!(!errors.is_empty());
961+
assert!(errors.iter().any(|e| e.to_string().contains(expected_msg)));
962+
}
963+
Err(e) => {
964+
dbg!(&errors);
965+
dbg!(&e);
966+
// Although the current implementation successfully parses
967+
// the program but returns an error in `errors`, we also
968+
// accept a hypothetical implementation in which
969+
// assemble_pass1() returns Err.
970+
assert!(e.to_string().contains(expected_msg));
971+
}
972+
}
973+
}

0 commit comments

Comments
 (0)