1
Fork 0

* If type filter is in quotes, throw an error.

* If there are generics, don't allow to have quotes.
This commit is contained in:
Guillaume Gomez 2022-01-03 23:51:20 +01:00
parent bbcf1762dd
commit 51de26cfd9
5 changed files with 45 additions and 58 deletions

View file

@ -216,11 +216,13 @@ window.initSearch = function(rawSearchIndex) {
} }
function isPathStart(query) { function isPathStart(query) {
var pos = query.pos; var pos = query.pos;
return pos + 1 < query.length && query.userQuery[pos] === ':' && query.userQuery[pos + 1] === ':'; return pos + 1 < query.length && query.userQuery[pos] === ':' &&
query.userQuery[pos + 1] === ':';
} }
function isReturnArrow(query) { function isReturnArrow(query) {
var pos = query.pos; var pos = query.pos;
return pos + 1 < query.length && query.userQuery[pos] === '-' && query.userQuery[pos + 1] === '>'; return pos + 1 < query.length && query.userQuery[pos] === '-' &&
query.userQuery[pos + 1] === '>';
} }
function removeEmptyStringsFromArray(x) { function removeEmptyStringsFromArray(x) {
for (var i = 0, len = x.length; i < len; ++i) { for (var i = 0, len = x.length; i < len; ++i) {
@ -235,6 +237,9 @@ window.initSearch = function(rawSearchIndex) {
if (name === '*' || (name.length === 0 && generics.length === 0)) { if (name === '*' || (name.length === 0 && generics.length === 0)) {
return; return;
} }
if (query.literalSearch && query.totalElems > 0) {
throw new Error("You cannot have more than one element if you use quotes");
}
var paths = name.split("::"); var paths = name.split("::");
removeEmptyStringsFromArray(paths); removeEmptyStringsFromArray(paths);
// In case we only have something like `<p>`, there is no name but it remains valid. // In case we only have something like `<p>`, there is no name but it remains valid.
@ -320,6 +325,9 @@ window.initSearch = function(rawSearchIndex) {
} else if (c === ":" && query.typeFilter === null && !isPathStart(query) && } else if (c === ":" && query.typeFilter === null && !isPathStart(query) &&
query.elems.length === 1) query.elems.length === 1)
{ {
if (query.literalSearch) {
throw new Error("You cannot use quotes on type filter");
}
// The type filter doesn't count as an element since it's a modifier. // The type filter doesn't count as an element since it's a modifier.
query.typeFilter = query.elems.pop().name; query.typeFilter = query.elems.pop().name;
query.pos += 1; query.pos += 1;
@ -400,7 +408,7 @@ window.initSearch = function(rawSearchIndex) {
if (!query.literalSearch) { if (!query.literalSearch) {
// If there is more than one element in the query, we switch to literalSearch in any // If there is more than one element in the query, we switch to literalSearch in any
// case. // case.
query.literalSearch = query.foundElems > 1; query.literalSearch = query.totalElems > 1;
} }
if (query.elemName !== null) { if (query.elemName !== null) {
query.foundElems += 1; query.foundElems += 1;

View file

@ -1,4 +1,4 @@
const QUERY = ['<"P">', '"P" "P"', 'P "P"']; const QUERY = ['<"P">', '"P" "P"', 'P "P"', '"p" p', '"const": p'];
const PARSED = [ const PARSED = [
{ {
@ -40,4 +40,30 @@ const PARSED = [
userQuery: "p \"p\"", userQuery: "p \"p\"",
error: "Cannot use literal search when there is more than one element", error: "Cannot use literal search when there is more than one element",
}, },
{
args: [],
elemName: null,
elems: [],
foundElems: 0,
id: "\"p\" p",
nameSplit: null,
original: "\"p\" p",
returned: [],
typeFilter: null,
userQuery: "\"p\" p",
error: "You cannot have more than one element if you use quotes",
},
{
args: [],
elemName: null,
elems: [],
foundElems: 0,
id: "\"const\": p",
nameSplit: null,
original: "\"const\": p",
returned: [],
typeFilter: null,
userQuery: "\"const\": p",
error: "You cannot use quotes on type filter",
},
]; ];

View file

@ -1,4 +1,4 @@
const QUERY = ['"R"<P>']; const QUERY = ['R<P>'];
const PARSED = [ const PARSED = [
{ {
@ -20,12 +20,12 @@ const PARSED = [
], ],
}], }],
foundElems: 1, foundElems: 1,
id: "\"R\"<P>", id: "R<P>",
nameSplit: null, nameSplit: null,
original: "\"R\"<P>", original: "R<P>",
returned: [], returned: [],
typeFilter: -1, typeFilter: -1,
userQuery: "\"r\"<p>", userQuery: "r<p>",
error: null, error: null,
} }
]; ];

View file

@ -1,4 +1,4 @@
const QUERY = ['-> "p"', '"const": "p"', '("p")', '"p"<p>']; const QUERY = ['-> "p"', '("p")'];
const PARSED = [ const PARSED = [
{ {
@ -20,27 +20,6 @@ const PARSED = [
userQuery: "-> \"p\"", userQuery: "-> \"p\"",
error: null, 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,
userQuery: "\"const\": \"p\"",
error: null,
},
{ {
args: [{ args: [{
name: "p", name: "p",
@ -60,30 +39,4 @@ const PARSED = [
userQuery: "(\"p\")", userQuery: "(\"p\")",
error: null, 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\"<p>",
nameSplit: null,
original: "\"p\"<p>",
returned: [],
typeFilter: -1,
userQuery: "\"p\"<p>",
error: null,
},
]; ];

View file

@ -1,10 +1,10 @@
// exact-check // exact-check
const QUERY = [ const QUERY = [
'"R"<P>', 'R<P>',
'"P"', '"P"',
'P', 'P',
'"ExtraCreditStructMulti"<ExtraCreditInnerMulti, ExtraCreditInnerMulti>', 'ExtraCreditStructMulti<ExtraCreditInnerMulti, ExtraCreditInnerMulti>',
'TraitCat', 'TraitCat',
'TraitDog', 'TraitDog',
'Result<String>', 'Result<String>',