From a27d20dbcdfacb8a63aafd327638cab7c4ca01b4 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 12 Feb 2026 09:01:27 +0100 Subject: [PATCH] Rust: Add test cases for binary operator at start of line --- ruby/ql/test/library-tests/ast/Ast.expected | 18 ++++++++++ .../library-tests/ast/TreeSitter.expected | 33 +++++++++++++++++++ .../test/library-tests/ast/ValueText.expected | 12 +++++++ .../ast/control/ConditionalExpr.expected | 6 ++++ .../ast/control/ControlExpr.expected | 3 ++ .../library-tests/ast/control/conditionals.rb | 19 +++++++++++ 6 files changed, 91 insertions(+) diff --git a/ruby/ql/test/library-tests/ast/Ast.expected b/ruby/ql/test/library-tests/ast/Ast.expected index 6263cb8919b..bdc67bd794d 100644 --- a/ruby/ql/test/library-tests/ast/Ast.expected +++ b/ruby/ql/test/library-tests/ast/Ast.expected @@ -1458,6 +1458,24 @@ control/conditionals.rb: # 67| getBranch/getThen: [StmtSequence] then ... # 68| getBranch/getElse: [StmtSequence] else ... # 69| getStmt: [LocalVariableAccess] c +# 73| getStmt: [IfExpr] if ... +# 73| getCondition: [LogicalAndExpr] ... && ... +# 73| getAnOperand/getLeftOperand/getReceiver: [LocalVariableAccess] a +# 73| getAnOperand/getArgument/getRightOperand: [LocalVariableAccess] b +# 73| getBranch/getThen: [StmtSequence] then ... +# 74| getStmt: [LocalVariableAccess] c +# 78| getStmt: [IfExpr] if ... +# 78| getCondition: [LogicalAndExpr] ... && ... +# 78| getAnOperand/getLeftOperand/getReceiver: [LocalVariableAccess] a +# 79| getAnOperand/getArgument/getRightOperand: [LocalVariableAccess] b +# 79| getBranch/getThen: [StmtSequence] then ... +# 81| getStmt: [LocalVariableAccess] c +# 85| getStmt: [IfExpr] if ... +# 85| getCondition: [LogicalAndExpr] ... && ... +# 85| getAnOperand/getLeftOperand/getReceiver: [LocalVariableAccess] a +# 86| getAnOperand/getArgument/getRightOperand: [LocalVariableAccess] b +# 86| getBranch/getThen: [StmtSequence] then ... +# 88| getStmt: [LocalVariableAccess] c constants/constants.rb: # 1| [Toplevel] constants.rb # 1| getStmt: [ModuleDeclaration] ModuleA diff --git a/ruby/ql/test/library-tests/ast/TreeSitter.expected b/ruby/ql/test/library-tests/ast/TreeSitter.expected index 04a66cce847..a2ae9813a79 100644 --- a/ruby/ql/test/library-tests/ast/TreeSitter.expected +++ b/ruby/ql/test/library-tests/ast/TreeSitter.expected @@ -2962,6 +2962,36 @@ control/conditionals.rb: # 68| 0: [ReservedWord] else # 69| 1: [Identifier] c # 70| 4: [ReservedWord] end +# 73| 17: [If] If +# 73| 0: [ReservedWord] if +# 73| 1: [Binary] Binary +# 73| 0: [Identifier] a +# 73| 1: [ReservedWord] && +# 73| 2: [Identifier] b +# 73| 2: [Then] Then +# 73| 0: [ReservedWord] then +# 74| 1: [Identifier] c +# 75| 3: [ReservedWord] end +# 78| 18: [If] If +# 78| 0: [ReservedWord] if +# 78| 1: [Binary] Binary +# 78| 0: [Identifier] a +# 79| 1: [ReservedWord] && +# 79| 2: [Identifier] b +# 79| 2: [Then] Then +# 80| 0: [ReservedWord] then +# 81| 1: [Identifier] c +# 82| 3: [ReservedWord] end +# 85| 19: [If] If +# 85| 0: [ReservedWord] if +# 85| 1: [Binary] Binary +# 85| 0: [Identifier] a +# 85| 1: [ReservedWord] && +# 86| 2: [Identifier] b +# 86| 2: [Then] Then +# 87| 0: [ReservedWord] then +# 88| 1: [Identifier] c +# 89| 3: [ReservedWord] end # 1| [Comment] # Define some variables used below # 9| [Comment] # If expr with no else # 14| [Comment] # If expr with single else @@ -2974,6 +3004,9 @@ control/conditionals.rb: # 57| [Comment] # Ternary if expr # 60| [Comment] # If expr with empty else (treated as no else) # 66| [Comment] # If expr with empty then (treated as no then) +# 72| [Comment] # If expr with && on same line as condition and then +# 77| [Comment] # If expr with && at the start of a separate line before then +# 84| [Comment] # If expr with && at end of line control/loops.rb: # 1| [Program] Program # 2| 0: [Assignment] Assignment diff --git a/ruby/ql/test/library-tests/ast/ValueText.expected b/ruby/ql/test/library-tests/ast/ValueText.expected index 283eef73d25..c2204cf60d4 100644 --- a/ruby/ql/test/library-tests/ast/ValueText.expected +++ b/ruby/ql/test/library-tests/ast/ValueText.expected @@ -336,6 +336,12 @@ exprValue | control/conditionals.rb:62:5:62:5 | c | 0 | int | | control/conditionals.rb:67:8:67:8 | b | 0 | int | | control/conditionals.rb:69:5:69:5 | c | 0 | int | +| control/conditionals.rb:73:9:73:9 | b | 0 | int | +| control/conditionals.rb:74:5:74:5 | c | 0 | int | +| control/conditionals.rb:79:8:79:8 | b | 0 | int | +| control/conditionals.rb:81:5:81:5 | c | 0 | int | +| control/conditionals.rb:86:5:86:5 | b | 0 | int | +| control/conditionals.rb:88:5:88:5 | c | 0 | int | | control/loops.rb:2:7:2:7 | 0 | 0 | int | | control/loops.rb:3:7:3:7 | 0 | 0 | int | | control/loops.rb:4:5:4:5 | 0 | 0 | int | @@ -1257,6 +1263,12 @@ exprCfgNodeValue | control/conditionals.rb:62:5:62:5 | c | 0 | int | | control/conditionals.rb:67:8:67:8 | b | 0 | int | | control/conditionals.rb:69:5:69:5 | c | 0 | int | +| control/conditionals.rb:73:9:73:9 | b | 0 | int | +| control/conditionals.rb:74:5:74:5 | c | 0 | int | +| control/conditionals.rb:79:8:79:8 | b | 0 | int | +| control/conditionals.rb:81:5:81:5 | c | 0 | int | +| control/conditionals.rb:86:5:86:5 | b | 0 | int | +| control/conditionals.rb:88:5:88:5 | c | 0 | int | | control/loops.rb:2:7:2:7 | 0 | 0 | int | | control/loops.rb:3:7:3:7 | 0 | 0 | int | | control/loops.rb:4:5:4:5 | 0 | 0 | int | diff --git a/ruby/ql/test/library-tests/ast/control/ConditionalExpr.expected b/ruby/ql/test/library-tests/ast/control/ConditionalExpr.expected index db7cd1957fb..f9b619c2ea0 100644 --- a/ruby/ql/test/library-tests/ast/control/ConditionalExpr.expected +++ b/ruby/ql/test/library-tests/ast/control/ConditionalExpr.expected @@ -22,6 +22,9 @@ conditionalExprs | conditionals.rb:61:1:64:3 | if ... | IfExpr | conditionals.rb:61:4:61:8 | ... > ... | conditionals.rb:63:1:63:4 | else ... | false | | conditionals.rb:67:1:70:3 | if ... | IfExpr | conditionals.rb:67:4:67:8 | ... > ... | conditionals.rb:67:10:67:13 | then ... | true | | conditionals.rb:67:1:70:3 | if ... | IfExpr | conditionals.rb:67:4:67:8 | ... > ... | conditionals.rb:68:1:69:5 | else ... | false | +| conditionals.rb:73:1:75:3 | if ... | IfExpr | conditionals.rb:73:4:73:9 | ... && ... | conditionals.rb:73:11:74:5 | then ... | true | +| conditionals.rb:78:1:82:3 | if ... | IfExpr | conditionals.rb:78:4:79:8 | ... && ... | conditionals.rb:79:9:81:5 | then ... | true | +| conditionals.rb:85:1:89:3 | if ... | IfExpr | conditionals.rb:85:4:86:5 | ... && ... | conditionals.rb:86:6:88:5 | then ... | true | | loops.rb:9:5:9:5 | if ... | IfExpr | loops.rb:9:5:9:5 | ! ... | loops.rb:9:5:9:5 | ... = ... | true | | loops.rb:16:5:16:5 | if ... | IfExpr | loops.rb:16:5:16:5 | ! ... | loops.rb:16:5:16:5 | ... = ... | true | | loops.rb:22:5:22:7 | if ... | IfExpr | loops.rb:22:5:22:7 | ! ... | loops.rb:22:5:22:7 | ... = ... | true | @@ -38,6 +41,9 @@ ifExprs | conditionals.rb:35:1:36:5 | elsif ... | IfExpr | conditionals.rb:35:7:35:12 | ... == ... | conditionals.rb:35:13:36:5 | then ... | (none) | true | | conditionals.rb:61:1:64:3 | if ... | IfExpr | conditionals.rb:61:4:61:8 | ... > ... | conditionals.rb:61:10:62:5 | then ... | else ... | false | | conditionals.rb:67:1:70:3 | if ... | IfExpr | conditionals.rb:67:4:67:8 | ... > ... | conditionals.rb:67:10:67:13 | then ... | else ... | false | +| conditionals.rb:73:1:75:3 | if ... | IfExpr | conditionals.rb:73:4:73:9 | ... && ... | conditionals.rb:73:11:74:5 | then ... | (none) | false | +| conditionals.rb:78:1:82:3 | if ... | IfExpr | conditionals.rb:78:4:79:8 | ... && ... | conditionals.rb:79:9:81:5 | then ... | (none) | false | +| conditionals.rb:85:1:89:3 | if ... | IfExpr | conditionals.rb:85:4:86:5 | ... && ... | conditionals.rb:86:6:88:5 | then ... | (none) | false | unlessExprs | conditionals.rb:40:1:42:3 | unless ... | UnlessExpr | conditionals.rb:40:8:40:12 | ... > ... | conditionals.rb:40:14:41:5 | then ... | (none) | | conditionals.rb:45:1:49:3 | unless ... | UnlessExpr | conditionals.rb:45:8:45:13 | ... == ... | conditionals.rb:45:14:46:5 | then ... | else ... | diff --git a/ruby/ql/test/library-tests/ast/control/ControlExpr.expected b/ruby/ql/test/library-tests/ast/control/ControlExpr.expected index aaa72ac8027..726c9be5c90 100644 --- a/ruby/ql/test/library-tests/ast/control/ControlExpr.expected +++ b/ruby/ql/test/library-tests/ast/control/ControlExpr.expected @@ -28,6 +28,9 @@ | conditionals.rb:58:5:58:25 | ... ? ... : ... | TernaryIfExpr | | conditionals.rb:61:1:64:3 | if ... | IfExpr | | conditionals.rb:67:1:70:3 | if ... | IfExpr | +| conditionals.rb:73:1:75:3 | if ... | IfExpr | +| conditionals.rb:78:1:82:3 | if ... | IfExpr | +| conditionals.rb:85:1:89:3 | if ... | IfExpr | | loops.rb:9:1:12:3 | for ... in ... | ForExpr | | loops.rb:9:5:9:5 | if ... | IfExpr | | loops.rb:16:1:19:3 | for ... in ... | ForExpr | diff --git a/ruby/ql/test/library-tests/ast/control/conditionals.rb b/ruby/ql/test/library-tests/ast/control/conditionals.rb index 85e008f5c1d..9e3494a2709 100644 --- a/ruby/ql/test/library-tests/ast/control/conditionals.rb +++ b/ruby/ql/test/library-tests/ast/control/conditionals.rb @@ -67,4 +67,23 @@ end if a > b then else c +end + +# If expr with && on same line as condition and then +if a && b then + c +end + +# If expr with && at the start of a separate line before then +if a + && b +then + c +end + +# If expr with && at end of line +if a && + b +then + c end \ No newline at end of file