How to use wasmer - 10 common examples

To help you get started, we’ve selected a few wasmer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / python-ext-wasm / tests / test_instance.py View on Github external
def test_memory_view():
    assert isinstance(Instance(TEST_BYTES).memory.uint8_view(), Uint8Array)
github wasmerio / python-ext-wasm / tests / instance.py View on Github external
def test_is_a_class(self):
        self.assertTrue(inspect.isclass(Instance))
github wasmerio / python-ext-wasm / tests / memory_view.py View on Github external
def test_bytes_per_element(self):
        self.assertEqual(Instance(TEST_BYTES).uint8_memory_view().bytes_per_element, 1)
        self.assertEqual(Instance(TEST_BYTES).int8_memory_view().bytes_per_element, 1)
        self.assertEqual(Instance(TEST_BYTES).uint16_memory_view().bytes_per_element, 2)
        self.assertEqual(Instance(TEST_BYTES).int16_memory_view().bytes_per_element, 2)
        self.assertEqual(Instance(TEST_BYTES).uint32_memory_view().bytes_per_element, 4)
        self.assertEqual(Instance(TEST_BYTES).int32_memory_view().bytes_per_element, 4)
github wasmerio / python-ext-wasm / tests / instance.py View on Github external
def test_call_i32_i64_f32_f64_f64(self):
        self.assertEqual(
            round(Instance(TEST_BYTES).exports['i32_i64_f32_f64_f64'](1, 2, 3.4, 5.6), 6),
            1 + 2 + 3.4 + 5.6
        )
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_set_bytearray():
    memory = Instance(TEST_BYTES).memory.uint8_view()

    memory[7:12] = bytearray(b'abcde')
    assert memory[7:12] == [97, 98, 99, 100, 101]
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_set_single_value():
    memory = Instance(TEST_BYTES).memory.uint8_view()

    assert memory[7] == 0
    memory[7] = 42
    assert memory[7] == 42
github wasmerio / python-ext-wasm / tests / memory_view.py View on Github external
def test_hello_world(self):
        instance = Instance(TEST_BYTES)
        pointer = instance.exports['string']()
        memory = instance.uint8_memory_view(pointer)
        nth = 0
        string = ''

        while (0 != memory[nth]):
            string += chr(memory[nth])
            nth += 1

        self.assertEqual(string, 'Hello, World!')
github wasmerio / python-ext-wasm / tests / test_memory.py View on Github external
def test_hello_world():
    instance = Instance(TEST_BYTES)
    pointer = instance.exports.string()
    memory = instance.memory.uint8_view(pointer)
    nth = 0
    string = ''

    while (0 != memory[nth]):
        string += chr(memory[nth])
        nth += 1

    assert string, 'Hello, World!'
github wasmerio / python-ext-wasm / tests / test_module.py View on Github external
def test_deserialize():
    serialized_module = Module(TEST_BYTES).serialize()
    module = Module.deserialize(serialized_module)
    del serialized_module

    assert module.instantiate().exports.sum(1, 2) == 3
github wasmerio / python-ext-wasm / tests / test_module.py View on Github external
def test_compile():
    assert isinstance(Module(TEST_BYTES), Module)