Skip to content

Commit 9977c4d

Browse files
Refactor tests a bit and include canonical example
1 parent 9c62dcc commit 9977c4d

File tree

7 files changed

+113
-62
lines changed

7 files changed

+113
-62
lines changed

tests/data/dwarf.red

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;redcode
2+
3+
;name Dwarf
4+
;author A. K. Dewdney
5+
;version 94.1
6+
;date April 29, 1993
7+
8+
;strategy Bombs every fourth instruction.
9+
;assert CORESIZE % 4 == 0
10+
11+
ORG start ; Indicates the instruction with
12+
; the label "start" should be the
13+
; first to execute.
14+
15+
step EQU 4 ; Replaces all occurrences of "step"
16+
; with the character "4".
17+
18+
target DAT.F #0, #0 ; Pointer to target instruction.
19+
start ADD.AB #step, target ; Increments pointer by step.
20+
MOV.AB #0, @target ; Bombs target instruction.
21+
JMP.A start ; Same as JMP.A -2. Loops back to
22+
; the instruction labelled "start".
23+
END

tests/data/dwarf_loadfile.red

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;redcode
2+
;name Dwarf
3+
;author A. K. Dewdney
4+
;version 94.1
5+
;date April 29, 1993
6+
;strategy Bombs every fourth instruction.
7+
;assert CORESIZE % 4 == 0
8+
ORG $1
9+
DAT.F #0, #0
10+
ADD.AB #4, $-1
11+
MOV.AB #0, @-2
12+
JMP.A $-2, #0

tests/data/test.red

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
preload
2+
mov 0, 1
3+
dat 1 , 2
4+
mov 1, 0
5+
6+
jmp 123
7+
8+
begin: add # 1, @ 2
9+
sub 3, 4
10+
mul 5, 6
11+
div 7, 8
12+
mod 9, 10
13+
jmz 0
14+
jmn 0
15+
djn 0
16+
cmp 0
17+
seq 0
18+
sne 0
19+
slt 0
20+
spl 0
21+
nop 0
22+
23+
loop
24+
; TODO rewrite grammar to handle org, equ, end
25+
; org 0
26+
; equ 0
27+
; end 0
28+
29+
mov.a 1, 2
30+
mov.b 1, 2
31+
mov.ab 1, 2
32+
mov.ba 1, 2
33+
mov.f 1, 2
34+
mov.x 1, 2
35+
mov.i 1, 2
36+
37+
jmp loop

tests/data/test_file.red

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
MOV.I $0, $1
1+
MOV.I #0, $1
22
DAT.F $1, $2
3-
MOV.I $1, $0
4-
JMP.B $123, $0
3+
MOV.I $1, #0
4+
JMP.B $123, #0
55
ADD.AB #1, @2
66
SUB.F $3, $4
77
MUL.F $5, $6
88
DIV.F $7, $8
99
MOD.F $9, $10
10-
JMZ.B $0, $0
11-
JMN.B $0, $0
12-
DJN.B $0, $0
13-
CMP.I $0, $0
14-
SEQ.I $0, $0
15-
SNE.I $0, $0
16-
SLT.B $0, $0
17-
SPL.B $0, $0
18-
NOP.B $0, $0
10+
JMZ.B #0, #0
11+
JMN.B #0, #0
12+
DJN.B #0, #0
13+
CMP.I #0, #0
14+
SEQ.I #0, #0
15+
SNE.I #0, #0
16+
SLT.B #0, #0
17+
SPL.B #0, #0
18+
NOP.B #0, #0
1919
MOV.A $1, $2
2020
MOV.B $1, $2
2121
MOV.AB $1, $2
2222
MOV.BA $1, $2
2323
MOV.F $1, $2
2424
MOV.X $1, $2
2525
MOV.I $1, $2
26+
JMP.B $-22, #0

tests/dump.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
extern crate corewa_rs;
2+
3+
fn run_test(input: &str, expected_output: &str) {
4+
eprintln!("Parsing warrior:\n{}", input);
5+
6+
let core = corewa_rs::parse(input).expect("Failed to parse test_file.red");
7+
8+
eprintln!("Loaded core:\n{:?}", core);
9+
10+
assert_eq!(core.dump(), expected_output);
11+
}
12+
13+
#[test]
14+
fn dump_all_opcodes() {
15+
run_test(
16+
include_str!("data/test.red"),
17+
include_str!("data/test_loadfile.red"),
18+
);
19+
}
20+
21+
#[test]
22+
#[ignore] // Until we have support for keeping metadata comments, EQU, etc.
23+
fn dump_icws94_example_dwarf() {
24+
run_test(
25+
include_str!("data/dwarf.red"),
26+
include_str!("data/dwarf_loadfile.red"),
27+
);
28+
}

tests/parse_and_dump.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)