//! > Test +=, -=, *=, /=, %=
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: false)
//! > cairo_code
fn foo() {
let mut x = 3;
x += 5;
x -= 5;
x *= 5;
x /= 5;
x %= 5;
x = 5;
}
//! > top_level_kind
StatementList
//! > ignored_kinds
StatementLet
//! > expected_diagnostics
//! > expected_tree
└── Top level kind: StatementList
├── child #0 (kind: StatementLet) <ignored>
├── child #1 (kind: StatementExpr)
│ ├── attributes (kind: AttributeList) []
│ ├── expr (kind: ExprBinary)
│ │ ├── lhs (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'x'
│ │ ├── op (kind: TokenPlusEq): '+='
│ │ └── rhs (kind: TokenLiteralNumber): '5'
│ └── semicolon (kind: TokenSemicolon): ';'
├── child #2 (kind: StatementExpr)
│ ├── attributes (kind: AttributeList) []
│ ├── expr (kind: ExprBinary)
│ │ ├── lhs (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'x'
│ │ ├── op (kind: TokenMinusEq): '-='
│ │ └── rhs (kind: TokenLiteralNumber): '5'
│ └── semicolon (kind: TokenSemicolon): ';'
├── child #3 (kind: StatementExpr)
│ ├── attributes (kind: AttributeList) []
│ ├── expr (kind: ExprBinary)
│ │ ├── lhs (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'x'
│ │ ├── op (kind: TokenMulEq): '*='
│ │ └── rhs (kind: TokenLiteralNumber): '5'
│ └── semicolon (kind: TokenSemicolon): ';'
├── child #4 (kind: StatementExpr)
│ ├── attributes (kind: AttributeList) []
│ ├── expr (kind: ExprBinary)
│ │ ├── lhs (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'x'
│ │ ├── op (kind: TokenDivEq): '/='
│ │ └── rhs (kind: TokenLiteralNumber): '5'
│ └── semicolon (kind: TokenSemicolon): ';'
├── child #5 (kind: StatementExpr)
│ ├── attributes (kind: AttributeList) []
│ ├── expr (kind: ExprBinary)
│ │ ├── lhs (kind: ExprPath)
│ │ │ └── item #0 (kind: PathSegmentSimple)
│ │ │ └── ident (kind: TokenIdentifier): 'x'
│ │ ├── op (kind: TokenModEq): '%='
│ │ └── rhs (kind: TokenLiteralNumber): '5'
│ └── semicolon (kind: TokenSemicolon): ';'
└── child #6 (kind: StatementExpr)
├── attributes (kind: AttributeList) []
├── expr (kind: ExprBinary)
│ ├── lhs (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'x'
│ ├── op (kind: TokenEq): '='
│ └── rhs (kind: TokenLiteralNumber): '5'
└── semicolon (kind: TokenSemicolon): ';'
//! > ==========================================================================
//! > Test error of `+=` with `let`.
//! > test_runner_name
test_partial_parser_tree(expect_diagnostics: true)
//! > cairo_code
fn foo() {
let x += 5;
}
//! > top_level_kind
StatementList
//! > ignored_kinds
//! > expected_diagnostics
error: Missing token TerminalEq.
--> dummy_file.cairo:2:10
let x += 5;
^
error: Missing tokens. Expected an expression.
--> dummy_file.cairo:2:10
let x += 5;
^
error: Missing token TerminalSemicolon.
--> dummy_file.cairo:2:10
let x += 5;
^
error: Skipped tokens. Expected: statement.
--> dummy_file.cairo:2:11
let x += 5;
^^
//! > expected_tree
└── Top level kind: StatementList
├── child #0 (kind: StatementLet)
│ ├── attributes (kind: AttributeList) []
│ ├── let_kw (kind: TokenLet): 'let'
│ ├── pattern (kind: ExprPath)
│ │ └── item #0 (kind: PathSegmentSimple)
│ │ └── ident (kind: TokenIdentifier): 'x'
│ ├── type_clause (kind: OptionTypeClauseEmpty) []
│ ├── eq: Missing
│ ├── rhs: Missing []
│ └── semicolon: Missing
└── child #1 (kind: StatementExpr)
├── attributes (kind: AttributeList) []
├── expr (kind: TokenLiteralNumber): '5'
└── semicolon (kind: TokenSemicolon): ';'