Skip to content

Commit

Permalink
Merge pull request #99 from Chia-Network/20240702-fix-bin-zero
Browse files Browse the repository at this point in the history
20240702 fix bin zero
  • Loading branch information
prozacchiwawa committed Jul 8, 2024
2 parents 39a0417 + 34663fa commit 17618c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Binary file added resources/tests/lz.bin
Binary file not shown.
8 changes: 7 additions & 1 deletion src/compiler/preprocessor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ impl Preprocessor {
.opts
.read_new_file(self.opts.filename(), fname.to_string())?;
let content = match kind {
IncludeProcessType::Bin => Rc::new(SExp::Atom(loc.clone(), content)),
IncludeProcessType::Bin => {
if self.opts.dialect().int_fix {
Rc::new(SExp::QuotedString(loc.clone(), b'x', content))
} else {
Rc::new(SExp::Atom(loc.clone(), content))
}
}
IncludeProcessType::Hex => hex_to_modern_sexp(
&mut allocator,
&HashMap::new(),
Expand Down
23 changes: 23 additions & 0 deletions src/tests/classic/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2428,3 +2428,26 @@ fn test_assign_cse_tricky_2() {
let wanted_repr = "(2 (1 2 10 (4 2 (4 5 ()))) (4 (1 ((11 5 11) 2 8 (4 2 (4 5 (4 11 ())))) (2 22 (4 2 (4 3 (4 (18 5 (1 . 11)) (4 (16 5 (1 . 1)) ()))))) (2 30 (4 2 (4 3 (4 (1 . 121) ())))) 2 (3 (9 17 (1 . 13)) (1 2 12 (4 2 (4 45 (4 21 ())))) (1 2 (3 (9 17 (1 . 15)) (1 2 8 (4 2 (4 45 (4 21 ())))) (1 . 11)) 1)) 1) 1))";
assert_eq!(program, wanted_repr);
}

#[test]
fn test_include_zero_bin() {
let program = do_basic_run(&vec![
"run".to_string(),
"-i".to_string(),
"resources/tests".to_string(),
"(mod (X) (include *standard-cl-23.1*) (embed-file lz bin lz.bin) (concat 1 lz))"
.to_string(),
]);
assert_eq!(program, "(2 (1 14 (1 . 1) 2) (4 (1 . 0x0001) 1))");
}

#[test]
fn test_include_zero_bin_pre_fix() {
let program = do_basic_run(&vec![
"run".to_string(),
"-i".to_string(),
"resources/tests".to_string(),
"(mod (X) (include *standard-cl-23*) (embed-file lz bin lz.bin) (concat 1 lz))".to_string(),
]);
assert_eq!(program, "(2 (1 14 (1 . 1) 2) (4 (1 . 1) 1))");
}

0 comments on commit 17618c8

Please sign in to comment.