summaryrefslogtreecommitdiff
path: root/cli/doc/tests.rs
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2020-04-02 11:38:13 +0200
committerGitHub <noreply@github.com>2020-04-02 11:38:13 +0200
commit3d56f3afcadf04cc082a77fa0ec2fcd9d76e039f (patch)
tree39a80c779ecfaebfc0ba59124413c78b67c1ea3e /cli/doc/tests.rs
parent2e24385c487d5471aceae7d7e7de9da4c7d87064 (diff)
Added 'declare' handling to 'deno doc' (#4573)
Diffstat (limited to 'cli/doc/tests.rs')
-rw-r--r--cli/doc/tests.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/cli/doc/tests.rs b/cli/doc/tests.rs
index 8cc61195a..7acadc228 100644
--- a/cli/doc/tests.rs
+++ b/cli/doc/tests.rs
@@ -592,6 +592,100 @@ export namespace RootNs {
}
#[test]
+fn declare_namespace() {
+ let source_code = r#"
+/** Namespace JSdoc */
+declare namespace RootNs {
+ declare const a = "a";
+
+ /** Nested namespace JSDoc */
+ declare namespace NestedNs {
+ declare enum Foo {
+ a = 1,
+ b = 2,
+ c = 3,
+ }
+ }
+}
+ "#;
+ let entries = DocParser::default()
+ .parse("test.ts".to_string(), source_code.to_string())
+ .unwrap();
+ assert_eq!(entries.len(), 1);
+ let entry = &entries[0];
+ let expected_json = json!({
+ "kind": "namespace",
+ "name": "RootNs",
+ "location": {
+ "filename": "test.ts",
+ "line": 3,
+ "col": 0
+ },
+ "jsDoc": "Namespace JSdoc",
+ "namespaceDef": {
+ "elements": [
+ {
+ "kind": "variable",
+ "name": "a",
+ "location": {
+ "filename": "test.ts",
+ "line": 4,
+ "col": 12
+ },
+ "jsDoc": null,
+ "variableDef": {
+ "tsType": null,
+ "kind": "const"
+ }
+ },
+ {
+ "kind": "namespace",
+ "name": "NestedNs",
+ "location": {
+ "filename": "test.ts",
+ "line": 7,
+ "col": 4
+ },
+ "jsDoc": "Nested namespace JSDoc",
+ "namespaceDef": {
+ "elements": [
+ {
+ "kind": "enum",
+ "name": "Foo",
+ "location": {
+ "filename": "test.ts",
+ "line": 8,
+ "col": 6
+ },
+ "jsDoc": null,
+ "enumDef": {
+ "members": [
+ {
+ "name": "a"
+ },
+ {
+ "name": "b"
+ },
+ {
+ "name": "c"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ });
+ let actual = serde_json::to_value(entry).unwrap();
+ assert_eq!(actual, expected_json);
+ assert!(
+ colors::strip_ansi_codes(super::printer::format(entries).as_str())
+ .contains("namespace RootNs")
+ );
+}
+#[test]
fn optional_return_type() {
let source_code = r#"
export function foo(a: number) {