Exemple #1
0
func TestFindImports(t *testing.T) {
	deets, err := pimports.Analyze("test/findImports.html")
	if err != nil {
		t.Fatal("Should not have errored with ", err)
	}

	expected := map[string]bool{
		"../bower_components/polymer/polymer.html":       false,
		"../bower_components/paper-menu/paper-menu.html": false,
		"./findCustomTags.html":                          false,
	}

	for _, imp := range deets.Imports {
		_, ok := expected[imp]
		if !ok {
			t.Errorf("Unexpected import %s", imp)
			continue
		}
		expected[imp] = true
	}

	for exp, found := range expected {
		if !found {
			t.Errorf("Did not find %s", exp)
		}
	}
}
Exemple #2
0
func TestFindCustomTags(t *testing.T) {
	deets, err := pimports.Analyze("test/findCustomTags.html")
	if err != nil {
		t.Fatal("Should not have errored with ", err)
	}

	expected := map[string]bool{
		"dom-module":     false,
		"custom-awesome": false,
	}

	for _, tag := range deets.CustomTags {
		_, ok := expected[tag]
		if !ok {
			t.Errorf("Unexpected custom tag %s", tag)
			continue
		}
		expected[tag] = true
	}

	for tag, found := range expected {
		if !found {
			t.Errorf("Did not found %s", tag)
		}
	}
}
Exemple #3
0
func TestFindDeclares(t *testing.T) {
	deets, err := pimports.Analyze("test/findDeclares.html")
	if err != nil {
		t.Fatal("Should not have errored with", err)
	}

	if len(deets.Declares) == 0 {
		t.Fatal("Failed to find element declaration")
	}
	decl := deets.Declares[0]
	if decl != "find-declares" {
		t.Fatalf("Expected to find `find-declares` but found `%s`", decl)
	}
}
Exemple #4
0
func TestNoFileFound(t *testing.T) {
	_, err := pimports.Analyze("fail")
	if err == nil || err.Error() != "Failed to open fail" {
		t.Fatal("Error should have been `Failed to open fail`")
	}
}
Exemple #5
0
func main() {
	then := time.Now()
	defer func() {
		diff := time.Now().Sub(then)
		fmt.Println(diff)
	}()

	flag.Usage = usage
	flag.Parse()

	defconf := &pimports.Config{
		[]string{
			"bower_components/iron-flex-layout/iron-flex-layout.html",
			"bower_components/iron-icons/iron-icons.html",
		},
		[]pimports.Override{
			pimports.Override{"dom-module", "bower_components/polymer/polymer.html"},
		},
		[]string{"bower_components"},
	}

	conf := &pimports.Config{}
	if bts, err := ioutil.ReadFile(".pimports.toml"); err == nil {
		if err := toml.Unmarshal(bts, conf); err != nil {
			fmt.Fprintf(os.Stderr, "Failed to parse config: %+v", err)
			return
		}
	}

	// Defaults (until BurntSushi/toml fixes built in defaults #49)
	if len(conf.Ignores) == 0 {
		conf.Ignores = defconf.Ignores
	}
	if len(conf.Paths) == 0 {
		conf.Paths = defconf.Paths
	}
	if len(conf.Overrides) == 0 {
		conf.Overrides = defconf.Overrides
	}

	if ipaths != nil && len(*ipaths) > 0 {
		conf.Paths = strings.Split(*ipaths, ",")
	}

	if flag.NArg() == 0 {
		fmt.Fprintln(os.Stderr, "must specify a file\n")
		return
	}

	d, err := pimports.Analyze(flag.Arg(0))
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}

	adjust, err := pimports.AssessWithImports(d, conf)
	if err != nil {
		fmt.Fprintf(os.Stdout, err.Error())
		return
	}
	adjust.Print()
}