Skip to content

Commit

Permalink
Added code simplification to gofmt (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin8105 authored and elliotchance committed Dec 5, 2017
1 parent 6247097 commit 88fe73d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions ast/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,84 @@ import (

func TestNewPositionFromString(t *testing.T) {
tests := map[string]Position{
`col:30`: Position{
`col:30`: {
File: "",
Line: 0,
Column: 30,
LineEnd: 0,
ColumnEnd: 0,
},
`col:47, col:57`: Position{
`col:47, col:57`: {
File: "",
Line: 0,
Column: 47,
LineEnd: 0,
ColumnEnd: 57,
},
`/usr/include/sys/cdefs.h:313:68`: Position{
`/usr/include/sys/cdefs.h:313:68`: {
File: "/usr/include/sys/cdefs.h",
Line: 313,
Column: 68,
LineEnd: 0,
ColumnEnd: 0,
},
`/usr/include/AvailabilityInternal.h:21697:88, col:124`: Position{
`/usr/include/AvailabilityInternal.h:21697:88, col:124`: {
File: "/usr/include/AvailabilityInternal.h",
Line: 21697,
Column: 88,
LineEnd: 0,
ColumnEnd: 124,
},
`line:275:50, col:99`: Position{
`line:275:50, col:99`: {
File: "",
Line: 275,
Column: 50,
LineEnd: 0,
ColumnEnd: 99,
},
`line:11:5, line:12:21`: Position{
`line:11:5, line:12:21`: {
File: "",
Line: 11,
Column: 5,
LineEnd: 12,
ColumnEnd: 21,
},
`col:54, line:358:1`: Position{
`col:54, line:358:1`: {
File: "",
Line: 0,
Column: 54,
LineEnd: 358,
ColumnEnd: 1,
},
`/usr/include/secure/_stdio.h:42:1, line:43:32`: Position{
`/usr/include/secure/_stdio.h:42:1, line:43:32`: {
File: "/usr/include/secure/_stdio.h",
Line: 42,
Column: 1,
LineEnd: 43,
ColumnEnd: 32,
},
`line:244:5`: Position{
`line:244:5`: {
File: "",
Line: 244,
Column: 5,
LineEnd: 0,
ColumnEnd: 0,
},
`<invalid sloc>`: Position{
`<invalid sloc>`: {
File: "",
Line: 0,
Column: 0,
LineEnd: 0,
ColumnEnd: 0,
},
`/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126`: Position{
`/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126`: {
File: "/usr/include/sys/stdio.h",
Line: 39,
Column: 1,
LineEnd: 0,
ColumnEnd: 0,
},
`col:1, /usr/include/sys/cdefs.h:351:63`: Position{
`col:1, /usr/include/sys/cdefs.h:351:63`: {
File: "",
Line: 0,
Column: 1,
Expand Down
8 changes: 4 additions & 4 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ func setupTest(args []string) (*bytes.Buffer, func()) {

var cliTests = map[string][]string{
// Test that help is printed if no files are given
"TranspileNoFilesHelp": []string{"test", "transpile"},
"TranspileNoFilesHelp": {"test", "transpile"},

// Test that help is printed if help flag is set, even if file is given
"TranspileHelpFlag": []string{"test", "transpile", "-h", "foo.c"},
"TranspileHelpFlag": {"test", "transpile", "-h", "foo.c"},

// Test that help is printed if no files are given
"AstNoFilesHelp": []string{"test", "ast"},
"AstNoFilesHelp": {"test", "ast"},

// Test that help is printed if help flag is set, even if file is given
"AstHelpFlag": []string{"test", "ast", "-h", "foo.c"},
"AstHelpFlag": {"test", "ast", "-h", "foo.c"},
}

func TestCLI(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ func NewProgram() *Program {
// Example node for adding:
// &ast.TypedefDecl{ ... Type:"struct __locale_struct *" ... }

"struct __va_list_tag [1]": &Struct{
"struct __va_list_tag [1]": {
Name: "struct __va_list_tag [1]",
IsUnion: false,
},

// Pos:ast.Position{File:"/usr/include/xlocale.h", Line:27
"struct __locale_struct *": &Struct{
"struct __locale_struct *": {
Name: "struct __locale_struct *",
IsUnion: false,
},

// Pos:ast.Position{File:"/usr/include/x86_64-linux-gnu/sys/time.h", Line:61
"struct timezone *__restrict": &Struct{
"struct timezone *__restrict": {
Name: "struct timezone *__restrict",
IsUnion: false,
},
Expand Down
8 changes: 4 additions & 4 deletions transpiler/declarations.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t
return []goast.Decl{&goast.GenDecl{
Tok: token.VAR,
Specs: []goast.Spec{&goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: name}},
Names: []*goast.Ident{{Name: name}},
Type: util.NewTypeIdent(theType),
}},
}}, "", nil
Expand All @@ -303,7 +303,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t
return []goast.Decl{&goast.GenDecl{
Tok: token.VAR,
Specs: []goast.Spec{&goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: name}},
Names: []*goast.Ident{{Name: name}},
Type: util.NewTypeIdent(theType),
}},
}}, "", nil
Expand Down Expand Up @@ -350,7 +350,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t
return []goast.Decl{&goast.GenDecl{
Tok: token.VAR,
Specs: []goast.Spec{&goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: nameVar1}},
Names: []*goast.Ident{{Name: nameVar1}},
Type: functionType,
Values: []goast.Expr{&goast.TypeAssertExpr{
X: &goast.Ident{Name: nameVar2},
Expand Down Expand Up @@ -378,7 +378,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t
decls = append(decls, &goast.GenDecl{
Tok: token.VAR,
Specs: []goast.Spec{&goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: nameVar1}},
Names: []*goast.Ident{{Name: nameVar1}},
Type: functionType,
},
}})
Expand Down
2 changes: 1 addition & 1 deletion transpiler/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func transpileEnumDecl(p *program.Program, n *ast.EnumDecl) (decls []goast.Decl,
switch v := val.Values[0].(type) {
case *goast.Ident:
e = &goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: c.Name}},
Names: []*goast.Ident{{Name: c.Name}},
Values: []goast.Expr{&goast.BasicLit{Kind: token.INT, Value: strconv.Itoa(counter)}},
Type: val.Type,
}
Expand Down
2 changes: 1 addition & 1 deletion transpiler/transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TranspileAST(fileName, packageName string, p *program.Program, root ast.Nod
Type: &goast.FuncType{
Params: &goast.FieldList{
List: []*goast.Field{
&goast.Field{
{
Names: []*goast.Ident{util.NewIdent("t")},
Type: util.NewTypeIdent("*testing.T"),
},
Expand Down
2 changes: 1 addition & 1 deletion transpiler/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newDeclStmt(a *ast.VarDecl, p *program.Program) (
return &goast.DeclStmt{Decl: &goast.GenDecl{
Tok: token.VAR,
Specs: []goast.Spec{&goast.ValueSpec{
Names: []*goast.Ident{&goast.Ident{Name: nameVar1}},
Names: []*goast.Ident{{Name: nameVar1}},
Type: functionType,
Values: []goast.Expr{&goast.TypeAssertExpr{
X: &goast.Ident{Name: nameVar2},
Expand Down

0 comments on commit 88fe73d

Please sign in to comment.