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 parseEnumTypeDefinition(parser *Parser) (*ast.EnumDefinition, error) {
	start := parser.Token.Start
	_, err := expectKeyWord(parser, "enum")
	if err != nil {
		return nil, err
	}
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	iEnumValueDefs, err := any(parser, lexer.TokenKind[lexer.BRACE_L], parseEnumValueDefinition, lexer.TokenKind[lexer.BRACE_R])
	if err != nil {
		return nil, err
	}
	values := []*ast.EnumValueDefinition{}
	for _, iEnumValueDef := range iEnumValueDefs {
		if iEnumValueDef != nil {
			values = append(values, iEnumValueDef.(*ast.EnumValueDefinition))
		}
	}
	return ast.NewEnumDefinition(&ast.EnumDefinition{
		Name:   name,
		Loc:    loc(parser, start),
		Values: values,
	}), nil
}