Ejemplo n.º 1
0
	"github.com/kr/pretty"
	nodes "github.com/lfittl/pg_query_go/nodes"
	"github.com/lfittl/pg_query_go/util"
)

var aExprTests = []struct {
	jsonText     string
	expectedNode nodes.A_Expr
}{
	{
		`{"name": [{"String": {"str": "="}}], "lexpr": null, "rexpr": null}`,
		nodes.A_Expr{
			Kind: nodes.AEXPR_OP,
			Name: util.MakeListNode([]nodes.Node{
				util.MakeStrNode("="),
			}),
			Lexpr: nil,
			Rexpr: nil,
		},
	},
	{
		`{"name": [{"String": {"str": "="}}], "lexpr": {"ColumnRef": {"fields": ` +
			`[{"String": {"str": "z"}}], "location": 22}}, "rexpr": {"A_Const": {"val": ` +
			`{"Integer": {"ival": 1}}, "location": 26}}, "location": 24}`,
		nodes.A_Expr{
			Kind: nodes.AEXPR_OP,
			Name: util.MakeListNode([]nodes.Node{
				util.MakeStrNode("="),
			}),
			Lexpr: nodes.ColumnRef{
Ejemplo n.º 2
0
	input        string
	expectedJSON string
	expectedTree pg_query.ParsetreeList
}{
	{
		"SELECT 1",
		`[{"SelectStmt": {"targetList": [{"ResTarget": {"val": {"A_Const": {"val": ` +
			`{"Integer": {"ival": 1}}, "location": 7}}, "location": 7}}], "op": 0}}]`,
		pg_query.ParsetreeList{
			Statements: []nodes.Node{
				nodes.SelectStmt{
					TargetList: util.MakeListNode([]nodes.Node{
						nodes.ResTarget{
							Val: nodes.A_Const{
								Val:      util.MakeIntNode(1),
								Location: 7,
							},
							Location: 7,
						},
					}),
				},
			},
		},
	},
	{
		"SELECT * FROM x WHERE z = 1",
		`[{"SelectStmt": {"targetList": [{"ResTarget": {"val": {"ColumnRef": {"fields": ` +
			`[{"A_Star": {}}], "location": 7}}, "location": 7}}], "fromClause": [{"RangeVar": ` +
			`{"relname": "x", "inhOpt": 2, "relpersistence": "p", "location": 14}}], "whereClause": ` +
			`{"A_Expr": {"kind": 0, "name": [{"String": {"str": "="}}], "lexpr": {"ColumnRef": ` +
			`{"fields": [{"String": {"str": "z"}}], "location": 22}}, "rexpr": {"A_Const": ` +