func TestSchemaPrinter_PrintsMinimalAST(t *testing.T) {
	astDoc := ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
		Name: ast.NewName(&ast.Name{
			Value: "foo",
		}),
	})
	results := printer.Print(astDoc)
	expected := "scalar foo"
	if !reflect.DeepEqual(results, expected) {
		t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, results))
	}
}
Exemplo n.º 2
0
func parseScalarTypeDefinition(parser *Parser) (*ast.ScalarTypeDefinition, error) {
	start := parser.Token.Start
	_, err := expectKeyWord(parser, "scalar")
	if err != nil {
		return nil, err
	}
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	def := ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
		Name: name,
		Loc:  loc(parser, start),
	})
	return def, nil
}
func TestSchemaParser_Scalar(t *testing.T) {
	body := `scalar Hello`
	astDoc := parse(t, body)
	expected := ast.NewDocument(&ast.Document{
		Loc: loc(0, 12),
		Definitions: []ast.Node{
			ast.NewScalarTypeDefinition(&ast.ScalarTypeDefinition{
				Loc: loc(0, 12),
				Name: ast.NewName(&ast.Name{
					Value: "Hello",
					Loc:   loc(7, 12),
				}),
			}),
		},
	})
	if !reflect.DeepEqual(astDoc, expected) {
		t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc)
	}
}