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