github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/bug296.go (about)

     1  // run
     2  
     3  // Copyright 2010 The Go Authors.  All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  type I interface {
    10  	m(a, b, c, d, e, f, g, h byte)
    11  }
    12  
    13  type Int8 int8
    14  
    15  func (x Int8) m(a, b, c, d, e, f, g, h byte) {
    16  	check("Int8", int64(x), 0x01, a, b, c, d, e, f, g, h)
    17  }
    18  
    19  type Uint8 uint8
    20  
    21  func (x Uint8) m(a, b, c, d, e, f, g, h byte) {
    22  	check("Uint8", int64(x), 0x01, a, b, c, d, e, f, g, h)
    23  }
    24  
    25  type Int16 int16
    26  
    27  func (x Int16) m(a, b, c, d, e, f, g, h byte) {
    28  	check("Int16", int64(x), 0x0102, a, b, c, d, e, f, g, h)
    29  }
    30  
    31  type Uint16 uint16
    32  
    33  func (x Uint16) m(a, b, c, d, e, f, g, h byte) {
    34  	check("Uint16", int64(x), 0x0102, a, b, c, d, e, f, g, h)
    35  }
    36  
    37  type Int32 int32
    38  
    39  func (x Int32) m(a, b, c, d, e, f, g, h byte) {
    40  	check("Int32", int64(x), 0x01020304, a, b, c, d, e, f, g, h)
    41  }
    42  
    43  type Uint32 uint32
    44  
    45  func (x Uint32) m(a, b, c, d, e, f, g, h byte) {
    46  	check("Uint32", int64(x), 0x01020304, a, b, c, d, e, f, g, h)
    47  }
    48  
    49  type Int64 int64
    50  
    51  func (x Int64) m(a, b, c, d, e, f, g, h byte) {
    52  	check("Int64", int64(x), 0x0102030405060708, a, b, c, d, e, f, g, h)
    53  }
    54  
    55  type Uint64 uint64
    56  
    57  func (x Uint64) m(a, b, c, d, e, f, g, h byte) {
    58  	check("Uint64", int64(x), 0x0102030405060708, a, b, c, d, e, f, g, h)
    59  }
    60  
    61  var test = []I{
    62  	Int8(0x01),
    63  	Uint8(0x01),
    64  	Int16(0x0102),
    65  	Uint16(0x0102),
    66  	Int32(0x01020304),
    67  	Uint32(0x01020304),
    68  	Int64(0x0102030405060708),
    69  	Uint64(0x0102030405060708),
    70  }
    71  
    72  func main() {
    73  	for _, t := range test {
    74  		t.m(0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17)
    75  	}
    76  }
    77  
    78  var bug = false
    79  
    80  func check(desc string, have, want int64, a, b, c, d, e, f, g, h byte) {
    81  	if have != want || a != 0x10 || b != 0x11 || c != 0x12 || d != 0x13 || e != 0x14 || f != 0x15 || g != 0x16 || h != 0x17 {
    82  		if !bug {
    83  			bug = true
    84  			println("BUG")
    85  		}
    86  		println(desc, "check", have, want, a, b, c, d, e, f, g, h)
    87  	}
    88  }