Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 04b6998bbdbcddebbe5fffc091a392fd7a8e701f (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jesper Steen Møller <jesper@selskabet.org> - contributions for:	
 *         Bug 531046: [10] ICodeAssist#codeSelect support for 'var'
 *******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.parser;

import org.eclipse.jdt.core.JavaModelException;

import junit.framework.Test;

public class SelectionParserTest10 extends AbstractSelectionTest {
	static {
		// TESTS_NUMBERS = new int[] { 1 };
		// TESTS_NAMES = new String[] { "test001" };
	}

	public static Test suite() {
		return buildMinimalComplianceTestSuite(SelectionParserTest10.class, F_10);
	}

	public SelectionParserTest10(String testName) {
		super(testName);
	}

	public void test001() throws JavaModelException {
		String string =   "public class X {\n" 
						+ "  public static void main(String[] args) {\n"
						+ "    var s_s = args[0];\n"
						+ "  }\n"
						+ "}\n";	

		String selection = "s_s";
		String expectedSelection = "<SelectionOnLocalName:var s_s = args[0]>;";

		String completionIdentifier = "s_s";
		String expectedUnitDisplayString = "public class X {\n" + 
											"  public X() {\n" + 
											"  }\n" + 
											"  public static void main(String[] args) {\n" + 
											"    <SelectionOnLocalName:var s_s = args[0]>;\n" + 
											"  }\n" + 
											"}\n";
		String expectedReplacedSource = "s_s";
		String testName = "X.java";

		int selectionStart = string.lastIndexOf(selection);
		int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;

		checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
				completionIdentifier, expectedReplacedSource, testName);
	}

	public void test002() throws JavaModelException {
		String string =   "public class X {\n" 
						+ "  public static void main(String[] args) {\n"
						+ "    var s_s = args[0];\n"
						+ "  }\n"
						+ "}\n";	

		String selection = "var";
		String expectedSelection = "<SelectOnType:var>";

		String completionIdentifier = "var";
		String expectedUnitDisplayString = "public class X {\n" + 
											"  public X() {\n" + 
											"  }\n" + 
											"  public static void main(String[] args) {\n" + 
										    "    <SelectOnType:var> s_s = args[0];\n" +
											"  }\n" + 
											"}\n";
		String expectedReplacedSource = "var";
		String testName = "X.java";

		int selectionStart = string.lastIndexOf(selection);
		int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1;

		checkMethodParse(string.toCharArray(), selectionStart, selectionEnd, expectedSelection, expectedUnitDisplayString,
				completionIdentifier, expectedReplacedSource, testName);
	}
}

Back to the top