Skip to content

Commit

Permalink
feat: improve scaffold (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd authored Jan 13, 2024
1 parent fee9352 commit 7f16f23
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/commands/new_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ wasm-bindgen = "=${versions.wasmBindgen}"
"./rs_lib/src/lib.rs",
`use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Greeter {
name: String,
}
#[wasm_bindgen]
impl Greeter {
#[wasm_bindgen(constructor)]
pub fn new(name: String) -> Self {
Self { name }
}
pub fn greet(&self) -> String {
format!("hello {}!", self.name)
}
}
#[wasm_bindgen]
pub fn add(a: i32, b: i32) -> i32 {
return a + b;
Expand All @@ -87,6 +104,8 @@ mod tests {
#[test]
fn it_works() {
let greeter = Greeter::new("world".into());
assert_eq!(greeter.greet(), "hello world!");
let result = add(1, 2);
assert_eq!(result, 3);
}
Expand All @@ -98,8 +117,11 @@ mod tests {
"./mod.ts",
`import { instantiate } from "./lib/rs_lib.generated.js";
const { add } = await instantiate();
const { Greeter, add } = await instantiate();
console.log(add(1, 1));
const greeter = new Greeter("world");
console.log(greeter.greet());
`,
);
}
Expand Down

0 comments on commit 7f16f23

Please sign in to comment.