Exemplo n.º 1
0
func TestSchemaParser_DoubleValueEnum(t *testing.T) {
	body := `enum Hello { WO, RLD }`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: testLoc(0, 22),
		Definitions: []ast.Node{
			ast.NewEnumDefinition(&ast.EnumDefinition{
				Loc: testLoc(0, 22),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   testLoc(5, 10),
				}),
				Values: []*ast.EnumValueDefinition{
					ast.NewEnumValueDefinition(&ast.EnumValueDefinition{
						Name: ast.NewName(&ast.Name{
							Value: "WO",
							Loc:   testLoc(13, 15),
						}),
						Loc: testLoc(13, 15),
					}),
					ast.NewEnumValueDefinition(&ast.EnumValueDefinition{
						Name: ast.NewName(&ast.Name{
							Value: "RLD",
							Loc:   testLoc(17, 20),
						}),
						Loc: testLoc(17, 20),
					}),
				},
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}
Exemplo n.º 2
0
func parseEnumValueDefinition(parser *Parser) (interface{}, error) {
	start := parser.Token.Start
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	return ast.NewEnumValueDefinition(&ast.EnumValueDefinition{
		Name: name,
		Loc:  loc(parser, start),
	}), nil
}