(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestMatchParser_SimplePatterns(t *testing.T) { |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | input string |
| 15 | wantArms int |
| 16 | wantPattern string |
| 17 | wantBody string |
| 18 | }{ |
| 19 | { |
| 20 | name: "wildcard pattern", |
| 21 | input: "match x { _ => 0 }", |
| 22 | wantArms: 1, |
| 23 | wantPattern: "_", |
| 24 | wantBody: "0", |
| 25 | }, |
| 26 | { |
| 27 | name: "variable pattern", |
| 28 | input: "match x { value => value }", |
| 29 | wantArms: 1, |
| 30 | wantPattern: "value", |
| 31 | wantBody: "value", |
| 32 | }, |
| 33 | { |
| 34 | name: "int literal pattern", |
| 35 | input: "match x { 42 => \"answer\" }", |
| 36 | wantArms: 1, |
| 37 | wantPattern: "42", |
| 38 | wantBody: `"answer"`, |
| 39 | }, |
| 40 | { |
| 41 | name: "string literal pattern", |
| 42 | input: `match x { "hello" => 1 }`, |
| 43 | wantArms: 1, |
| 44 | wantPattern: `"hello"`, |
| 45 | wantBody: "1", |
| 46 | }, |
| 47 | { |
| 48 | name: "simple constructor Ok", |
| 49 | input: "match result { Ok(x) => x }", |
| 50 | wantArms: 1, |
| 51 | wantPattern: "Ok(x)", |
| 52 | wantBody: "x", |
| 53 | }, |
| 54 | { |
| 55 | name: "simple constructor Err", |
| 56 | input: "match result { Err(e) => e }", |
| 57 | wantArms: 1, |
| 58 | wantPattern: "Err(e)", |
| 59 | wantBody: "e", |
| 60 | }, |
| 61 | { |
| 62 | name: "nullary constructor None", |
| 63 | input: "match opt { None => 0 }", |
| 64 | wantArms: 1, |
| 65 | wantPattern: "None", |
| 66 | wantBody: "0", |
| 67 | }, |
| 68 | } |
nothing calls this directly
no test coverage detected