...

Source file src/internal/types/testdata/check/literals.go

Documentation: internal/types/testdata/check

     1  // Copyright 2019 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  // This file tests various representations of literals
     6  // and compares them with literals or constant expressions
     7  // of equal values.
     8  
     9  package literals
    10  
    11  func _() {
    12  	// 0-octals
    13  	assert(0_123 == 0123)
    14  	assert(0123_456 == 0123456)
    15  
    16  	// decimals
    17  	assert(1_234 == 1234)
    18  	assert(1_234_567 == 1234567)
    19  
    20  	// hexadecimals
    21  	assert(0X_0 == 0)
    22  	assert(0X_1234 == 0x1234)
    23  	assert(0X_CAFE_f00d == 0xcafef00d)
    24  
    25  	// octals
    26  	assert(0o0 == 0)
    27  	assert(0o1234 == 01234)
    28  	assert(0o01234567 == 01234567)
    29  
    30  	assert(0O0 == 0)
    31  	assert(0O1234 == 01234)
    32  	assert(0O01234567 == 01234567)
    33  
    34  	assert(0o_0 == 0)
    35  	assert(0o_1234 == 01234)
    36  	assert(0o0123_4567 == 01234567)
    37  
    38  	assert(0O_0 == 0)
    39  	assert(0O_1234 == 01234)
    40  	assert(0O0123_4567 == 01234567)
    41  
    42  	// binaries
    43  	assert(0b0 == 0)
    44  	assert(0b1011 == 0xb)
    45  	assert(0b00101101 == 0x2d)
    46  
    47  	assert(0B0 == 0)
    48  	assert(0B1011 == 0xb)
    49  	assert(0B00101101 == 0x2d)
    50  
    51  	assert(0b_0 == 0)
    52  	assert(0b10_11 == 0xb)
    53  	assert(0b_0010_1101 == 0x2d)
    54  
    55  	// decimal floats
    56  	assert(1_2_3. == 123.)
    57  	assert(0_123. == 123.)
    58  
    59  	assert(0_0e0 == 0.)
    60  	assert(1_2_3e0 == 123.)
    61  	assert(0_123e0 == 123.)
    62  
    63  	assert(0e-0_0 == 0.)
    64  	assert(1_2_3E+0 == 123.)
    65  	assert(0123E1_2_3 == 123e123)
    66  
    67  	assert(0.e+1 == 0.)
    68  	assert(123.E-1_0 == 123e-10)
    69  	assert(01_23.e123 == 123e123)
    70  
    71  	assert(.0e-1 == .0)
    72  	assert(.123E+10 == .123e10)
    73  	assert(.0123E123 == .0123e123)
    74  
    75  	assert(1_2_3.123 == 123.123)
    76  	assert(0123.01_23 == 123.0123)
    77  
    78  	// hexadecimal floats
    79  	assert(0x0.p+0 == 0.)
    80  	assert(0Xdeadcafe.p-10 == 0xdeadcafe/1024.0)
    81  	assert(0x1234.P84 == 0x1234000000000000000000000)
    82  
    83  	assert(0x.1p-0 == 1./16)
    84  	assert(0X.deadcafep4 == 1.0*0xdeadcafe/0x10000000)
    85  	assert(0x.1234P+12 == 1.0*0x1234/0x10)
    86  
    87  	assert(0x0p0 == 0.)
    88  	assert(0Xdeadcafep+1 == 0x1bd5b95fc)
    89  	assert(0x1234P-10 == 0x1234/1024.0)
    90  
    91  	assert(0x0.0p0 == 0.)
    92  	assert(0Xdead.cafep+1 == 1.0*0x1bd5b95fc/0x10000)
    93  	assert(0x12.34P-10 == 1.0*0x1234/0x40000)
    94  
    95  	assert(0Xdead_cafep+1 == 0xdeadcafep+1)
    96  	assert(0x_1234P-10 == 0x1234p-10)
    97  
    98  	assert(0X_dead_cafe.p-10 == 0xdeadcafe.p-10)
    99  	assert(0x12_34.P1_2_3 == 0x1234.p123)
   100  
   101  	assert(1_234i == 1234i)
   102  	assert(1_234_567i == 1234567i)
   103  
   104  	assert(0.i == 0i)
   105  	assert(123.i == 123i)
   106  	assert(0123.i == 123i)
   107  
   108  	assert(0.e+1i == 0i)
   109  	assert(123.E-1_0i == 123e-10i)
   110  	assert(01_23.e123i == 123e123i)
   111  }
   112  

View as plain text