|
| 1 | +package pmy |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +// TestIsApplicable tests if applicability of |
| 6 | +// snippet is correctly works |
| 7 | +func TestIsApplicable(t *testing.T) { |
| 8 | + testcases := []struct { |
| 9 | + description string |
| 10 | + path string |
| 11 | + basename string |
| 12 | + relpath string |
| 13 | + givenRelpath string |
| 14 | + expectedRes bool |
| 15 | + }{ |
| 16 | + { |
| 17 | + description: "valid pattern", |
| 18 | + path: "./snippets/curl/test.txt", |
| 19 | + basename: "test.txt", |
| 20 | + relpath: "curl/test.txt", |
| 21 | + givenRelpath: "curl/test", |
| 22 | + expectedRes: true, |
| 23 | + }, |
| 24 | + { |
| 25 | + description: "invalid pattern", |
| 26 | + path: "./snippets/curl/test.txt", |
| 27 | + basename: "test.txt", |
| 28 | + relpath: "curl/test.txt", |
| 29 | + givenRelpath: "curl/testhoge", |
| 30 | + expectedRes: false, |
| 31 | + }, |
| 32 | + ////////////////////////////////////////////////// |
| 33 | + // !!!!!!!! TODO: deprecated test !!!!!!!!!! |
| 34 | + ////////////////////////////////////////////////// |
| 35 | + { |
| 36 | + description: "(deprecated) valid pattern", |
| 37 | + path: "./snippets/curl/test_pmy_snippet.txt", |
| 38 | + basename: "test_pmy_snippet.txt", |
| 39 | + relpath: "curl/test_pmy_snippet.txt", |
| 40 | + givenRelpath: "curl/test", |
| 41 | + expectedRes: true, |
| 42 | + }, |
| 43 | + { |
| 44 | + description: "(deprecated) valid pattern", |
| 45 | + path: "./snippets/curl/test_pmy_snippet.txt", |
| 46 | + basename: "test_pmy_snippet.txt", |
| 47 | + relpath: "curl/testhoge_pmy_snippet.txt", |
| 48 | + givenRelpath: "curl/test", |
| 49 | + expectedRes: false, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, testcase := range testcases { |
| 54 | + target := &SnippetFile{ |
| 55 | + Path: testcase.path, |
| 56 | + Basename: testcase.basename, |
| 57 | + Relpath: testcase.relpath, |
| 58 | + } |
| 59 | + res := target.isApplicable(testcase.givenRelpath) |
| 60 | + if !(res == testcase.expectedRes) { |
| 61 | + t.Errorf( |
| 62 | + "test failed (%v): resulting res %v is not equal to %v", |
| 63 | + testcase.description, |
| 64 | + res, |
| 65 | + testcase.expectedRes, |
| 66 | + ) |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments