mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-28 20:43:23 +03:00
Merge pull request #324 from rail44/string-code_point_at
Support String.prototype.codePointAt
This commit is contained in:
commit
de88291b72
@ -583,6 +583,12 @@ extern {
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
|
||||
pub fn char_code_at(this: &JsString, index: u32) -> Number;
|
||||
|
||||
/// The codePointAt() method returns a non-negative integer that is the Unicode code point value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
|
||||
pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
|
||||
|
||||
/// The concat() method concatenates the string arguments to the calling string and returns a new string.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
|
||||
|
@ -31,6 +31,34 @@ fn char_at() {
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_point_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_code_point_at(this: &js::JsString, pos: u32) -> JsValue {
|
||||
this.code_point_at(pos)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.string_code_point_at('ABC', 1), 66);
|
||||
assert.equal(wasm.string_code_point_at('\uD800\uDC00', 0), 65536);
|
||||
assert.equal(wasm.string_code_point_at('XYZ', 42), undefined);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concat() {
|
||||
project()
|
||||
@ -62,7 +90,7 @@ fn concat() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn char_code_at() {
|
||||
project()
|
||||
|
Loading…
Reference in New Issue
Block a user