test/tools/javac/quid/QuotedIdent_BAD62.java

changeset 309
664edca41e34
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/quid/QuotedIdent_BAD62.java	Fri Jun 26 19:12:41 2009 -0700
     1.3 @@ -0,0 +1,132 @@
     1.4 +/*
     1.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * ##test
    1.29 + * ##bug 6746458
    1.30 + * ##summary Verify correct lexing of quoted identifiers.
    1.31 + * ##author jrose
    1.32 + *
    1.33 + * ##library ..
    1.34 + * ##run main quid.QuotedIdent_BAD62
    1.35 + */
    1.36 +
    1.37 +/*
    1.38 + * Standalone testing:
    1.39 + * <code>
    1.40 + * $ cd $MY_REPO_DIR/langtools
    1.41 + * $ (cd make; make)
    1.42 + * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD62.java
    1.43 + * $ java -version  # should print 1.6 or later
    1.44 + * $ java -cp dist quid.QuotedIdent_BAD62
    1.45 + * </code>
    1.46 + */
    1.47 +
    1.48 +package quid;
    1.49 +
    1.50 +public class QuotedIdent_BAD62 {
    1.51 +    static void check(int testid, String have, String expect)
    1.52 +                throws RuntimeException {
    1.53 +        if ((have == null && have != expect) ||
    1.54 +                (have != null && !have.equals(expect))) {
    1.55 +            String msg =
    1.56 +                "TEST " + testid + ": HAVE \"" +
    1.57 +                have + "\" EXPECT \"" + expect + "\"";
    1.58 +            System.out.println("StringConversion: " + msg);
    1.59 +            throw new RuntimeException(msg);
    1.60 +        }
    1.61 +    }
    1.62 +
    1.63 +    // negative tests:
    1.64 +    //static class #"" { } //BAD empty ident name
    1.65 +    static class #"<foo>" { } //BAD bad char in ident name
    1.66 +    /*static class /*(//BAD ident name interrupted by newline) #"jump:
    1.67 +    " { } /* uncomment previous line to attempt class w/ bad name */
    1.68 +
    1.69 +    static class #"int" extends Number {
    1.70 +        final int #"int";
    1.71 +        #"int"(int #"int") {
    1.72 +            this.#"int" = #"int";
    1.73 +        }
    1.74 +        static #"int" valueOf(int #"int") {
    1.75 +            return new #"int"(#"int");
    1.76 +        }
    1.77 +        public int intValue() { return #"int"; }
    1.78 +        public long longValue() { return #"int"; }
    1.79 +        public float floatValue() { return #"int"; }
    1.80 +        public double doubleValue() { return #"int"; }
    1.81 +        public String toString() { return String.valueOf(#"int"); }
    1.82 +    }
    1.83 +
    1.84 +    class #"*86" {
    1.85 +        String #"555-1212"() { return "[*86.555-1212]"; }
    1.86 +    }
    1.87 +    static#"*86"#"MAKE-*86"() {   // note close spacing
    1.88 +        return new QuotedIdent_BAD62().new#"*86"();
    1.89 +    }
    1.90 +
    1.91 +    static String bar() { return "[bar]"; }
    1.92 +
    1.93 +    public static void main(String[] args) throws Exception {
    1.94 +        String s;
    1.95 +
    1.96 +        String #"sticky \' wicket" = "wicked ' stick";
    1.97 +        s = #"sticky ' wicket";
    1.98 +        check(11, s, "wicked \' stick");
    1.99 +        check(12, #"s", s);
   1.100 +        check(13, #"\163", s);
   1.101 +
   1.102 +        s = #"QuotedIdent_BAD62".bar();
   1.103 +        check(21, s, "[bar]");
   1.104 +
   1.105 +        s = #"int".valueOf(123).toString();
   1.106 +        check(22, s, "123");
   1.107 +
   1.108 +        s = #"MAKE-*86"().#"555-1212"();
   1.109 +        check(23, s, "[*86.555-1212]");
   1.110 +
   1.111 +        class#"{{{inmost}}}" { }
   1.112 +        s = new#"{{{inmost}}}"().getClass().getName();
   1.113 +        if (!s.endsWith("{{{inmost}}}"))
   1.114 +            check(24, s, "should end with \"{{{inmost}}}\"");
   1.115 +
   1.116 +        s = #"Yog-Shoggoth".#"(nameless ululation)";
   1.117 +        check(25, s, "Tekeli-li!");
   1.118 +
   1.119 +        s = #"int".class.getName();
   1.120 +        check(31, s, QuotedIdent_BAD62.class.getName()+"$int");
   1.121 +
   1.122 +        Class x86 = Class.forName(QuotedIdent_BAD62.class.getName()+"$*86");
   1.123 +        if (x86 != #"*86".class)
   1.124 +            check(32, "reflected "+x86, "static "+#"*86".class);
   1.125 +
   1.126 +        s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
   1.127 +        check(31, s, "[*86.555-1212]");
   1.128 +
   1.129 +        System.out.println("OK");
   1.130 +    }
   1.131 +}
   1.132 +
   1.133 +interface #"Yog-Shoggoth" {
   1.134 +    final String #"(nameless ululation)" = "Tekeli-li!";
   1.135 +}

mercurial