summaryrefslogtreecommitdiff
path: root/cli/doc/tests.rs
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2020-04-14 00:07:06 +0200
committerGitHub <noreply@github.com>2020-04-14 00:07:06 +0200
commita9923f3f93f8786388d84313666f0fc11113830f (patch)
tree4743a3986f8570a21f4ba6477f9ee956b448b07e /cli/doc/tests.rs
parent2585b72c9bdd5ca36b6b43cf5b5609419081c7a8 (diff)
fix(doc): expose optionality in function params and class members (#4738)
Diffstat (limited to 'cli/doc/tests.rs')
-rw-r--r--cli/doc/tests.rs42
1 files changed, 37 insertions, 5 deletions
diff --git a/cli/doc/tests.rs b/cli/doc/tests.rs
index fb2c69689..9a9ac8e02 100644
--- a/cli/doc/tests.rs
+++ b/cli/doc/tests.rs
@@ -52,7 +52,7 @@ async fn export_fn() {
*
* Or not that many?
*/
-export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ...args: unknown[]): void {
+export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, ...args: unknown[]): void {
console.log("Hello world");
}
"#;
@@ -70,6 +70,7 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
{
"name": "a",
"kind": "identifier",
+ "optional": false,
"tsType": {
"keyword": "string",
"kind": "keyword",
@@ -79,6 +80,7 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
{
"name": "b",
"kind": "identifier",
+ "optional": true,
"tsType": {
"keyword": "number",
"kind": "keyword",
@@ -88,6 +90,7 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
{
"name": "cb",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "",
"kind": "fnOrConstructor",
@@ -102,6 +105,7 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
"params": [{
"kind": "rest",
"name": "cbArgs",
+ "optional": false,
"tsType": {
"repr": "",
"kind": "array",
@@ -118,6 +122,7 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
{
"name": "args",
"kind": "rest",
+ "optional": false,
"tsType": {
"repr": "",
"kind": "array",
@@ -148,9 +153,13 @@ export function foo(a: string, b: number, cb: (...cbArgs: unknown[]) => void, ..
let actual = serde_json::to_value(entry).unwrap();
assert_eq!(actual, expected_json);
+ assert!(colors::strip_ansi_codes(
+ super::printer::format(entries.clone()).as_str()
+ )
+ .contains("Hello there"));
assert!(
colors::strip_ansi_codes(super::printer::format(entries).as_str())
- .contains("Hello there")
+ .contains("b?: number")
);
}
@@ -180,6 +189,7 @@ export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest},
{
"name": "",
"kind": "array",
+ "optional": false,
"tsType": {
"repr": "",
"kind": "array",
@@ -193,11 +203,13 @@ export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest},
{
"name": "",
"kind": "object",
+ "optional": false,
"tsType": null
},
{
"name": "ops",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "AssignOpts",
"kind": "typeRef",
@@ -270,7 +282,7 @@ async fn export_class() {
let source_code = r#"
/** Class doc */
export class Foobar extends Fizz implements Buzz, Aldrin {
- private private1: boolean;
+ private private1?: boolean;
protected protected1: number;
public public1: boolean;
public2: number;
@@ -284,7 +296,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
}
/** Sync bar method */
- bar(): void {
+ bar?(): void {
//
}
}
@@ -316,6 +328,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
{
"name": "name",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "string",
"kind": "keyword",
@@ -325,6 +338,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
{
"name": "private2",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "number",
"kind": "keyword",
@@ -334,6 +348,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
{
"name": "protected2",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "number",
"kind": "keyword",
@@ -358,6 +373,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
},
"readonly": false,
"accessibility": "private",
+ "optional": true,
"isAbstract": false,
"isStatic": false,
"name": "private1",
@@ -376,6 +392,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
},
"readonly": false,
"accessibility": "protected",
+ "optional": false,
"isAbstract": false,
"isStatic": false,
"name": "protected1",
@@ -394,6 +411,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
},
"readonly": false,
"accessibility": "public",
+ "optional": false,
"isAbstract": false,
"isStatic": false,
"name": "public1",
@@ -412,6 +430,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
},
"readonly": false,
"accessibility": null,
+ "optional": false,
"isAbstract": false,
"isStatic": false,
"name": "public2",
@@ -426,6 +445,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
{
"jsDoc": "Async foo method",
"accessibility": null,
+ "optional": false,
"isAbstract": false,
"isStatic": false,
"name": "foo",
@@ -459,6 +479,7 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
{
"jsDoc": "Sync bar method",
"accessibility": null,
+ "optional": true,
"isAbstract": false,
"isStatic": false,
"name": "bar",
@@ -487,6 +508,11 @@ export class Foobar extends Fizz implements Buzz, Aldrin {
let actual = serde_json::to_value(entry).unwrap();
assert_eq!(actual, expected_json);
+ assert!(colors::strip_ansi_codes(
+ super::printer::format_details(entry.clone()).as_str()
+ )
+ .contains("bar?(): void"));
+
assert!(
colors::strip_ansi_codes(super::printer::format(entries).as_str())
.contains("class Foobar extends Fizz implements Buzz, Aldrin")
@@ -501,7 +527,7 @@ async fn export_interface() {
*/
export interface Reader {
/** Read n bytes */
- read(buf: Uint8Array, something: unknown): Promise<number>
+ read?(buf: Uint8Array, something: unknown): Promise<number>
}
"#;
let loader =
@@ -527,11 +553,13 @@ export interface Reader {
"line": 7,
"col": 4
},
+ "optional": true,
"jsDoc": "Read n bytes",
"params": [
{
"name": "buf",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "Uint8Array",
"kind": "typeRef",
@@ -544,6 +572,7 @@ export interface Reader {
{
"name": "something",
"kind": "identifier",
+ "optional": false,
"tsType": {
"repr": "unknown",
"kind": "keyword",
@@ -613,6 +642,7 @@ export interface TypedIface<T> {
"col": 4
},
"jsDoc": null,
+ "optional": false,
"params": [],
"typeParams": [],
"returnType": {
@@ -956,6 +986,7 @@ async fn optional_return_type() {
{
"name": "a",
"kind": "identifier",
+ "optional": false,
"tsType": {
"keyword": "number",
"kind": "keyword",
@@ -1048,6 +1079,7 @@ export function fooFn(a: number) {
{
"name": "a",
"kind": "identifier",
+ "optional": false,
"tsType": {
"keyword": "number",
"kind": "keyword",