| 1 |
const assert = require('assert'); |
| 2 |
const wasm = require('wasm-bindgen-test'); |
| 3 |
|
| 4 |
exports.math_log = Math.log; |
| 5 |
|
| 6 |
exports.StaticFunction = class { |
| 7 |
static bar() { return 2; } |
| 8 |
}; |
| 9 |
|
| 10 |
class Construct { |
| 11 |
static create() { |
| 12 |
const ret = new Construct(); |
| 13 |
ret.internal_string = 'this'; |
| 14 |
return ret; |
| 15 |
} |
| 16 |
|
| 17 |
get_internal_string() { |
| 18 |
return this.internal_string; |
| 19 |
} |
| 20 |
|
| 21 |
append_to_internal_string(s) { |
| 22 |
this.internal_string += s; |
| 23 |
} |
| 24 |
|
| 25 |
assert_internal_string(s) { |
| 26 |
assert.strictEqual(this.internal_string, s); |
| 27 |
} |
| 28 |
|
| 29 |
["kebab-case"]() { |
| 30 |
return 42; |
| 31 |
} |
| 32 |
|
| 33 |
get ["kebab-case-val"]() { |
| 34 |
return 42; |
| 35 |
} |
| 36 |
|
| 37 |
set ["kebab-case-val"](val) {} |
| 38 |
|
| 39 |
static ["static-kebab-case"]() { |
| 40 |
return 42; |
| 41 |
} |
| 42 |
|
| 43 |
static get ["static-kebab-case-val"]() { |
| 44 |
return 42; |
| 45 |
} |
| 46 |
|
| 47 |
static set ["static-kebab-case-val"](val) {} |
| 48 |
} |
| 49 |
|
| 50 |
Construct.internal_string = ''; |
| 51 |
exports.Construct = Construct; |
| 52 |
|
| 53 |
class NewConstructor { |
| 54 |
constructor(field) { |
| 55 |
this.field = field; |
| 56 |
} |
| 57 |
|
| 58 |
get() { |
| 59 |
return this.field + 1; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
exports.NewConstructors = NewConstructor; |
| 64 |
exports.default = NewConstructor; |
| 65 |
|
| 66 |
let switch_called = false; |
| 67 |
class SwitchMethods { |
| 68 |
constructor() { |
| 69 |
} |
| 70 |
|
| 71 |
static a() { |
| 72 |
switch_called = true; |
| 73 |
} |
| 74 |
|
| 75 |
b() { |
| 76 |
switch_called = true; |
| 77 |
} |
| 78 |
} |
| 79 |
exports.SwitchMethods = SwitchMethods; |
| 80 |
exports.switch_methods_called = function() { |
| 81 |
const tmp = switch_called; |
| 82 |
switch_called = false; |
| 83 |
return tmp; |
| 84 |
}; |
| 85 |
exports.switch_methods_a = function() { SwitchMethods.a = function() {}; }; |
| 86 |
exports.switch_methods_b = function() { SwitchMethods.prototype.b = function() {}; }; |
| 87 |
|
| 88 |
exports.Properties = class { |
| 89 |
constructor() { |
| 90 |
this.num = 1; |
| 91 |
} |
| 92 |
|
| 93 |
get a() { |
| 94 |
return this.num; |
| 95 |
} |
| 96 |
|
| 97 |
set a(val) { |
| 98 |
this.num = val; |
| 99 |
} |
| 100 |
}; |
| 101 |
|
| 102 |
exports.RenameProperties = class { |
| 103 |
constructor() { |
| 104 |
this.num = 1; |
| 105 |
} |
| 106 |
|
| 107 |
get a() { |
| 108 |
return this.num; |
| 109 |
} |
| 110 |
|
| 111 |
set a(val) { |
| 112 |
this.num = val; |
| 113 |
} |
| 114 |
}; |
| 115 |
|
| 116 |
class Options { |
| 117 |
} |
| 118 |
exports.Options = Options; |
| 119 |
|
| 120 |
exports.take_none = function(val) { |
| 121 |
assert.strictEqual(val, undefined); |
| 122 |
}; |
| 123 |
|
| 124 |
exports.take_some = function(val) { |
| 125 |
assert.strictEqual(val === undefined, false); |
| 126 |
}; |
| 127 |
|
| 128 |
exports.return_null = function() { |
| 129 |
return null; |
| 130 |
}; |
| 131 |
|
| 132 |
exports.return_undefined = function() { |
| 133 |
return undefined; |
| 134 |
}; |
| 135 |
|
| 136 |
exports.return_some = function() { |
| 137 |
return new Options(); |
| 138 |
}; |
| 139 |
|
| 140 |
exports.run_rust_option_tests = function() { |
| 141 |
wasm.rust_take_none(); |
| 142 |
wasm.rust_take_none(null) |
| 143 |
wasm.rust_take_none(undefined); |
| 144 |
wasm.rust_take_some(new Options()); |
| 145 |
assert.strictEqual(wasm.rust_return_none(), undefined); |
| 146 |
assert.strictEqual(wasm.rust_return_none(), undefined); |
| 147 |
assert.strictEqual(wasm.rust_return_some() === undefined, false); |
| 148 |
}; |
| 149 |
|
| 150 |
exports.CatchConstructors = class { |
| 151 |
constructor(x) { |
| 152 |
if (x == 0) { |
| 153 |
throw new Error('bad!'); |
| 154 |
} |
| 155 |
} |
| 156 |
}; |
| 157 |
|
| 158 |
exports.StaticStructural = class { |
| 159 |
static static_structural(x) { |
| 160 |
return x + 3; |
| 161 |
} |
| 162 |
}; |
| 163 |
|
| 164 |
class InnerClass { |
| 165 |
static inner_static_function(x) { |
| 166 |
return x + 5; |
| 167 |
} |
| 168 |
|
| 169 |
static create_inner_instance() { |
| 170 |
const ret = new InnerClass(); |
| 171 |
ret.internal_int = 3; |
| 172 |
return ret; |
| 173 |
} |
| 174 |
|
| 175 |
get_internal_int() { |
| 176 |
return this.internal_int; |
| 177 |
} |
| 178 |
|
| 179 |
append_to_internal_int(i) { |
| 180 |
this.internal_int += i; |
| 181 |
} |
| 182 |
|
| 183 |
assert_internal_int(i) { |
| 184 |
assert.strictEqual(this.internal_int, i); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
exports.nestedNamespace = { |
| 189 |
InnerClass: InnerClass |
| 190 |
} |