]> git.proxmox.com Git - rustc.git/blob - vendor/wasm-bindgen/tests/wasm/enums.js
New upstream version 1.76.0+dfsg1
[rustc.git] / vendor / wasm-bindgen / tests / wasm / enums.js
1 const wasm = require('wasm-bindgen-test.js');
2 const assert = require('assert');
3
4 exports.js_c_style_enum = () => {
5 assert.strictEqual(wasm.Color.Green, 0);
6 assert.strictEqual(wasm.Color.Yellow, 1);
7 assert.strictEqual(wasm.Color.Red, 2);
8 assert.strictEqual(wasm.Color[0], 'Green');
9 assert.strictEqual(wasm.Color[1], 'Yellow');
10 assert.strictEqual(wasm.Color[2], 'Red');
11 assert.strictEqual(Object.keys(wasm.Color).length, 6);
12
13 assert.strictEqual(wasm.enum_cycle(wasm.Color.Green), wasm.Color.Yellow);
14 };
15
16 exports.js_c_style_enum_with_custom_values = () => {
17 assert.strictEqual(wasm.ColorWithCustomValues.Green, 21);
18 assert.strictEqual(wasm.ColorWithCustomValues.Yellow, 34);
19 assert.strictEqual(wasm.ColorWithCustomValues.Red, 2);
20 assert.strictEqual(wasm.ColorWithCustomValues[21], 'Green');
21 assert.strictEqual(wasm.ColorWithCustomValues[34], 'Yellow');
22 assert.strictEqual(wasm.ColorWithCustomValues[2], 'Red');
23 assert.strictEqual(Object.keys(wasm.ColorWithCustomValues).length, 6);
24
25 assert.strictEqual(wasm.enum_with_custom_values_cycle(wasm.ColorWithCustomValues.Green), wasm.ColorWithCustomValues.Yellow);
26 };
27
28 exports.js_handle_optional_enums = x => wasm.handle_optional_enums(x);
29
30 exports.js_expect_enum = (a, b) => {
31 assert.strictEqual(a, b);
32 };
33
34 exports.js_expect_enum_none = a => {
35 assert.strictEqual(a, undefined);
36 };
37
38 exports.js_renamed_enum = b => {
39 assert.strictEqual(wasm.JsRenamedEnum.B, b);
40 };
41
42 exports.js_enum_with_error_variant = () => {
43 assert.strictEqual(wasm.EnumWithErrorVariant.Error, 2);
44 };