test/tools/javac/quid/QuotedIdent_BAD62.java

changeset 309
664edca41e34
equal deleted inserted replaced
308:03944ee4fac4 309:664edca41e34
1 /*
2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24 /*
25 * ##test
26 * ##bug 6746458
27 * ##summary Verify correct lexing of quoted identifiers.
28 * ##author jrose
29 *
30 * ##library ..
31 * ##run main quid.QuotedIdent_BAD62
32 */
33
34 /*
35 * Standalone testing:
36 * <code>
37 * $ cd $MY_REPO_DIR/langtools
38 * $ (cd make; make)
39 * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent_BAD62.java
40 * $ java -version # should print 1.6 or later
41 * $ java -cp dist quid.QuotedIdent_BAD62
42 * </code>
43 */
44
45 package quid;
46
47 public class QuotedIdent_BAD62 {
48 static void check(int testid, String have, String expect)
49 throws RuntimeException {
50 if ((have == null && have != expect) ||
51 (have != null && !have.equals(expect))) {
52 String msg =
53 "TEST " + testid + ": HAVE \"" +
54 have + "\" EXPECT \"" + expect + "\"";
55 System.out.println("StringConversion: " + msg);
56 throw new RuntimeException(msg);
57 }
58 }
59
60 // negative tests:
61 //static class #"" { } //BAD empty ident name
62 static class #"<foo>" { } //BAD bad char in ident name
63 /*static class /*(//BAD ident name interrupted by newline) #"jump:
64 " { } /* uncomment previous line to attempt class w/ bad name */
65
66 static class #"int" extends Number {
67 final int #"int";
68 #"int"(int #"int") {
69 this.#"int" = #"int";
70 }
71 static #"int" valueOf(int #"int") {
72 return new #"int"(#"int");
73 }
74 public int intValue() { return #"int"; }
75 public long longValue() { return #"int"; }
76 public float floatValue() { return #"int"; }
77 public double doubleValue() { return #"int"; }
78 public String toString() { return String.valueOf(#"int"); }
79 }
80
81 class #"*86" {
82 String #"555-1212"() { return "[*86.555-1212]"; }
83 }
84 static#"*86"#"MAKE-*86"() { // note close spacing
85 return new QuotedIdent_BAD62().new#"*86"();
86 }
87
88 static String bar() { return "[bar]"; }
89
90 public static void main(String[] args) throws Exception {
91 String s;
92
93 String #"sticky \' wicket" = "wicked ' stick";
94 s = #"sticky ' wicket";
95 check(11, s, "wicked \' stick");
96 check(12, #"s", s);
97 check(13, #"\163", s);
98
99 s = #"QuotedIdent_BAD62".bar();
100 check(21, s, "[bar]");
101
102 s = #"int".valueOf(123).toString();
103 check(22, s, "123");
104
105 s = #"MAKE-*86"().#"555-1212"();
106 check(23, s, "[*86.555-1212]");
107
108 class#"{{{inmost}}}" { }
109 s = new#"{{{inmost}}}"().getClass().getName();
110 if (!s.endsWith("{{{inmost}}}"))
111 check(24, s, "should end with \"{{{inmost}}}\"");
112
113 s = #"Yog-Shoggoth".#"(nameless ululation)";
114 check(25, s, "Tekeli-li!");
115
116 s = #"int".class.getName();
117 check(31, s, QuotedIdent_BAD62.class.getName()+"$int");
118
119 Class x86 = Class.forName(QuotedIdent_BAD62.class.getName()+"$*86");
120 if (x86 != #"*86".class)
121 check(32, "reflected "+x86, "static "+#"*86".class);
122
123 s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
124 check(31, s, "[*86.555-1212]");
125
126 System.out.println("OK");
127 }
128 }
129
130 interface #"Yog-Shoggoth" {
131 final String #"(nameless ululation)" = "Tekeli-li!";
132 }

mercurial