| 40 columns | |
| >>> logic |
| if (o case 1 || 2 && 3 ) {} |
| <<< |
| if (o case 1 || 2 && 3) {} |
| >>> logic as subpattern |
| if (o case 1 && ( 2 || 3 ) ) {} |
| <<< |
| if (o case 1 && (2 || 3)) {} |
| >>> relational |
| switch (obj) { |
| case == other: |
| case != other: |
| case < other: |
| case <= other: |
| case > other: |
| case >= other: |
| body; |
| } |
| <<< |
| switch (obj) { |
| case == other: |
| case != other: |
| case < other: |
| case <= other: |
| case > other: |
| case >= other: |
| body; |
| } |
| >>> relational as subpattern |
| if (o case > 1 && < 2 && ( == 3 )) {} |
| <<< |
| if (o case > 1 && < 2 && (== 3)) {} |
| >>> cast |
| if (o case 1 as List < int > ? ) {} |
| <<< |
| if (o case 1 as List<int>?) {} |
| >>> null-check |
| if (o case pattern ? ) {} |
| <<< |
| if (o case pattern?) {} |
| >>> null-assert |
| if (o case pattern ! ) {} |
| <<< |
| if (o case pattern!) {} |
| >>> simple constants |
| switch (obj) { |
| case true : |
| case false : |
| case null : |
| case 123 : |
| case 12.34 : |
| case - 123 : |
| case - 12.34 : |
| case 'string' : |
| case 's$tr${ ing }' : |
| case #symbol : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case true: |
| case false: |
| case null: |
| case 123: |
| case 12.34: |
| case -123: |
| case -12.34: |
| case 'string': |
| case 's$tr${ing}': |
| case #symbol: |
| ok; |
| } |
| >>> identifiers |
| switch (obj) { |
| case _ : |
| case name : |
| case qualified . name : |
| case prefixed . qualified . name : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case _: |
| case name: |
| case qualified.name: |
| case prefixed.qualified.name: |
| ok; |
| } |
| >>> variables |
| switch (obj) { |
| case int ? _ : |
| case List < String > name : |
| case var name : |
| case final name : |
| case final ( int , String ) name : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case int? _: |
| case List<String> name: |
| case var name: |
| case final name: |
| case final (int, String) name: |
| ok; |
| } |
| >>> list |
| switch (obj) { |
| case [ ] : |
| case < int > [ ] : |
| case [ _ ] : |
| case [ _ , ] : |
| case [ _ , _ ] : |
| case [ ... ] : |
| case [ ... _ ] : |
| case [ _ , ... ] : |
| case [ ... , _ ] : |
| case [ ... , ] : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case []: |
| case <int>[]: |
| case [_]: |
| case [ |
| _, |
| ]: |
| case [_, _]: |
| case [...]: |
| case [..._]: |
| case [_, ...]: |
| case [..., _]: |
| case [ |
| ..., |
| ]: |
| ok; |
| } |
| >>> map |
| switch (obj) { |
| case { } : |
| case < int , String > { } : |
| case { k : _ } : |
| case { k : _ , } : |
| case { k : 1 , m : 2 } : |
| case { ... } : |
| case { k : _ , ... } : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case {}: |
| case <int, String>{}: |
| case {k: _}: |
| case { |
| k: _, |
| }: |
| case {k: 1, m: 2}: |
| case {...}: |
| case {k: _, ...}: |
| ok; |
| } |
| >>> record |
| switch (obj) { |
| case ( ) : |
| case ( value , ) : |
| case ( first , second , third ) : |
| case ( first : 1 , 2 , third : 3 ) : |
| case ( : var x , : var y ) : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case (): |
| case (value,): |
| case (first, second, third): |
| case (first: 1, 2, third: 3): |
| case (:var x, :var y): |
| ok; |
| } |
| >>> object |
| switch (obj) { |
| case Foo ( ) : |
| case Foo ( getter : pattern ) : |
| case Foo ( getter : pattern , ) : |
| case Foo ( a : 1 , b : 2 , c : 3 ) : |
| case Foo ( : var x , : var y ) : |
| case Foo < int , String > ( : var x , : var y ) : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case Foo(): |
| case Foo(getter: pattern): |
| case Foo( |
| getter: pattern, |
| ): |
| case Foo(a: 1, b: 2, c: 3): |
| case Foo(:var x, :var y): |
| case Foo<int, String>(:var x, :var y): |
| ok; |
| } |
| >>> object |
| switch (obj) { |
| case Foo ( ) : |
| case Foo ( getter : pattern ) : |
| case Foo ( getter : pattern , ) : |
| case Foo ( a : 1 , b : 2 , c : 3 ) : |
| case Foo ( : var x , : var y ) : |
| case Foo < int , String > ( : var x , : var y ) : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case Foo(): |
| case Foo(getter: pattern): |
| case Foo( |
| getter: pattern, |
| ): |
| case Foo(a: 1, b: 2, c: 3): |
| case Foo(:var x, :var y): |
| case Foo<int, String>(:var x, :var y): |
| ok; |
| } |
| >>> constant collections |
| switch (obj) { |
| case const [ ] : |
| case const < int > [ ] : |
| case const [ 1 , 2 ] : |
| case const { } : |
| case const < int > { } : |
| case const { 1 , 2 } : |
| case const < int , String > { } : |
| case const { 1 : 's' , 2 : 't' } : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case const []: |
| case const <int>[]: |
| case const [1, 2]: |
| case const {}: |
| case const <int>{}: |
| case const {1, 2}: |
| case const <int, String>{}: |
| case const {1: 's', 2: 't'}: |
| ok; |
| } |
| >>> constant constructor |
| switch (obj) { |
| case const Foo ( ) : |
| case const Foo ( field , another ) : |
| case const Foo ( field : value ) : |
| case const Foo ( field : value , ) : |
| case const Foo < int , String > ( field ) : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case const Foo(): |
| case const Foo(field, another): |
| case const Foo(field: value): |
| case const Foo( |
| field: value, |
| ): |
| case const Foo<int, String>(field): |
| ok; |
| } |
| >>> parenthesized constant expression |
| switch (obj) { |
| case const ( 1 ) : |
| case const ( - foo * bar ) : |
| ok; |
| } |
| <<< |
| switch (obj) { |
| case const (1): |
| case const (-foo * bar): |
| ok; |
| } |