Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 527
Add else if support#879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Add else if support
#879
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -197,15 +197,19 @@ world`}, | ||
| }, | ||
| { | ||
| "true ? true : false", | ||
| &ConditionalNode{Cond: &BoolNode{Value: true}, | ||
| Exp1: &BoolNode{Value: true}, | ||
| Exp2: &BoolNode{}}, | ||
| &ConditionalNode{ | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &BoolNode{Value: true}, | ||
| Exp2: &BoolNode{}}, | ||
| }, | ||
| { | ||
| "a?[b]:c", | ||
| &ConditionalNode{Cond: &IdentifierNode{Value: "a"}, | ||
| Exp1: &ArrayNode{Nodes: []Node{&IdentifierNode{Value: "b"}}}, | ||
| Exp2: &IdentifierNode{Value: "c"}}, | ||
| &ConditionalNode{ | ||
| Ternary: true, | ||
| Cond: &IdentifierNode{Value: "a"}, | ||
| Exp1: &ArrayNode{Nodes: []Node{&IdentifierNode{Value: "b"}}}, | ||
| Exp2: &IdentifierNode{Value: "c"}}, | ||
| }, | ||
| { | ||
| "a.b().c().d[33]", | ||
| @@ -396,6 +400,7 @@ world`}, | ||
| { | ||
| "2==2 ? false : 3 not in [1, 2, 5]", | ||
| &ConditionalNode{ | ||
| Ternary: true, | ||
| Cond: &BinaryNode{ | ||
| Operator: "==", | ||
| Left: &IntegerNode{Value: 2}, | ||
| @@ -659,6 +664,29 @@ world`}, | ||
| Exp1: &BoolNode{Value: true}, | ||
| Exp2: &IdentifierNode{Value: "x"}}, | ||
| }, | ||
| { | ||
| "if a { 1 } else if b { 2 } else { 3 }", | ||
| &ConditionalNode{ | ||
| Cond: &IdentifierNode{Value: "a"}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &ConditionalNode{ | ||
| Cond: &IdentifierNode{Value: "b"}, | ||
| Exp1: &IntegerNode{Value: 2}, | ||
| Exp2: &IntegerNode{Value: 3}}}, | ||
| }, | ||
Comment on lines
+667
to
+676
CopilotAI | ||
| { | ||
| "if a { 1 } else if b { 2 } else if c { 3 } else { 4 }", | ||
| &ConditionalNode{ | ||
| Cond: &IdentifierNode{Value: "a"}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &ConditionalNode{ | ||
| Cond: &IdentifierNode{Value: "b"}, | ||
| Exp1: &IntegerNode{Value: 2}, | ||
| Exp2: &ConditionalNode{ | ||
| Cond: &IdentifierNode{Value: "c"}, | ||
| Exp1: &IntegerNode{Value: 3}, | ||
| Exp2: &IntegerNode{Value: 4}}}}, | ||
| }, | ||
| { | ||
| "1; 2; 3", | ||
| &SequenceNode{ | ||
| @@ -687,9 +715,10 @@ world`}, | ||
| &SequenceNode{ | ||
| Nodes: []Node{ | ||
| &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}, | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}, | ||
| &IntegerNode{Value: 3}, | ||
| &IntegerNode{Value: 4}, | ||
| }, | ||
| @@ -698,8 +727,9 @@ world`}, | ||
| { | ||
| "true ? 1 : ( 2; 3; 4 )", | ||
| &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &SequenceNode{ | ||
| Nodes: []Node{ | ||
| &IntegerNode{Value: 2}, | ||
| @@ -714,9 +744,10 @@ world`}, | ||
| &SequenceNode{ | ||
| Nodes: []Node{ | ||
| &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &BoolNode{Value: true}, | ||
| Exp2: &IntegerNode{Value: 1}}, | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &BoolNode{Value: true}, | ||
| Exp2: &IntegerNode{Value: 1}}, | ||
| &IntegerNode{Value: 2}, | ||
| &IntegerNode{Value: 3}, | ||
| }, | ||
| @@ -727,18 +758,20 @@ world`}, | ||
| &VariableDeclaratorNode{ | ||
| Name: "x", | ||
| Value: &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}, | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}, | ||
| Expr: &IdentifierNode{Value: "x"}}, | ||
| }, | ||
| { | ||
| "let x = true ? 1 : ( 2; 3; 4 ); x", | ||
| &VariableDeclaratorNode{ | ||
| Name: "x", | ||
| Value: &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Ternary: true, | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &SequenceNode{ | ||
| Nodes: []Node{ | ||
| &IntegerNode{Value: 2}, | ||
| @@ -762,7 +795,8 @@ world`}, | ||
| Nodes: []Node{ | ||
| &IntegerNode{Value: 4}, | ||
| &IntegerNode{Value: 5}, | ||
| &IntegerNode{Value: 6}}}}, | ||
| &IntegerNode{Value: 6}}}, | ||
| }, | ||
| }, | ||
| { | ||
| `all(ls, if true { 1 } else { 2 })`, | ||
| @@ -774,7 +808,8 @@ world`}, | ||
| Node: &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}}}}, | ||
| Exp2: &IntegerNode{Value: 2}, | ||
| }}}}, | ||
| }, | ||
| { | ||
| `let x = if true { 1 } else { 2 }; x`, | ||
| @@ -783,7 +818,8 @@ world`}, | ||
| Value: &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}, | ||
| Exp2: &IntegerNode{Value: 2}, | ||
| }, | ||
| Expr: &IdentifierNode{Value: "x"}}, | ||
| }, | ||
| { | ||
| @@ -794,7 +830,8 @@ world`}, | ||
| &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}}}, | ||
| Exp2: &IntegerNode{Value: 2}, | ||
| }}}, | ||
| }, | ||
| { | ||
| `[if true { 1 } else { 2 }]`, | ||
| @@ -803,7 +840,8 @@ world`}, | ||
| &ConditionalNode{ | ||
| Cond: &BoolNode{Value: true}, | ||
| Exp1: &IntegerNode{Value: 1}, | ||
| Exp2: &IntegerNode{Value: 2}}}}, | ||
| Exp2: &IntegerNode{Value: 2}, | ||
| }}}, | ||
| }, | ||
| { | ||
| `map(ls, { 1; 2; 3 })`, | ||
| @@ -1019,6 +1057,12 @@ func TestParse_error(t *testing.T) { | ||
| `unexpected token Operator("if") (1:5) | ||
| | 1 + if true { 2 } else { 3 } | ||
| | ....^`, | ||
| }, | ||
| { | ||
| `if a { 1 } else b`, | ||
| `unexpected token Identifier("b") (1:17) | ||
| | if a { 1 } else b | ||
| | ................^`, | ||
| }, | ||
| { | ||
| `list | all(#,,)`, | ||
Uh oh!
There was an error while loading. Please reload this page.
CopilotAIDec 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test case with multiple chained else if statements to ensure the feature works correctly for longer chains. For example:
if 1 == 2 { "a" } else if 2 == 3 { "b" } else if 3 == 3 { "c" } else { "d" }with expected result "c".