Skip to content

Commit 9c4ee61

Browse files
committed
BAEL-9118: givenAddModule_whenCallingAddWithTwoAndForty_thenResultIsFortyTwo
1 parent dbf3cab commit 9c4ee61

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

libraries-bytecode/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>asm-util</artifactId>
4141
<version>${asm.version}</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>com.dylibso.chicory</groupId>
45+
<artifactId>runtime</artifactId>
46+
<version>${chicory.version}</version>
47+
</dependency>
4348
<!--
4449
Importing the libraries as jars using system path. These are two versions of the same library, which is generated
4550
from the code inside /incompatibleclasschange/libraries/modified and /incompatibleclasschange/libraries/original
@@ -118,6 +123,7 @@
118123
<asm.version>5.2</asm.version>
119124
<teavm.version>0.10.1</teavm.version>
120125
<objenesis.version>3.4</objenesis.version>
126+
<chicory.version>1.5.3</chicory.version>
121127
</properties>
122128

123129
</project>

libraries-bytecode/src/test/java/com/baeldung/chicory/ChicoryUnitTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
package com.baeldung.chicory;
22

3-
import static org.junit.Assert.assertTrue;
4-
3+
import com.dylibso.chicory.runtime.ExportFunction;
4+
import com.dylibso.chicory.runtime.Instance;
5+
import com.dylibso.chicory.wasm.Parser;
56
import org.junit.jupiter.api.Test;
67

8+
import java.io.InputStream;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
12+
713
class ChicoryUnitTest {
814

915
@Test
10-
void whenProjectLoads_thenTestsRun() {
11-
assertTrue(true);
16+
void givenAddModule_whenCallingAddWithTwoAndForty_thenResultIsFortyTwo() {
17+
InputStream wasm = getClass().getResourceAsStream("/wasm/add.wasm");
18+
assertNotNull(wasm);
19+
20+
var module = Parser.parse(wasm);
21+
Instance instance = Instance.builder(module).build();
22+
ExportFunction add = instance.export("add");
23+
24+
long[] result = add.apply(2, 40);
25+
26+
assertEquals(42, (int) result[0]);
1227
}
1328
}
14-
53 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(module
2+
(func (export "add") (param i32 i32) (result i32)
3+
local.get 0
4+
local.get 1
5+
i32.add))

0 commit comments

Comments
 (0)