Skip to content

Commit

Permalink
test for infinite recursion in parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ScanMountGoat committed Mar 14, 2023
1 parent 33338e4 commit c9ae933
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/tests/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,27 @@ fn parse_recursive() {
assert_eq!(file0, file1b);
print_rec(&source_map, "root.ldr", &root_file, 0);
}

#[test]
fn parse_cycle() {
let mut memory_resolver = MemoryResolver::new();

// Infinite recursion on a naive implementation.
let ldr_contents = b"0 FILE a.ldr
1 16 0 0 0 1 0 0 0 1 0 0 0 1 b.ldr
0 FILE b.ldr
1 16 0 0 0 1 0 0 0 1 0 0 0 1 a.ldr
";

memory_resolver.add("root.ldr", ldr_contents);

let mut source_map = weldr::SourceMap::new();

weldr::parse("root.ldr", &memory_resolver, &mut source_map).unwrap();
let file_a = source_map.get("a.ldr").unwrap();
assert_eq!(2, file_a.cmds.len());

let file_b = source_map.get("b.ldr").unwrap();
assert_eq!(2, file_b.cmds.len());
}

0 comments on commit c9ae933

Please sign in to comment.