Debian Codegraph @

crates/wasmprinter/tests/all.rs

raw
1 #[test]
2 fn no_oom() {
3 // Whatever is printed here, it shouldn't take more than 500MB to print
4 // since it's only 20k functions.
5 let mut s = String::new();
6 s.push_str("(module\n");
7 for _ in 0..20_000 {
8 s.push_str("(func i32.const 0 if i32.const 0 else i32.const 0 end)\n");
9 }
10 s.push(')');
11 let bytes = wat::parse_str(&s).unwrap();
12 let wat = wasmprinter::print_bytes(&bytes).unwrap();
13 assert!(wat.len() < 500_000_000);
14 }
15
16 #[test]
17 fn offsets_and_lines_smoke_test() {
18 const MODULE: &str = r#"
19 (;@0 ;) (module
20 (;@b ;) (type (;0;) (func (param i32) (result i32)))
21 (;@1f ;) (func (;0;) (type 0) (param i32) (result i32)
22 (;@20 ;) local.get 0
23 )
24 (;@17 ;) (export "f" (func 0))
25 )
26 "#;
27 let bytes = wat::parse_str(MODULE).unwrap();
28
29 let mut storage = String::new();
30 let actual: Vec<_> = wasmprinter::Config::new()
31 .offsets_and_lines(&bytes, &mut storage)
32 .unwrap()
33 .collect();
34
35 #[rustfmt::skip]
36 let expected = vec![
37 (Some(0), "(module\n"),
38 (Some(0xb), " (type (;0;) (func (param i32) (result i32)))\n"),
39 (Some(0x17), " (export \"f\" (func 0))\n"),
40 (Some(0x1f), " (func (;0;) (type 0) (param i32) (result i32)\n"),
41 (Some(0x20), " local.get 0\n"),
42 (None, " )\n"),
43 (None, ")\n"),
44 (Some(0x23), ""),
45 ];
46
47 assert_eq!(actual, expected);
48 }