From 64a122acfdd93d498a79a50c6ddf1887f253a952 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Thu, 16 Nov 2023 15:26:07 +0900 Subject: [PATCH] [ruby/prism] Add test cases for `in` in `case` condition Fix https://github.com/ruby/prism/pull/1515 It is also fixed by #1807, so this adds only test cases. https://github.com/ruby/prism/commit/a0092f075e --- test/prism/fixtures/case.txt | 12 ++++ test/prism/snapshots/case.txt | 108 ++++++++++++++++++++++++++++++---- 2 files changed, 107 insertions(+), 13 deletions(-) diff --git a/test/prism/fixtures/case.txt b/test/prism/fixtures/case.txt index 1b720bc5ac..9db91e8d0f 100644 --- a/test/prism/fixtures/case.txt +++ b/test/prism/fixtures/case.txt @@ -30,3 +30,15 @@ case type; end case ;;;;;;;; when 1; end + +case 1 in 2 +when 3 +end + +case 1 in 2; when 3; end + +case 1 in 2 +in 3 +end + +case 1 in 2; in 3; end diff --git a/test/prism/snapshots/case.txt b/test/prism/snapshots/case.txt index a5f1b9c046..3655ce16e1 100644 --- a/test/prism/snapshots/case.txt +++ b/test/prism/snapshots/case.txt @@ -1,8 +1,8 @@ -@ ProgramNode (location: (1,0)-(32,25)) +@ ProgramNode (location: (1,0)-(44,22)) ├── locals: [] └── statements: - @ StatementsNode (location: (1,0)-(32,25)) - └── body: (length: 9) + @ StatementsNode (location: (1,0)-(44,22)) + └── body: (length: 13) ├── @ CaseNode (location: (1,0)-(3,3)) │ ├── predicate: │ │ @ SymbolNode (location: (1,5)-(1,8)) @@ -254,15 +254,97 @@ │ │ └── end_keyword_loc: (30,3)-(30,6) = "end" │ ├── case_keyword_loc: (27,0)-(27,4) = "case" │ └── end_keyword_loc: (30,3)-(30,6) = "end" - └── @ CaseNode (location: (32,0)-(32,25)) - ├── predicate: ∅ + ├── @ CaseNode (location: (32,0)-(32,25)) + │ ├── predicate: ∅ + │ ├── conditions: (length: 1) + │ │ └── @ WhenNode (location: (32,14)-(32,20)) + │ │ ├── keyword_loc: (32,14)-(32,18) = "when" + │ │ ├── conditions: (length: 1) + │ │ │ └── @ IntegerNode (location: (32,19)-(32,20)) + │ │ │ └── flags: decimal + │ │ └── statements: ∅ + │ ├── consequent: ∅ + │ ├── case_keyword_loc: (32,0)-(32,4) = "case" + │ └── end_keyword_loc: (32,22)-(32,25) = "end" + ├── @ CaseNode (location: (34,0)-(36,3)) + │ ├── predicate: + │ │ @ MatchPredicateNode (location: (34,5)-(34,11)) + │ │ ├── value: + │ │ │ @ IntegerNode (location: (34,5)-(34,6)) + │ │ │ └── flags: decimal + │ │ ├── pattern: + │ │ │ @ IntegerNode (location: (34,10)-(34,11)) + │ │ │ └── flags: decimal + │ │ └── operator_loc: (34,7)-(34,9) = "in" + │ ├── conditions: (length: 1) + │ │ └── @ WhenNode (location: (35,0)-(35,6)) + │ │ ├── keyword_loc: (35,0)-(35,4) = "when" + │ │ ├── conditions: (length: 1) + │ │ │ └── @ IntegerNode (location: (35,5)-(35,6)) + │ │ │ └── flags: decimal + │ │ └── statements: ∅ + │ ├── consequent: ∅ + │ ├── case_keyword_loc: (34,0)-(34,4) = "case" + │ └── end_keyword_loc: (36,0)-(36,3) = "end" + ├── @ CaseNode (location: (38,0)-(38,24)) + │ ├── predicate: + │ │ @ MatchPredicateNode (location: (38,5)-(38,11)) + │ │ ├── value: + │ │ │ @ IntegerNode (location: (38,5)-(38,6)) + │ │ │ └── flags: decimal + │ │ ├── pattern: + │ │ │ @ IntegerNode (location: (38,10)-(38,11)) + │ │ │ └── flags: decimal + │ │ └── operator_loc: (38,7)-(38,9) = "in" + │ ├── conditions: (length: 1) + │ │ └── @ WhenNode (location: (38,13)-(38,19)) + │ │ ├── keyword_loc: (38,13)-(38,17) = "when" + │ │ ├── conditions: (length: 1) + │ │ │ └── @ IntegerNode (location: (38,18)-(38,19)) + │ │ │ └── flags: decimal + │ │ └── statements: ∅ + │ ├── consequent: ∅ + │ ├── case_keyword_loc: (38,0)-(38,4) = "case" + │ └── end_keyword_loc: (38,21)-(38,24) = "end" + ├── @ CaseNode (location: (40,0)-(42,3)) + │ ├── predicate: + │ │ @ MatchPredicateNode (location: (40,5)-(40,11)) + │ │ ├── value: + │ │ │ @ IntegerNode (location: (40,5)-(40,6)) + │ │ │ └── flags: decimal + │ │ ├── pattern: + │ │ │ @ IntegerNode (location: (40,10)-(40,11)) + │ │ │ └── flags: decimal + │ │ └── operator_loc: (40,7)-(40,9) = "in" + │ ├── conditions: (length: 1) + │ │ └── @ InNode (location: (41,0)-(41,4)) + │ │ ├── pattern: + │ │ │ @ IntegerNode (location: (41,3)-(41,4)) + │ │ │ └── flags: decimal + │ │ ├── statements: ∅ + │ │ ├── in_loc: (41,0)-(41,2) = "in" + │ │ └── then_loc: ∅ + │ ├── consequent: ∅ + │ ├── case_keyword_loc: (40,0)-(40,4) = "case" + │ └── end_keyword_loc: (42,0)-(42,3) = "end" + └── @ CaseNode (location: (44,0)-(44,22)) + ├── predicate: + │ @ MatchPredicateNode (location: (44,5)-(44,11)) + │ ├── value: + │ │ @ IntegerNode (location: (44,5)-(44,6)) + │ │ └── flags: decimal + │ ├── pattern: + │ │ @ IntegerNode (location: (44,10)-(44,11)) + │ │ └── flags: decimal + │ └── operator_loc: (44,7)-(44,9) = "in" ├── conditions: (length: 1) - │ └── @ WhenNode (location: (32,14)-(32,20)) - │ ├── keyword_loc: (32,14)-(32,18) = "when" - │ ├── conditions: (length: 1) - │ │ └── @ IntegerNode (location: (32,19)-(32,20)) - │ │ └── flags: decimal - │ └── statements: ∅ + │ └── @ InNode (location: (44,13)-(44,17)) + │ ├── pattern: + │ │ @ IntegerNode (location: (44,16)-(44,17)) + │ │ └── flags: decimal + │ ├── statements: ∅ + │ ├── in_loc: (44,13)-(44,15) = "in" + │ └── then_loc: ∅ ├── consequent: ∅ - ├── case_keyword_loc: (32,0)-(32,4) = "case" - └── end_keyword_loc: (32,22)-(32,25) = "end" + ├── case_keyword_loc: (44,0)-(44,4) = "case" + └── end_keyword_loc: (44,19)-(44,22) = "end"