@@ -126,3 +126,67 @@ fn value_of() {
126
126
"# )
127
127
. test ( )
128
128
}
129
+
130
+ #[ test]
131
+ fn to_fixed ( ) {
132
+ project ( )
133
+ . file ( "src/lib.rs" , r#"
134
+ #![feature(proc_macro, wasm_custom_section)]
135
+
136
+ extern crate wasm_bindgen;
137
+ use wasm_bindgen::prelude::*;
138
+ use wasm_bindgen::js;
139
+
140
+ #[wasm_bindgen]
141
+ pub fn to_fixed(this: &js::Number, digits: u8) -> js::JsString {
142
+ let result = this.to_fixed(digits);
143
+ let result = match result {
144
+ Ok(num) => num,
145
+ Err(_err) => "RangeError".into()
146
+ };
147
+ result
148
+ }
149
+ "# )
150
+ . file ( "test.ts" , r#"
151
+ import * as assert from "assert";
152
+ import * as wasm from "./out";
153
+
154
+ export function test() {
155
+ assert.equal(wasm.to_fixed(123.456, 2), "123.46");
156
+ assert.equal(wasm.to_fixed(10, 101), "RangeError");
157
+ }
158
+ "# )
159
+ . test ( )
160
+ }
161
+
162
+ #[ test]
163
+ fn to_exponential ( ) {
164
+ project ( )
165
+ . file ( "src/lib.rs" , r#"
166
+ #![feature(proc_macro, wasm_custom_section)]
167
+
168
+ extern crate wasm_bindgen;
169
+ use wasm_bindgen::prelude::*;
170
+ use wasm_bindgen::js;
171
+
172
+ #[wasm_bindgen]
173
+ pub fn to_exponential(this: &js::Number, fraction_digits: u8) -> js::JsString {
174
+ let result = this.to_exponential(fraction_digits);
175
+ let result = match result {
176
+ Ok(num) => num,
177
+ Err(_err) => "RangeError".into()
178
+ };
179
+ result
180
+ }
181
+ "# )
182
+ . file ( "test.ts" , r#"
183
+ import * as assert from "assert";
184
+ import * as wasm from "./out";
185
+
186
+ export function test() {
187
+ assert.equal(wasm.to_exponential(123456, 2), "1.23e+5");
188
+ assert.equal(wasm.to_exponential(10, 101), "RangeError");
189
+ }
190
+ "# )
191
+ . test ( )
192
+ }
0 commit comments