Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java')
-rw-r--r--tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java
new file mode 100644
index 0000000..2d47e5b
--- /dev/null
+++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java
@@ -0,0 +1,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