|
17 | 17 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | 19 | // TODO: use functions instead of "fake" struct once we handle function API generation |
| 20 | + |
| 21 | +const Runner = testing.Runner(void, void, .{Primitives}); |
| 22 | +const Env = Runner.Env; |
| 23 | + |
20 | 24 | const Primitives = struct { |
21 | 25 | pub fn constructor() Primitives { |
22 | 26 | return .{}; |
@@ -114,6 +118,46 @@ const Primitives = struct { |
114 | 118 | } |
115 | 119 | } |
116 | 120 |
|
| 121 | + pub fn _returnUint8(_: *const Primitives) Env.TypedArray(u8) { |
| 122 | + return .{ .values = &.{ 10, 20, 250 } }; |
| 123 | + } |
| 124 | + |
| 125 | + pub fn _returnInt8(_: *const Primitives) Env.TypedArray(i8) { |
| 126 | + return .{ .values = &.{ 10, -20, -120 } }; |
| 127 | + } |
| 128 | + |
| 129 | + pub fn _returnUint16(_: *const Primitives) Env.TypedArray(u16) { |
| 130 | + return .{ .values = &.{ 10, 200, 2050 } }; |
| 131 | + } |
| 132 | + |
| 133 | + pub fn _returnInt16(_: *const Primitives) Env.TypedArray(i16) { |
| 134 | + return .{ .values = &.{ 10, -420, 0 } }; |
| 135 | + } |
| 136 | + |
| 137 | + pub fn _returnUint32(_: *const Primitives) Env.TypedArray(u32) { |
| 138 | + return .{ .values = &.{ 10, 2444343, 43432432 } }; |
| 139 | + } |
| 140 | + |
| 141 | + pub fn _returnInt32(_: *const Primitives) Env.TypedArray(i32) { |
| 142 | + return .{ .values = &.{ 10, -20, -495929123 } }; |
| 143 | + } |
| 144 | + |
| 145 | + pub fn _returnUint64(_: *const Primitives) Env.TypedArray(u64) { |
| 146 | + return .{ .values = &.{ 10, 495812375924, 0 } }; |
| 147 | + } |
| 148 | + |
| 149 | + pub fn _returnInt64(_: *const Primitives) Env.TypedArray(i64) { |
| 150 | + return .{ .values = &.{ 10, -49283838122, -2 } }; |
| 151 | + } |
| 152 | + |
| 153 | + pub fn _returnFloat32(_: *const Primitives) Env.TypedArray(f32) { |
| 154 | + return .{ .values = &.{ 1.1, -200.035, 0.0003 } }; |
| 155 | + } |
| 156 | + |
| 157 | + pub fn _returnFloat64(_: *const Primitives) Env.TypedArray(f64) { |
| 158 | + return .{ .values = &.{ 8881.22284, -4928.3838122, -0.00004 } }; |
| 159 | + } |
| 160 | + |
117 | 161 | pub fn _int16(_: *const Primitives, arr: []i16) void { |
118 | 162 | for (arr) |*a| { |
119 | 163 | a.* -= @intCast(arr.len); |
@@ -153,7 +197,7 @@ const Primitives = struct { |
153 | 197 |
|
154 | 198 | const testing = @import("testing.zig"); |
155 | 199 | test "JS: primitive types" { |
156 | | - var runner = try testing.Runner(void, void, .{Primitives}).init({}, {}); |
| 200 | + var runner = try Runner.init({}, {}); |
157 | 201 | defer runner.deinit(); |
158 | 202 |
|
159 | 203 | // constructor |
@@ -280,5 +324,16 @@ test "JS: primitive types" { |
280 | 324 | .{ "try { p.int64(arr_u64) } catch(e) { e instanceof TypeError; }", "true" }, |
281 | 325 | .{ "try { p.intu64(arr_i64) } catch(e) { e instanceof TypeError; }", "true" }, |
282 | 326 | .{ "try { p.intu64(arr_u32) } catch(e) { e instanceof TypeError; }", "true" }, |
| 327 | + |
| 328 | + .{ "p.returnUint8()", "10,20,250" }, |
| 329 | + .{ "p.returnInt8()", "10,-20,-120" }, |
| 330 | + .{ "p.returnUint16()", "10,200,2050" }, |
| 331 | + .{ "p.returnInt16()", "10,-420,0" }, |
| 332 | + .{ "p.returnUint32()", "10,2444343,43432432" }, |
| 333 | + .{ "p.returnInt32()", "10,-20,-495929123" }, |
| 334 | + .{ "p.returnUint64()", "10,495812375924,0" }, |
| 335 | + .{ "p.returnInt64()", "10,-49283838122,-2" }, |
| 336 | + .{ "p.returnFloat32()", "1.100000023841858,-200.03500366210938,0.0003000000142492354" }, |
| 337 | + .{ "p.returnFloat64()", "8881.22284,-4928.3838122,-0.00004" }, |
283 | 338 | }, .{}); |
284 | 339 | } |
0 commit comments