Add codegen test too

This commit is contained in:
Erik Arvidsson
2016-01-20 14:03:49 -08:00
parent 4482eed74c
commit c6ce02b285

View File

@@ -244,3 +244,37 @@ func TestMakeGoIdentifier(t *testing.T) {
assert.Equal("he_llo", makeGoIdentifier("he\u2318llo"))
}
func TestCanUseDefFromImport(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
dir, err := ioutil.TempDir("", "")
assert.NoError(err)
defer os.RemoveAll(dir)
byPathNomDL := filepath.Join(dir, "filedep.noms")
err = ioutil.WriteFile(byPathNomDL, []byte("struct FromFile{i:Int8}"), 0600)
assert.NoError(err)
r1 := strings.NewReader(`
struct A {
B: B
}
struct B {
X: Int64
}`)
pkg1 := pkg.ParseNomDL("test1", r1, dir, cs)
pkgRef1 := types.WriteValue(pkg1.Package, cs)
r2 := strings.NewReader(fmt.Sprintf(`
alias Other = import "%s"
struct C {
C: Map<Int64, Other.A>
}
`, pkgRef1))
pkg2 := pkg.ParseNomDL("test2", r2, dir, cs)
gen2 := newCodeGen(nil, "test2", map[string]bool{}, depsMap{pkg1.Ref(): pkg1.Package}, pkg2)
assert.True(gen2.canUseDef(pkg2.Types()[0], gen2.pkg.Package))
}