File: all.rs

package info (click to toggle)
rust-wasmprinter 0.239.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 348 kB
  • sloc: makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#[test]
fn no_oom() {
    // Whatever is printed here, it shouldn't take more than 500MB to print
    // since it's only 20k functions.
    let mut s = String::new();
    s.push_str("(module\n");
    for _ in 0..20_000 {
        s.push_str("(func i32.const 0 if i32.const 0 else i32.const 0 end)\n");
    }
    s.push(')');
    let bytes = wat::parse_str(&s).unwrap();
    let wat = wasmprinter::print_bytes(&bytes).unwrap();
    assert!(wat.len() < 500_000_000);
}

#[test]
fn offsets_and_lines_smoke_test() {
    const MODULE: &str = r#"
        (;@0     ;) (module
        (;@b     ;)   (type (;0;) (func (param i32) (result i32)))
        (;@1f    ;)   (func (;0;) (type 0) (param i32) (result i32)
        (;@20    ;)     local.get 0
                      )
        (;@17    ;)   (export "f" (func 0))
                    )
    "#;
    let bytes = wat::parse_str(MODULE).unwrap();

    let mut storage = String::new();
    let actual: Vec<_> = wasmprinter::Config::new()
        .offsets_and_lines(&bytes, &mut storage)
        .unwrap()
        .collect();

    #[rustfmt::skip]
    let expected = vec![
        (Some(0),    "(module\n"),
        (Some(0xb),  "  (type (;0;) (func (param i32) (result i32)))\n"),
        (Some(0x17), "  (export \"f\" (func 0))\n"),
        (Some(0x1f), "  (func (;0;) (type 0) (param i32) (result i32)\n"),
        (Some(0x20), "    local.get 0\n"),
        (None,       "  )\n"),
        (None,       ")\n"),
        (Some(0x23), ""),
    ];

    assert_eq!(actual, expected);
}