Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TS tests #1356

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions crates/typescript-tests/index.ts

This file was deleted.

11 changes: 11 additions & 0 deletions crates/typescript-tests/src/custom_section.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen(typescript_custom_section)]
const TS_INTERFACE_EXPORT: &'static str = r"
interface Height { height: number; }
";

#[wasm_bindgen]
pub struct Person {
pub height: u32,
}
3 changes: 3 additions & 0 deletions crates/typescript-tests/src/custom_section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as wbg from '../pkg/typescript_tests';

const height: wbg.Height = new wbg.Person();
24 changes: 4 additions & 20 deletions crates/typescript-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn greet(_: &str) {}

#[wasm_bindgen]
struct A {
}

#[wasm_bindgen]
impl A {
#[wasm_bindgen(constructor)]
pub fn new() -> A {
A {}
}

pub fn other() {}

pub fn foo(&self) {}
}
mod custom_section;
mod opt_args_and_ret;
mod simple_fn;
mod simple_struct;
3 changes: 3 additions & 0 deletions crates/typescript-tests/src/memory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as wasm from '../pkg/typescript_tests_bg';

const memory: WebAssembly.Memory = wasm.memory;
6 changes: 6 additions & 0 deletions crates/typescript-tests/src/opt_args_and_ret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn opt_fn(_a: Option<i32>) -> Option<i32> {
None
}
3 changes: 3 additions & 0 deletions crates/typescript-tests/src/opt_args_and_ret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as wbg from '../pkg/typescript_tests';

const opt_fn: (a: number | undefined) => number | undefined = wbg.opt_fn;
4 changes: 4 additions & 0 deletions crates/typescript-tests/src/simple_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn greet(_: &str) {}
5 changes: 5 additions & 0 deletions crates/typescript-tests/src/simple_fn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as wbg from '../pkg/typescript_tests';
import * as wasm from '../pkg/typescript_tests_bg';

const wbg_greet: (a: string) => void = wbg.greet;
const wasm_greet: (a: number, b: number) => void = wasm.greet;
17 changes: 17 additions & 0 deletions crates/typescript-tests/src/simple_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct A {
}

#[wasm_bindgen]
impl A {
#[wasm_bindgen(constructor)]
pub fn new() -> A {
A {}
}

pub fn other() {}

pub fn foo(&self) {}
}
6 changes: 6 additions & 0 deletions crates/typescript-tests/src/simple_struct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as wbg from '../pkg/typescript_tests';

const a = new wbg.A();
wbg.A.other();
a.foo();
a.free();
2 changes: 1 addition & 1 deletion crates/typescript-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"baseUrl": "."
},
"include": [
"index.ts"
"src/*.ts"
]
}