(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestAST_ExtractAnnotations(t *testing.T) { |
| 10 | sqlVariations := []struct { |
| 11 | title string |
| 12 | sql string |
| 13 | annotations map[string]string |
| 14 | }{ |
| 15 | { |
| 16 | "comments at the top", |
| 17 | ` |
| 18 | -- some random comment |
| 19 | -- @materialise_v1 |
| 20 | -- @materialise_v2 : true |
| 21 | -- @materialise_v3 : tr ue |
| 22 | -- some other comment |
| 23 | select * from AdBids |
| 24 | `, |
| 25 | map[string]string{ |
| 26 | "materialise_v1": "", |
| 27 | "materialise_v2": "true", |
| 28 | "materialise_v3": "tr ue", |
| 29 | }, |
| 30 | }, |
| 31 | { |
| 32 | "comments in the middle", |
| 33 | ` |
| 34 | select |
| 35 | -- @measure: avg |
| 36 | -- @measure.format: usd |
| 37 | a, |
| 38 | -- @dimension |
| 39 | b |
| 40 | from AdBids |
| 41 | `, |
| 42 | map[string]string{ |
| 43 | "measure": "avg", |
| 44 | "measure.format": "usd", |
| 45 | "dimension": "", |
| 46 | }, |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | for _, tt := range sqlVariations { |
| 51 | t.Run(tt.title, func(t *testing.T) { |
| 52 | require.EqualValues(t, tt.annotations, ExtractAnnotations(tt.sql)) |
| 53 | }) |
| 54 | } |
| 55 | } |
nothing calls this directly
no test coverage detected