Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenbakker-atmind committed Jan 31, 2025
1 parent 02c4808 commit fa340ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
1 change: 1 addition & 0 deletions c64-assembler/src/validator/address_names_unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn validate_instructions(visited_names: &mut Vec<String>, instructions: &Instruc
if visited_names.contains(label) {
return Err(Error::AddressNameNotUnique(label.to_string()));
}
visited_names.push(label.clone());
}
}
Ok(())
Expand Down
57 changes: 47 additions & 10 deletions c64-assembler/tests/validator_addressing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use c64_assembler::validator::{AssemblerResult, Error, Validator};
use c64_assembler::{
instruction::operation::Operation,
validator::{AssemblerResult, Error, Validator},
};
use c64_assembler_macro::application;

#[test]
Expand Down Expand Up @@ -54,21 +57,24 @@ fn address_names_unique_modules() -> AssemblerResult<()> {

#[test]
fn address_names_not_unique_one_module() -> AssemblerResult<()> {
let application = application!(module!(instruction!(
let application = application!(module!(instructions!(
not_unique_label:
not_unique_label:
)))?;

let result = application.validate();
if let Err(Error::AddressNameNotUnique(label)) = result {
assert_eq!(&label, "not_unique_label");
match result {
Err(Error::AddressNameNotUnique(label)) => assert_eq!(&label, "not_unique_label"),
_ => {
unreachable!()
}
}
Ok(())
}

#[test]
fn address_names_not_unique_one_module_function() -> AssemblerResult<()> {
let application = application!(module!(instruction!(
let application = application!(module!(instructions!(
not_unique_label:
)
function!(
Expand All @@ -77,15 +83,18 @@ fn address_names_not_unique_one_module_function() -> AssemblerResult<()> {
))))?;

let result = application.validate();
if let Err(Error::AddressNameNotUnique(label)) = result {
assert_eq!(&label, "not_unique_label");
match result {
Err(Error::AddressNameNotUnique(label)) => assert_eq!(&label, "not_unique_label"),
_ => {
unreachable!()
}
}
Ok(())
}

#[test]
fn address_names_not_unique_modules() -> AssemblerResult<()> {
let application = application!(module!(instruction!(
let application = application!(module!(instructions!(
not_unique_label:
))
module!(instructions!(
Expand All @@ -94,8 +103,36 @@ fn address_names_not_unique_modules() -> AssemblerResult<()> {
)?;

let result = application.validate();
if let Err(Error::AddressNameNotUnique(label)) = result {
assert_eq!(&label, "not_unique_label");
match result {
Err(Error::AddressNameNotUnique(label)) => assert_eq!(&label, "not_unique_label"),
_ => {
unreachable!()
}
}
Ok(())
}

/// It is a common pattern to put a label at the end of an program for scratch space.
#[test]
fn label_at_end_of_instructions() -> AssemblerResult<()> {
let application = application!(module!(instructions!(
label_a:
)))?;
assert_eq!(1, application.modules.len());
assert_eq!(1, application.modules.get(0).unwrap().instructions.instructions.len());
if let Operation::Label(label) = &application
.modules
.get(0)
.unwrap()
.instructions
.instructions
.get(0)
.unwrap()
.operation
{
assert_eq!("label_a", label);
} else {
unreachable!("no label instruction")
}
Ok(())
}

0 comments on commit fa340ad

Please sign in to comment.