aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/NamePatternParserTestCase.java
blob: 442e498854fa868a9fd8e96b209cce3a7e949c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* *******************************************************************
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *     PARC     initial implementation
 * ******************************************************************/

package org.aspectj.weaver.patterns;

import junit.framework.TestCase;

/**
 * @author hugunin
 *
 *         To change this generated comment edit the template variable
 *         "typecomment": Window>Preferences>Java>Templates. To enable and
 *         disable the creation of type comments go to
 *         Window>Preferences>Java>Code Generation.
 */
public class NamePatternParserTestCase extends TestCase {
	/**
	 * Constructor for PatternTestCase.
	 *
	 * @param name
	 */
	public NamePatternParserTestCase(String name) {
		super(name);
	}

	public void testMatch() {
		checkMatch(NamePatternTestCase.matchAll);
		checkMatch(NamePatternTestCase.match1);
		checkMatch(NamePatternTestCase.match2);

		NamePattern p = new PatternParser("abc *").parseNamePattern();
		assertEquals(new NamePattern("abc"), p);
	}

	public void testTypePattern() {
		TypePattern tp = null;
		tp = new PatternParser(" @Ann *  ").parseTypePattern();
		assertEquals(1, tp.start);
		assertEquals(6, tp.end);
		tp = new PatternParser("  (@Ann *)   ").parseTypePattern();
		assertEquals(2, tp.start);
		assertEquals(9, tp.end);
	}

	/**
	 * Method checkMatch.
	 *
	 * @param string
	 * @param matchAll
	 * @param b
	 */
	private void checkMatch(String[] patterns) {
		for (String pattern : patterns) {
			ITokenSource tokenSource = BasicTokenSource.makeTokenSource(
					pattern, null);
			NamePattern p1 = new PatternParser(tokenSource).parseNamePattern();
			NamePattern p2 = new NamePattern(pattern);
			assertEquals("pattern: " + pattern, p2, p1);
			assertEquals("eof", IToken.EOF, tokenSource.next());
		}
	}
}