Add parser tests

This commit is contained in:
Guillaume Gomez 2021-12-20 17:45:52 +01:00
parent 7cefee027a
commit f5833e759e
10 changed files with 643 additions and 6 deletions

View File

@ -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",
},
];

View File

@ -0,0 +1,61 @@
const QUERY = ['fn:foo', 'enum : foo', 'macro<f>: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<f>:foo",
nameSplit: null,
original: "macro<f>:foo",
returned: [],
typeFilter: 14,
val: "macro<f>:foo",
error: null,
},
];

View File

@ -0,0 +1,81 @@
const QUERY = ['<P>', 'A<B<C<D>, E>'];
const PARSED = [
{
args: [],
elemName: null,
elems: [{
name: "",
fullPath: [""],
pathWithoutLast: [],
pathLast: "",
generics: [
{
name: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
generics: [],
},
],
}],
foundElems: 1,
id: "<P>",
nameSplit: null,
original: "<P>",
returned: [],
typeFilter: -1,
val: "<p>",
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<B<C<D>, E>',
nameSplit: null,
original: 'A<B<C<D>, E>',
returned: [],
typeFilter: -1,
val: 'a<b<c<d>, e>',
error: null,
}
];

View File

@ -0,0 +1,50 @@
const QUERY = ['(whatever)', '(<P>)'];
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: "(<P>)",
nameSplit: null,
original: "(<P>)",
returned: [],
typeFilter: -1,
val: "(<p>)",
error: null,
},
];

View File

@ -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 = ['-> <P> (p2)', '(p -> p2', 'a b', 'a,b(c)'];
const PARSED = [
{
args: [],
elemName: null,
elems: [],
foundElems: 2,
id: "-> <P> (p2)",
nameSplit: null,
original: "-> <P> (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: "-> <p> (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,
},
];

View File

@ -0,0 +1,31 @@
const QUERY = ['"R"<P>'];
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\"<P>",
nameSplit: null,
original: "\"R\"<P>",
returned: [],
typeFilter: -1,
val: "\"r\"<p>",
error: null,
}
];

View File

@ -0,0 +1,106 @@
const QUERY = ['A::B', '::A::B', 'A::B::,C', 'A::B::<f>,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::<f>,C',
nameSplit: null,
original: 'A::B::<f>,C',
returned: [],
typeFilter: -1,
val: 'a::b::<f>,c',
error: null,
},
];

View File

@ -0,0 +1,89 @@
const QUERY = ['-> "p"', '"const": "p"', '("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\"<p>",
nameSplit: null,
original: "\"p\"<p>",
returned: [],
typeFilter: -1,
val: "\"p\"<p>",
error: null,
},
];

View File

@ -0,0 +1,50 @@
const QUERY = ['-> <P>', '-> P'];
const PARSED = [
{
args: [],
elemName: null,
elems: [],
foundElems: 1,
id: "-> <P>",
nameSplit: null,
original: "-> <P>",
returned: [{
name: "",
fullPath: [""],
pathWithoutLast: [],
pathLast: "",
generics: [
{
name: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
generics: [],
},
],
}],
typeFilter: -1,
val: "-> <p>",
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,
},
];

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