diff --git a/src/test/rustdoc-js-std/parser-errors.js b/src/test/rustdoc-js-std/parser-errors.js new file mode 100644 index 00000000000..98be691e0e7 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-errors.js @@ -0,0 +1,43 @@ +const QUERY = ['<"P">', '"P" "P"', 'P "P"']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [], + foundElems: 0, + id: "<\"P\">", + nameSplit: null, + original: "<\"P\">", + returned: [], + typeFilter: null, + val: "<\"p\">", + error: "`\"` cannot be used in generics", + }, + { + args: [], + elemName: null, + elems: [], + foundElems: 0, + id: "\"P\" \"P\"", + nameSplit: null, + original: "\"P\" \"P\"", + returned: [], + typeFilter: null, + val: "\"p\" \"p\"", + error: "Cannot have more than one literal search element", + }, + { + args: [], + elemName: null, + elems: [], + foundElems: 0, + id: "P \"P\"", + nameSplit: null, + original: "P \"P\"", + returned: [], + typeFilter: null, + val: "p \"p\"", + error: "Cannot use literal search when there is more than one element", + }, +]; diff --git a/src/test/rustdoc-js-std/parser-filter.js b/src/test/rustdoc-js-std/parser-filter.js new file mode 100644 index 00000000000..ba119af816a --- /dev/null +++ b/src/test/rustdoc-js-std/parser-filter.js @@ -0,0 +1,61 @@ +const QUERY = ['fn:foo', 'enum : foo', 'macro:foo']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [{ + name: "foo", + fullPath: ["foo"], + pathWithoutLast: [], + pathLast: "foo", + generics: [], + }], + foundElems: 1, + id: "fn:foo", + nameSplit: null, + original: "fn:foo", + returned: [], + typeFilter: 5, + val: "fn:foo", + error: null, + }, + { + args: [], + elemName: null, + elems: [{ + name: "foo", + fullPath: ["foo"], + pathWithoutLast: [], + pathLast: "foo", + generics: [], + }], + foundElems: 1, + id: "enum : foo", + nameSplit: null, + original: "enum : foo", + returned: [], + typeFilter: 4, + val: "enum : foo", + error: null, + }, + { + args: [], + elemName: null, + elems: [{ + name: "foo", + fullPath: ["foo"], + pathWithoutLast: [], + pathLast: "foo", + generics: [], + }], + foundElems: 1, + id: "macro:foo", + nameSplit: null, + original: "macro:foo", + returned: [], + typeFilter: 14, + val: "macro:foo", + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-generics.js b/src/test/rustdoc-js-std/parser-generics.js new file mode 100644 index 00000000000..4ad65d0d644 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-generics.js @@ -0,0 +1,81 @@ +const QUERY = ['

', 'A, E>']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [{ + name: "", + fullPath: [""], + pathWithoutLast: [], + pathLast: "", + generics: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + ], + }], + foundElems: 1, + id: "

", + nameSplit: null, + original: "

", + returned: [], + typeFilter: -1, + val: "

", + error: null, + }, + { + args: [], + elemName: null, + elems: [{ + name: "a", + fullPath: ["a"], + pathWithoutLast: [], + pathLast: "a", + generics: [ + { + name: "b", + fullPath: ["b"], + pathWithoutLast: [], + pathLast: "b", + generics: [ + { + name: "c", + fullPath: ["c"], + pathWithoutLast: [], + pathLast: "c", + generics: [ + { + name: "d", + fullPath: ["d"], + pathWithoutLast: [], + pathLast: "d", + generics: [], + }, + ], + }, + { + name: "e", + fullPath: ["e"], + pathWithoutLast: [], + pathLast: "e", + generics: [], + }, + ], + }, + ], + }], + foundElems: 1, + id: 'A, E>', + nameSplit: null, + original: 'A, E>', + returned: [], + typeFilter: -1, + val: 'a, e>', + error: null, + } +]; diff --git a/src/test/rustdoc-js-std/parser-in_args.js b/src/test/rustdoc-js-std/parser-in_args.js new file mode 100644 index 00000000000..6542319458f --- /dev/null +++ b/src/test/rustdoc-js-std/parser-in_args.js @@ -0,0 +1,50 @@ +const QUERY = ['(whatever)', '(

)']; + +const PARSED = [ + { + args: [{ + name: "whatever", + fullPath: ["whatever"], + pathWithoutLast: [], + pathLast: "whatever", + generics: [], + }], + elemName: null, + elems: [], + foundElems: 1, + id: "(whatever)", + nameSplit: null, + original: "(whatever)", + returned: [], + typeFilter: -1, + val: "(whatever)", + error: null, + }, + { + args: [{ + name: "", + fullPath: [""], + pathWithoutLast: [], + pathLast: "", + generics: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + ], + }], + elemName: null, + elems: [], + foundElems: 1, + id: "(

)", + nameSplit: null, + original: "(

)", + returned: [], + typeFilter: -1, + val: "(

)", + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-invalid.js b/src/test/rustdoc-js-std/parser-invalid.js new file mode 100644 index 00000000000..a94792b0694 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-invalid.js @@ -0,0 +1,128 @@ +// This test is mostly to check that the parser still kinda outputs something +// (and doesn't enter an infinite loop!) even though the query is completely +// invalid. +const QUERY = ['->

(p2)', '(p -> p2', 'a b', 'a,b(c)']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [], + foundElems: 2, + id: "->

(p2)", + nameSplit: null, + original: "->

(p2)", + returned: [ + { + name: "", + fullPath: [""], + pathWithoutLast: [], + pathLast: "", + generics: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + ], + }, + { + name: "p2", + fullPath: ["p2"], + pathWithoutLast: [], + pathLast: "p2", + generics: [], + }, + ], + typeFilter: -1, + val: "->

(p2)", + error: null, + }, + { + args: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + { + name: "p2", + fullPath: ["p2"], + pathWithoutLast: [], + pathLast: "p2", + generics: [], + }, + ], + elemName: null, + elems: [], + foundElems: 2, + id: "(p -> p2", + nameSplit: null, + original: "(p -> p2", + returned: [], + typeFilter: -1, + val: "(p -> p2", + error: null, + }, + { + args: [], + elemName: null, + elems: [ + { + name: "a b", + fullPath: ["a b"], + pathWithoutLast: [], + pathLast: "a b", + generics: [], + }, + ], + foundElems: 1, + id: "a b", + nameSplit: null, + original: "a b", + returned: [], + typeFilter: -1, + val: "a b", + error: null, + }, + { + args: [ + { + name: "c", + fullPath: ["c"], + pathWithoutLast: [], + pathLast: "c", + generics: [], + }, + ], + elemName: null, + elems: [ + { + name: "a", + fullPath: ["a"], + pathWithoutLast: [], + pathLast: "a", + generics: [], + }, + { + name: "b", + fullPath: ["b"], + pathWithoutLast: [], + pathLast: "b", + generics: [], + }, + ], + foundElems: 3, + id: "a,b(c)", + nameSplit: null, + original: "a,b(c)", + returned: [], + typeFilter: -1, + val: "a,b(c)", + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-literal.js b/src/test/rustdoc-js-std/parser-literal.js new file mode 100644 index 00000000000..0624930f14a --- /dev/null +++ b/src/test/rustdoc-js-std/parser-literal.js @@ -0,0 +1,31 @@ +const QUERY = ['"R"

']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [{ + name: "r", + fullPath: ["r"], + pathWithoutLast: [], + pathLast: "r", + generics: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + ], + }], + foundElems: 1, + id: "\"R\"

", + nameSplit: null, + original: "\"R\"

", + returned: [], + typeFilter: -1, + val: "\"r\"

", + error: null, + } +]; diff --git a/src/test/rustdoc-js-std/parser-paths.js b/src/test/rustdoc-js-std/parser-paths.js new file mode 100644 index 00000000000..9422eada9bc --- /dev/null +++ b/src/test/rustdoc-js-std/parser-paths.js @@ -0,0 +1,106 @@ +const QUERY = ['A::B', '::A::B', 'A::B::,C', 'A::B::,C']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [{ + name: "a::b", + fullPath: ["a", "b"], + pathWithoutLast: ["a"], + pathLast: "b", + generics: [], + }], + foundElems: 1, + id: "A::B", + nameSplit: null, + original: "A::B", + returned: [], + typeFilter: -1, + val: "a::b", + error: null, + }, + { + args: [], + elemName: null, + elems: [{ + name: "::a::b", + fullPath: ["a", "b"], + pathWithoutLast: ["a"], + pathLast: "b", + generics: [], + }], + foundElems: 1, + id: '::A::B', + nameSplit: null, + original: '::A::B', + returned: [], + typeFilter: -1, + val: '::a::b', + error: null, + }, + { + args: [], + elemName: null, + elems: [ + { + name: "a::b::", + fullPath: ["a", "b"], + pathWithoutLast: ["a"], + pathLast: "b", + generics: [], + }, + { + name: "c", + fullPath: ["c"], + pathWithoutLast: [], + pathLast: "c", + generics: [], + }, + ], + foundElems: 2, + id: 'A::B::,C', + nameSplit: null, + original: 'A::B::,C', + returned: [], + typeFilter: -1, + val: 'a::b::,c', + error: null, + }, + { + args: [], + elemName: null, + elems: [ + { + name: "a::b::", + fullPath: ["a", "b"], + pathWithoutLast: ["a"], + pathLast: "b", + generics: [ + { + name: "f", + fullPath: ["f"], + pathWithoutLast: [], + pathLast: "f", + generics: [], + }, + ], + }, + { + name: "c", + fullPath: ["c"], + pathWithoutLast: [], + pathLast: "c", + generics: [], + }, + ], + foundElems: 2, + id: 'A::B::,C', + nameSplit: null, + original: 'A::B::,C', + returned: [], + typeFilter: -1, + val: 'a::b::,c', + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-quote.js b/src/test/rustdoc-js-std/parser-quote.js new file mode 100644 index 00000000000..de7b004159f --- /dev/null +++ b/src/test/rustdoc-js-std/parser-quote.js @@ -0,0 +1,89 @@ +const QUERY = ['-> "p"', '"const": "p"', '("p")', '"p"

']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [], + foundElems: 1, + id: "-> \"p\"", + nameSplit: null, + original: "-> \"p\"", + returned: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }], + typeFilter: -1, + val: "-> \"p\"", + error: null, + }, + // This one checks that if quotes are used on the type filter, they're + // simply ignored. + { + args: [], + elemName: null, + elems: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }], + foundElems: 1, + id: "\"const\": \"p\"", + nameSplit: null, + original: "\"const\": \"p\"", + returned: [], + typeFilter: 17, + val: "\"const\": \"p\"", + error: null, + }, + { + args: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }], + elemName: null, + elems: [], + foundElems: 1, + id: "(\"p\")", + nameSplit: null, + original: "(\"p\")", + returned: [], + typeFilter: -1, + val: "(\"p\")", + error: null, + }, + // This test checks that a literal item can still have generics. + { + args: [], + elemName: null, + elems: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }], + }], + foundElems: 1, + id: "\"p\"

", + nameSplit: null, + original: "\"p\"

", + returned: [], + typeFilter: -1, + val: "\"p\"

", + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-returned.js b/src/test/rustdoc-js-std/parser-returned.js new file mode 100644 index 00000000000..92b378f1393 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-returned.js @@ -0,0 +1,50 @@ +const QUERY = ['->

', '-> P']; + +const PARSED = [ + { + args: [], + elemName: null, + elems: [], + foundElems: 1, + id: "->

", + nameSplit: null, + original: "->

", + returned: [{ + name: "", + fullPath: [""], + pathWithoutLast: [], + pathLast: "", + generics: [ + { + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }, + ], + }], + typeFilter: -1, + val: "->

", + error: null, + }, + { + args: [], + elemName: null, + elems: [], + foundElems: 1, + id: "-> P", + nameSplit: null, + original: "-> P", + returned: [{ + name: "p", + fullPath: ["p"], + pathWithoutLast: [], + pathLast: "p", + generics: [], + }], + typeFilter: -1, + val: "-> p", + error: null, + }, +]; diff --git a/src/test/rustdoc-js/generics.js b/src/test/rustdoc-js/generics.js index 9d5937dafdc..babfbf98e3e 100644 --- a/src/test/rustdoc-js/generics.js +++ b/src/test/rustdoc-js/generics.js @@ -1,10 +1,10 @@ // exact-check const QUERY = [ - '"R"<"P">', + '"R"

', '"P"', 'P', - '"ExtraCreditStructMulti"<"ExtraCreditInnerMulti", "ExtraCreditInnerMulti">', + '"ExtraCreditStructMulti"', 'TraitCat', 'TraitDog', 'Result', @@ -12,7 +12,7 @@ const QUERY = [ const EXPECTED = [ { - // "R"<"P"> + // "R"

'returned': [ { 'path': 'generics', 'name': 'alef' }, ], @@ -36,15 +36,13 @@ const EXPECTED = [ // P 'returned': [ { 'path': 'generics', 'name': 'alef' }, - { 'path': 'generics', 'name': 'bet' }, ], 'in_args': [ { 'path': 'generics', 'name': 'alpha' }, - { 'path': 'generics', 'name': 'beta' }, ], }, { - // "ExtraCreditStructMulti"<"ExtraCreditInnerMulti", "ExtraCreditInnerMulti"> + // "ExtraCreditStructMulti" 'in_args': [ { 'path': 'generics', 'name': 'extracreditlabhomework' }, ],