Пример #1
0
func main() {
	var file *ast.File
	var err error

	if file, err = json2go.Json2Ast(os.Stdin); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	ast.Print(nil, file)

	printer.Fprint(os.Stdout, token.NewFileSet(), file)
}
Пример #2
0
func (s *Json2AstSuite) TestJson2Ast(c *C) {
	var fset *token.FileSet
	var obtainedAst, expectedAst *ast.File
	var err error

	fset = token.NewFileSet()

	for i, tt := range json2AstTests {
		if expectedAst, err = parser.ParseFile(fset, "", tt.Output, 0); err != nil {
			c.Error(err)
			continue
		}

		if obtainedAst, err = json2go.Json2Ast(bytes.NewBufferString(tt.Input)); err != nil {
			c.Error(err)
			continue
		}

		c.Assert(obtainedAst, AstEquals, expectedAst, Commentf("Test Case %d failed", i))
	}
}