01: /**
02: *
03: * Copyright 2004 James Strachan
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: **/package org.codehaus.groovy.classgen;
18:
19: import junit.framework.TestCase;
20: import org.codehaus.groovy.ast.ASTNode;
21: import org.codehaus.groovy.syntax.RuntimeParserException;
22:
23: /**
24: * @version $Revision: 2120 $
25: */
26: public class VerifierCodeVisitorTest extends TestCase {
27: public void testValidNames() {
28: assertValidName("a");
29: assertValidName("a1234");
30: assertValidName("a_b_c");
31: assertValidName("a____1234");
32: }
33:
34: public void testInvalidNames() {
35: assertInvalidName("1");
36: assertInvalidName("100");
37: assertInvalidName("1a");
38: assertInvalidName("a!");
39: assertInvalidName("a.");
40: assertInvalidName("$");
41: assertInvalidName("$foo");
42: }
43:
44: protected void assertValidName(String name) {
45: VerifierCodeVisitor.assertValidIdentifier(name,
46: "variable name", new ASTNode());
47: }
48:
49: protected void assertInvalidName(String name) {
50: try {
51: VerifierCodeVisitor.assertValidIdentifier(name,
52: "variable name", new ASTNode());
53: fail("Should have thrown exception due to invalid name: "
54: + name);
55: } catch (RuntimeParserException e) {
56: System.out.println("Caught invalid exception: " + e);
57: }
58: }
59: }
|