# All files / src/utils test-utils.js

100% Statements 15/15
100% Branches 0/0
100% Functions 3/3
100% Lines 14/14

    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
    262x
    2x

    2x
    2x
    2x

    2x

    13x

    13x
    13x
    13x
    485x
    485x

    13x

    2x

     import compile from "..";
    import { stringDecoder } from "../utils/string";

    export const harness = source => t => {
      const memory = new WebAssembly.Memory({ initial: 1 });
      const view = new DataView(memory.buffer);

      return WebAssembly.instantiate(compile(source, { encodeNames: true }), {
        env: {
          memory,
          assert(strPointer, value, expected) {
            let text = "";

            const decoder = stringDecoder(view, strPointer);
            let iterator = decoder.next();
            while (!iterator.done) {
              text += String.fromCodePoint(iterator.value);
              iterator = decoder.next();
            }

            t.is(value, expected, text);
          },
        },
      }).then(module => module.instance.exports.run());
    };