Skip to content

Commit

Permalink
Add tests for array access, and mixed array access/function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Nov 30, 2023
1 parent 00251ca commit b5b84ee
Show file tree
Hide file tree
Showing 2 changed files with 410 additions and 0 deletions.
205 changes: 205 additions & 0 deletions spec/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,211 @@ const sampleExpressions = Object.entries({
],
"error"
],
array1: [
[
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "1", type: "number.decimal" },
{ text: "]", type: "bracket.close" },
],
{
operator: "array access",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{ text: "1", type: "number.decimal" },
]
}
],
array2: [
[
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "a", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "b", type: "name" },
{ text: "]", type: "bracket.close" },
],
{
operator: "array access",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{
operator: operators.add,
operatorToken: { text: "+", type: "operator.add" },
nodes: [
{ text: "a", type: "name" },
{ text: "b", type: "name" },
]
},
]
}
],
arraynested1: [
[
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "a", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "sussy", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "b", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "c", type: "name" },
{ text: "]", type: "bracket.close" },
{ text: "]", type: "bracket.close" },
],
{
operator: "array access",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{
operator: operators.add,
operatorToken: { text: "+", type: "operator.add" },
nodes: [
{ text: "a", type: "name" },
{
operator: "array access",
operatorToken: { text: "sussy", type: "name" },
nodes: [
{
operator: operators.add,
operatorToken: { text: "+", type: "operator.add" },
nodes: [
{ text: "b", type: "name" },
{ text: "c", type: "name" },
]
},
]
}
]
},
]
}
],
arrayfunction1: [
[
{ text: "arr", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "a", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "amogus", type: "name" },
{ text: "(", type: "parentheses.open" },
{ text: "5", type: "number.decimal" },
{ text: ",", type: "punctuation.comma" },
{ text: "6", type: "number.decimal" },
{ text: ")", type: "parentheses.close" },
{ text: "]", type: "bracket.close" },
],
{
operator: "array access",
operatorToken: { text: "arr", type: "name" },
nodes: [
{
operator: operators.add,
operatorToken: { text: "+", type: "operator.add" },
nodes: [
{ text: "a", type: "name" },
{
operator: "function call",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{ text: "5", type: "number.decimal" },
{ text: "6", type: "number.decimal" },
]
}
]
},
]
}
],
arrayfunction2: [
[
{ text: "amogus", type: "name" },
{ text: "(", type: "parentheses.open" },
{ text: "a", type: "name" },
{ text: ",", type: "punctuation.comma" },
{ text: "b", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "5", type: "number.decimal" },
{ text: ",", type: "punctuation.comma" },
{ text: "6", type: "number.decimal" },
{ text: "]", type: "bracket.close" },
{ text: ")", type: "parentheses.close" },
],
{
operator: "function call",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{ text: "a", type: "name" },
{
operator: operators.add,
operatorToken: { text: "+", type: "operator.add" },
nodes: [
{ text: "b", type: "name" },
{
operator: "array access",
operatorToken: { text: "amogus", type: "name" },
nodes: [
{ text: "5", type: "number.decimal" },
{ text: "6", type: "number.decimal" },
]
}
]
},
]
}
],
arraybad1: [
[
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "]", type: "bracket.close" },
],
"error"
],
arraybad2: [
[
{ text: "amogus", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "[", type: "bracket.open" },
{ text: "]", type: "bracket.close" },
{ text: "]", type: "bracket.close" },
],
"error"
],
arrayfunctionbad1: [
[
{ text: "arr", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "a", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "amogus", type: "name" },
{ text: "(", type: "parentheses.open" },
{ text: "5", type: "number.decimal" },
{ text: "6", type: "number.decimal" },
{ text: ")", type: "parentheses.close" },
{ text: "]", type: "bracket.close" },
],
"error"
],
arrayfunctionbad2: [
[
{ text: "arr", type: "name" },
{ text: "[", type: "bracket.open" },
{ text: "a", type: "name" },
{ text: "+", type: "operator.add" },
{ text: "amogus", type: "name" },
{ text: "(", type: "parentheses.open" },
{ text: "5", type: "number.decimal" },
{ text: ",", type: "punctuation.comma" },
{ text: "6", type: "number.decimal" },
{ text: "]", type: "bracket.close" },
{ text: ")", type: "parentheses.close" },
],
"error"
],
SussyBaka: [
[
{ text: "(", type: "parentheses.open" },
Expand Down
Loading

0 comments on commit b5b84ee

Please sign in to comment.