test/tools/javac/literals/BadUnderscoreLiterals.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/literals/BadUnderscoreLiterals.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,48 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 6860973
     1.7 + * @summary Project Coin: underscores in literals
     1.8 + *
     1.9 + * @compile/fail BadUnderscoreLiterals.java
    1.10 + * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java
    1.11 + *
    1.12 + * @compile/fail -source 6 BadUnderscoreLiterals.java
    1.13 + * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadUnderscoreLiterals.java
    1.14 + */
    1.15 +
    1.16 +public class BadUnderscoreLiterals {
    1.17 +    int valid = 1_1;            // valid literal; illegal in -source 6
    1.18 +
    1.19 +    // test zero
    1.20 +    int z1 = _0;                // valid (but undefined) variable
    1.21 +    int z2 = 0_;                // trailing underscore
    1.22 +
    1.23 +    // test simple (decimal) integers
    1.24 +    int i1 = _1_2_3;            // valid (but undefined) variable
    1.25 +    int i2 = 1_2_3_;            // trailing underscore
    1.26 +
    1.27 +    // test binary integers
    1.28 +    int b1 = 0b_0;              // leading underscore after radix
    1.29 +    int b2 = 0b0_;              // trailing underscore
    1.30 +
    1.31 +    // test hexadecimal integers
    1.32 +    int x1 = 0x_0;              // leading underscore after radix
    1.33 +    int x2 = 0x0_;              // trailing underscore
    1.34 +
    1.35 +    // test floating point numbers
    1.36 +    float f1 = 0_.1;            // trailing underscore before decimal point
    1.37 +    float f2 = 0._1;            // leading underscore after decimal point
    1.38 +    float f3 = 0.1_;            // trailing underscore
    1.39 +    float f4 = 0.1_e0;          // trailing underscore before exponent
    1.40 +    float f5 = 0e_1;            // leading underscore in exponent
    1.41 +    float f6 = 0e1_;            // trailing underscore in exponent
    1.42 +
    1.43 +    // hexadecimal floating point
    1.44 +    float xf1 = 0x_0.1p0;       // leading underscore after radix
    1.45 +    float xf2 = 0x0_.1p0;       // trailing underscore before decimal point
    1.46 +    float xf3 = 0x0._1p0;       // leading underscore after decimal point
    1.47 +    float xf4 = 0x0.1_p0;       // trailing underscore before exponent
    1.48 +    float xf5 = 0x0p_1;         // leading underscore after exponent
    1.49 +    float xf6 = 0x0p1_;         // trailing underscore
    1.50 +}
    1.51 +

mercurial