-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #201 - export Typescript function header
- Loading branch information
1 parent
48b86ae
commit 253fc44
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![allow(deprecated)] | ||
|
||
use specta::{fn_datatype, functions::FunctionDataType, specta, ts::export_function_header}; | ||
|
||
#[specta] | ||
fn a() {} | ||
#[specta] | ||
fn b() -> () {} | ||
#[specta] | ||
async fn c() {} | ||
#[specta] | ||
fn d() -> String { | ||
"todo".into() | ||
} | ||
#[specta] | ||
fn e(a: String) {} | ||
#[specta] | ||
fn f(a: String, b: i32) {} | ||
#[specta] | ||
#[deprecated] | ||
fn g() {} | ||
|
||
#[test] | ||
fn test_export_function_header() { | ||
assert(fn_datatype!(a), Ok("export function a();")); | ||
assert(fn_datatype!(b), Ok("export function b(): null;")); | ||
assert(fn_datatype!(c), Ok("export async function c();")); | ||
assert(fn_datatype!(d), Ok("export function d(): string;")); | ||
assert(fn_datatype!(e), Ok("export function e(a: string);")); | ||
assert( | ||
fn_datatype!(f), | ||
Ok("export function f(a: string, b: number);"), | ||
); | ||
assert( | ||
fn_datatype!(g), | ||
Ok("/**\n * @deprecated\n */\nexport function g();"), | ||
); | ||
} | ||
|
||
#[track_caller] | ||
fn assert(dt: FunctionDataType, result: specta::ts::Result<&str>) { | ||
match export_function_header(dt, &Default::default()) { | ||
Ok(s) => assert_eq!(result, Ok(s.as_str())), | ||
Err(e) => assert_eq!(result, Err(e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod export_function_header; |