Skip to content

Commit b6fe85a

Browse files
Add direct disassembly and data formatting tests to enum_tests
This adds new unit and integration tests to verify that: - Applied enums format correctly in active code disassembly (LDA #Colors.BLACK). - Data bytes (.byte) format and print enums namespace and variants correctly. - Little-endian data words (.word) format and print enums namespace and variants. TAG=agy CONV=168d6e0d-4484-483b-b051-42b81fefbdaf
1 parent 020798a commit b6fe85a

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

tests/enum_tests.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,82 @@ fn test_assembler_enum_formatting() {
277277
let acme_block = acme.format_enum_definition(&enum_def);
278278
assert_eq!(acme_block, "Colors_BLACK = $00\nColors_WHITE = $01");
279279
}
280+
281+
#[test]
282+
fn test_disassembly_enum_operand_formatting() {
283+
use regenerator2000_core::state::{Assembler, BlockType};
284+
285+
let mut app_state = AppState::new();
286+
app_state.origin = Addr(0x1000);
287+
app_state.raw_data = vec![0xA9, 0x00]; // LDA #$00
288+
app_state.block_types = vec![BlockType::Code; 2];
289+
290+
// Create enum def in AppState
291+
let mut variants = BTreeMap::new();
292+
variants.insert(0, "BLACK".to_string());
293+
let enum_def = EnumDefinition {
294+
name: "Colors".to_string(),
295+
variants,
296+
};
297+
app_state.enums.insert("Colors".to_string(), enum_def);
298+
299+
// Apply enum to address $1000
300+
app_state
301+
.enum_usages
302+
.insert(Addr(0x1000), "Colors".to_string());
303+
304+
// --- 1. 64tass ---
305+
app_state.settings.assembler = Assembler::Tass64;
306+
app_state.disassemble();
307+
assert_eq!(app_state.disassembly[0].mnemonic, "lda");
308+
assert_eq!(app_state.disassembly[0].operand, "#Colors.BLACK");
309+
310+
// --- 2. ca65 ---
311+
app_state.settings.assembler = Assembler::Ca65;
312+
app_state.disassemble();
313+
assert_eq!(app_state.disassembly[0].mnemonic, "lda");
314+
assert_eq!(app_state.disassembly[0].operand, "#Colors::BLACK");
315+
}
316+
317+
#[test]
318+
fn test_disassembly_data_enum_formatting() {
319+
use regenerator2000_core::state::{Assembler, BlockType};
320+
321+
let mut app_state = AppState::new();
322+
app_state.origin = Addr(0x1000);
323+
app_state.raw_data = vec![0x00, 0x00, 0x01]; // .byte $00, $00 (word low), $01 (word high)
324+
app_state.block_types = vec![
325+
BlockType::DataByte,
326+
BlockType::DataWord,
327+
BlockType::DataWord,
328+
];
329+
330+
let mut variants = BTreeMap::new();
331+
variants.insert(0, "BLACK".to_string());
332+
variants.insert(256, "WHITE_WORD".to_string()); // $0100 = 256
333+
let enum_def = EnumDefinition {
334+
name: "Colors".to_string(),
335+
variants,
336+
};
337+
app_state.enums.insert("Colors".to_string(), enum_def);
338+
339+
// Apply enum to data byte at $1000 and word at $1001
340+
app_state
341+
.enum_usages
342+
.insert(Addr(0x1000), "Colors".to_string());
343+
app_state
344+
.enum_usages
345+
.insert(Addr(0x1001), "Colors".to_string());
346+
347+
// --- Test ca65 ---
348+
app_state.settings.assembler = Assembler::Ca65;
349+
app_state.disassemble();
350+
351+
// ca65 byte
352+
assert_eq!(app_state.disassembly[0].mnemonic, ".byte");
353+
assert_eq!(app_state.disassembly[0].operand, "Colors::BLACK");
354+
355+
// ca65 word
356+
assert_eq!(app_state.disassembly[1].mnemonic, ".word");
357+
assert_eq!(app_state.disassembly[1].operand, "Colors::WHITE_WORD");
358+
}

0 commit comments

Comments
 (0)