Support String.prototype.charCodeAt

This commit is contained in:
Satoshi Amemiya
2018-06-26 21:25:44 +09:00
parent 947dfbeae0
commit 22fdcf02b2
2 changed files with 39 additions and 0 deletions

View File

@ -31,6 +31,35 @@ fn char_at() {
.test()
}
#[test]
fn char_code_at() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn string_char_code_at(this: &js::JsString, index: u32) -> js::Number {
this.char_code_at(index)
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
var anyString = 'Brave new world';
export function test() {
assert.equal(wasm.string_char_code_at(anyString, 0), 66);
assert.ok(isNaN(wasm.string_char_code_at(anyString, 999)));
}
"#)
.test()
}
#[test]
fn starts_with() {
project()