Ejemplo n.º 1
0
func TestAddIncl(t *testing.T) {
	n := fs.NewDir("")
	sources := []string{
		"a/\n\tb/\n\t\tc\n",
		"a/\n\tb/\n\t\td\n",
		"a/\n\te/\n\t\tf\n",
	}
	expect := fs.NewDir("",
		fs.NewDir("a",
			fs.NewDir("b",
				fs.NewFile("c"),
				fs.NewFile("d"),
			),
			fs.NewDir("e",
				fs.NewFile("f"),
			),
		),
	)

	for _, source := range sources {
		if err := addIncl(n, strings.NewReader(source)); err != nil {
			t.Errorf("Failed: %v", err)
		}
	}

	if !equal(n, expect) {
		t.Errorf("Expected:\n%s\nGot:\n%s", expect.String(), n.String())
	}
}
Ejemplo n.º 2
0
func parseIncl(reader io.Reader) (*fs.Node, error) {
	n := fs.NewDir("")
	if err := addIncl(n, reader); err != nil {
		return nil, err
	}
	return n, nil
}
Ejemplo n.º 3
0
Archivo: gen.go Proyecto: eZanmoto/Bake
// GenTo generates the project p to dest.
func (p *Project) GenTo(dest string) error {
	templPath, err := env.TemplatesPath()
	if err != nil {
		return err
	}

	langRoot := path.Join(templPath, p.lang)

	filePaths := joinAll(langRoot, append(p.types, baseInclFile))
	incls, err := ParseInclFiles(filePaths...)
	if err != nil {
		return err
	}
	root := fs.NewDir("{ProjectName}", incls.Children()...)

	return p.genDirConts(fs.NewDir("").AddNode(root), langRoot, "")
}
Ejemplo n.º 4
0
// Return a filesystem description composed of files described by each include
// file in `paths`.
func ParseInclFiles(paths ...string) (*fs.Node, error) {
	root := fs.NewDir("")

	for _, path := range paths {
		file, err := os.OpenFile(path, os.O_RDONLY, 0666)
		if err != nil {
			return nil, err
		}
		defer file.Close()

		in := bufio.NewReader(file)

		// Skip description
		if _, err = in.ReadString('\n'); err != nil {
			return nil, err
		}

		if err = addIncl(root, in); err != nil {
			return nil, err
		}
	}

	return root, nil
}
Ejemplo n.º 5
0
import (
	"fs"
	"io"
	"strings"
	"testing"
)

type inclTest struct {
	source   string
	expected *fs.Node
}

var (
	inclTests = []inclTest{
		{"",
			fs.NewDir(""),
		},

		{"" +
			"a",
			fs.NewDir("",
				fs.NewFile("a"),
			),
		},

		{"" +
			"a\n",
			fs.NewDir("",
				fs.NewFile("a"),
			),
		},