Source file src/cmd/fix/egltype_test.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "strings"
     8  
     9  func init() {
    10  	addTestCases(eglTestsFor("EGLDisplay"), eglfixDisp)
    11  	addTestCases(eglTestsFor("EGLConfig"), eglfixConfig)
    12  }
    13  
    14  func eglTestsFor(tname string) []testCase {
    15  	var eglTests = []testCase{
    16  		{
    17  			Name: "egl.localVariable",
    18  			In: `package main
    19  
    20  import "C"
    21  
    22  func f() {
    23  	var x C.$EGLTYPE = nil
    24  	x = nil
    25  	x, x = nil, nil
    26  }
    27  `,
    28  			Out: `package main
    29  
    30  import "C"
    31  
    32  func f() {
    33  	var x C.$EGLTYPE = 0
    34  	x = 0
    35  	x, x = 0, 0
    36  }
    37  `,
    38  		},
    39  		{
    40  			Name: "egl.globalVariable",
    41  			In: `package main
    42  
    43  import "C"
    44  
    45  var x C.$EGLTYPE = nil
    46  
    47  func f() {
    48  	x = nil
    49  }
    50  `,
    51  			Out: `package main
    52  
    53  import "C"
    54  
    55  var x C.$EGLTYPE = 0
    56  
    57  func f() {
    58  	x = 0
    59  }
    60  `,
    61  		},
    62  		{
    63  			Name: "egl.EqualArgument",
    64  			In: `package main
    65  
    66  import "C"
    67  
    68  var x C.$EGLTYPE
    69  var y = x == nil
    70  var z = x != nil
    71  `,
    72  			Out: `package main
    73  
    74  import "C"
    75  
    76  var x C.$EGLTYPE
    77  var y = x == 0
    78  var z = x != 0
    79  `,
    80  		},
    81  		{
    82  			Name: "egl.StructField",
    83  			In: `package main
    84  
    85  import "C"
    86  
    87  type T struct {
    88  	x C.$EGLTYPE
    89  }
    90  
    91  var t = T{x: nil}
    92  `,
    93  			Out: `package main
    94  
    95  import "C"
    96  
    97  type T struct {
    98  	x C.$EGLTYPE
    99  }
   100  
   101  var t = T{x: 0}
   102  `,
   103  		},
   104  		{
   105  			Name: "egl.FunctionArgument",
   106  			In: `package main
   107  
   108  import "C"
   109  
   110  func f(x C.$EGLTYPE) {
   111  }
   112  
   113  func g() {
   114  	f(nil)
   115  }
   116  `,
   117  			Out: `package main
   118  
   119  import "C"
   120  
   121  func f(x C.$EGLTYPE) {
   122  }
   123  
   124  func g() {
   125  	f(0)
   126  }
   127  `,
   128  		},
   129  		{
   130  			Name: "egl.ArrayElement",
   131  			In: `package main
   132  
   133  import "C"
   134  
   135  var x = [3]C.$EGLTYPE{nil, nil, nil}
   136  `,
   137  			Out: `package main
   138  
   139  import "C"
   140  
   141  var x = [3]C.$EGLTYPE{0, 0, 0}
   142  `,
   143  		},
   144  		{
   145  			Name: "egl.SliceElement",
   146  			In: `package main
   147  
   148  import "C"
   149  
   150  var x = []C.$EGLTYPE{nil, nil, nil}
   151  `,
   152  			Out: `package main
   153  
   154  import "C"
   155  
   156  var x = []C.$EGLTYPE{0, 0, 0}
   157  `,
   158  		},
   159  		{
   160  			Name: "egl.MapKey",
   161  			In: `package main
   162  
   163  import "C"
   164  
   165  var x = map[C.$EGLTYPE]int{nil: 0}
   166  `,
   167  			Out: `package main
   168  
   169  import "C"
   170  
   171  var x = map[C.$EGLTYPE]int{0: 0}
   172  `,
   173  		},
   174  		{
   175  			Name: "egl.MapValue",
   176  			In: `package main
   177  
   178  import "C"
   179  
   180  var x = map[int]C.$EGLTYPE{0: nil}
   181  `,
   182  			Out: `package main
   183  
   184  import "C"
   185  
   186  var x = map[int]C.$EGLTYPE{0: 0}
   187  `,
   188  		},
   189  	}
   190  	for i := range eglTests {
   191  		t := &eglTests[i]
   192  		t.In = strings.ReplaceAll(t.In, "$EGLTYPE", tname)
   193  		t.Out = strings.ReplaceAll(t.Out, "$EGLTYPE", tname)
   194  	}
   195  	return eglTests
   196  }
   197  

View as plain text