예제 #1
0
func TestMissing(t *testing.T) {
	det := &pimports.Details{
		"./path.html",
		[]string{},
		[]string{"./match-1.html"},
		[]string{"not-match", "not-match-2", "match-1"},
	}
	res, err := pimports.Assess(det)
	if err != nil {
		t.Fatal(err)
	}

	expected := map[string]bool{
		"not-match":   false,
		"not-match-2": false,
	}

	for _, r := range res.Unimported {
		_, ok := expected[r]
		if !ok {
			t.Errorf("Unexpected error `%s`", r)
			continue
		}
		expected[r] = true
	}

	for exp, found := range expected {
		if !found {
			t.Errorf("Did not get `%s`", exp)
		}
	}
}
예제 #2
0
func TestNotUsed(t *testing.T) {
	det := &pimports.Details{
		"./path.html",
		[]string{},
		[]string{"./not-used.html", "./used/somewhere-here.html", "../also/not/used-anywhere.html"},
		[]string{"somewhere-here"},
	}
	res, err := pimports.Assess(det)
	if err != nil {
		t.Fatal(err)
	}

	expected := map[string]bool{
		"./not-used.html":                false,
		"../also/not/used-anywhere.html": false,
	}

	for _, r := range res.Unused {
		_, ok := expected[r]
		if !ok {
			t.Errorf("Unexpected error `%s`", r)
			continue
		}
		expected[r] = true
	}

	for exp, found := range expected {
		if !found {
			t.Errorf("Did not get `%s`", exp)
		}
	}
}