func TestSchemaPrinter_PrintsMinimalAST(t *testing.T) { astDoc := ast.NewScalarDefinition(&ast.ScalarDefinition{ 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)) } }
func parseScalarTypeDefinition(parser *Parser) (*ast.ScalarDefinition, 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.NewScalarDefinition(&ast.ScalarDefinition{ 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: testLoc(0, 12), Definitions: []ast.Node{ ast.NewScalarDefinition(&ast.ScalarDefinition{ Loc: testLoc(0, 12), Name: ast.NewName(&ast.Name{ Value: "Hello", Loc: testLoc(7, 12), }), }), }, }) if !reflect.DeepEqual(astDoc, expected) { t.Fatalf("unexpected document, expected: %v, got: %v", expected, astDoc) } }