Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca007de

Browse files
committedJul 23, 2023
Add a proper test for multiple interfaces
Without inspecting the resulting WAT, and instead concluding based on the test compiling successfully and executing without any errors, everything seems to work properly.
1 parent 360fb2d commit ca007de

5 files changed

+4699
-0
lines changed
 

‎tests/compiler/multiple-interfaces.debug.wat

+2,802
Large diffs are not rendered by default.

‎tests/compiler/multiple-interfaces.js

Whitespace-only changes.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

‎tests/compiler/multiple-interfaces.release.wat

+1,833
Large diffs are not rendered by default.

‎tests/compiler/multiple-interfaces.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
interface W {
2+
w: f64
3+
}
4+
5+
interface X {
6+
x: f64
7+
}
8+
9+
interface Y {
10+
y: f64
11+
}
12+
13+
interface Z {
14+
z: f64
15+
}
16+
17+
// WX XY XZ YZ
18+
// | \__|__/
19+
// | |
20+
// | Vec3
21+
// \_____|
22+
// Vec4
23+
24+
interface WX extends W, X {}
25+
interface XY extends X, Y {}
26+
interface XZ extends X, Z {}
27+
interface YZ extends Y, Z {}
28+
29+
interface Vec3 extends XY, XZ, YZ {}
30+
31+
/**
32+
* Who needs a regular old Vec3, when you can have a Vec4?
33+
* Vec3 is overused anyway :^)
34+
*/
35+
interface Vec4 extends WX, Vec3 {}
36+
37+
class Vec4TheClass implements Vec4 {
38+
constructor(
39+
public w: f64,
40+
public x: f64,
41+
public y: f64,
42+
public z: f64
43+
) {}
44+
}
45+
46+
const vec4 = new Vec4TheClass(1, 2, 3, 4);
47+
48+
const anotherVec4: Vec4 = vec4;
49+
assert(anotherVec4.w == vec4.w);
50+
51+
const y: Y = vec4;
52+
assert(y.y == vec4.y);
53+
54+
const yz: YZ = vec4;
55+
assert(yz.z == vec4.z);
56+
57+
const vec3: Vec3 = vec4;
58+
const x: X = vec3;
59+
assert(vec3.x == x.x);
60+
61+
// Up-cast, down-cast, left-cast, right-cast
62+
const wx = vec3 as Vec4 as WX;
63+
assert(wx.w == vec4.w);

0 commit comments

Comments
 (0)
Please sign in to comment.