Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2d47e5b857ffbe73aa49615dfdaa8c750e861798 (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
/*******************************************************************************
 * Copyright (c) 2011 Mat Booth 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:
 *     Mat Booth
 *******************************************************************************/
package org.eclipse.dltk.sh.internal.ui.text.tests;

import org.eclipse.dltk.sh.internal.ui.text.AssignmentDetector;
import org.eclipse.dltk.sh.internal.ui.text.AssignmentRule;
import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions;
import org.eclipse.jface.text.rules.Token;
import org.junit.Assert;
import org.junit.Test;

/**
 * Tests the assignment rule that detects variable assignments.
 */
public class AssignmentRuleTest {

	// Mock objects
	private MockScanner fScanner;

	// Objects under test
	private static AssignmentRule fRule = new AssignmentRule(new AssignmentDetector(),
			Token.UNDEFINED, new Token(IShellPartitions.PARAM_CONTENT_TYPE));

	/**
	 * Match simple variable assignments.
	 */
	@Test
	public void testAssignmentMatch() {
		fScanner = new MockScanner("VAR=assignment");
		Assert.assertFalse(fRule.evaluate(fScanner).isUndefined());
		Assert.assertEquals("VAR", fScanner.getBuffer().substring(0, fScanner.getOffset()));
	}

	/**
	 * Match assignments to shell array variable indexes.
	 */
	@Test
	public void testArrayIndexAssignmentMatch() {
		fScanner = new MockScanner("VAR[2]=assignment");
		Assert.assertFalse(fRule.evaluate(fScanner).isUndefined());
		Assert.assertEquals("VAR[2]", fScanner.getBuffer().substring(0, fScanner.getOffset()));
	}

	/**
	 * The equals MUST immediately follow the var-name, otherwise don't match.
	 */
	@Test
	public void testNonAssignmentMatch() {
		fScanner = new MockScanner("VAR = assignment");
		Assert.assertTrue(fRule.evaluate(fScanner).isUndefined());
		Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset()));
	}
}

Back to the top