package dragon

import (
	"bytes"
	"strings"
	"testing"
)

func TestOut(t *testing.T) {
	libChan := make(chan lib)

	go func() {
		libChan <- lib{
			pkg:    "dragon",
			object: "Imports",
			path:   "github.com/monochromegane/dragon-imports",
		}
		close(libChan)
	}()

	expect := `// AUTO-GENERATED BY dragon-imports

package imports

var stdlib = map[string]map[string]bool{`

	buf := &bytes.Buffer{}
	out(libChan, buf)

	actual := buf.String()
	if !strings.HasPrefix(actual, expect) {
		t.Errorf("out should have prefix\n%s\n  but\n%s", expect, actual)
	}

	contains := []string{
		`"github.com/monochromegane/dragon-imports":map[string]bool{"Imports":true}`,
		`"unsafe":map[string]bool{`,
	}

	for _, s := range contains {
		if !strings.Contains(actual, s) {
			t.Errorf("out should contain \n%s\n  but\n%s", s, actual)
		}
	}
}

package dragon

import (
	"bytes"
	"strings"
	"testing"
)

func TestOut(t *testing.T) {
	libChan := make(chan lib)

	go func() {
		libChan <- lib{
			object: "Imports",
			path:   "github.com/monochromegane/dragon-imports",
		}
		libChan <- lib{
			object: "Imports",
			path:   "github.com/someone/dragon-imports",
		}
		close(libChan)
	}()

	expect := `// AUTO-GENERATED BY dragon-imports

package imports

var stdlib = map[string]map[string]bool{`

	buf := &bytes.Buffer{}
	out(libChan, buf)

	actual := buf.String()
	if !strings.HasPrefix(actual, expect) {
		t.Errorf("out should have prefix\n%s\n  but\n%s", expect, actual)
	}

	contains := []string{
		`"github.com/monochromegane/dragon-imports":map[string]bool{"Imports":true}`,
		`"github.com/someone/dragon-imports":map[string]bool{"Imports":true}`,
		`"unsafe":map[string]bool{`,
	}

	for _, s := range contains {
		if !strings.Contains(actual, s) {
			t.Errorf("out should contain \n%s\n  but\n%s", s, actual)
		}
	}
}

Add duplicated package pattern test.
Add duplicated package pattern test.
