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/DoubleQuoteScannerTest.java')
-rw-r--r--tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java
new file mode 100644
index 0000000..cdfd9c0
--- /dev/null
+++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ *******************************************************************************/
+package org.eclipse.dltk.sh.internal.ui.text.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.dltk.sh.internal.ui.Activator;
+import org.eclipse.dltk.sh.internal.ui.IShellColorConstants;
+import org.eclipse.dltk.sh.internal.ui.text.DoubleQuoteScanner;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.junit.Test;
+
+/**
+ * Test the scanner for double quote partitions.
+ */
+public class DoubleQuoteScannerTest extends AbstractScannerTester {
+
+ @Override
+ protected RuleBasedScanner getScanner() {
+ return new DoubleQuoteScanner(cm, Activator.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected String getText() {
+ return "x${var}x$var`eval`x$(eval)";
+ }
+
+ /**
+ * Tests that we correctly highlight $dollar style parameter expansions
+ * within interpolated strings.
+ */
+ @Test
+ public void testDollar() {
+ IToken token = getNthToken(4);
+ assertEquals(4, scanner.getTokenLength());
+ assertEquals(8, scanner.getTokenOffset());
+ TextAttribute ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE));
+ }
+
+ /**
+ * Tests that we correctly highlight ${dollar-brace} style parameter
+ * expansions within interpolated strings.
+ */
+ @Test
+ public void testDollarBrace() {
+ IToken token = getNthToken(2);
+ assertEquals(6, scanner.getTokenLength());
+ assertEquals(1, scanner.getTokenOffset());
+ TextAttribute ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE));
+ }
+
+ /**
+ * Tests that we correctly highlight `back-tick` style command substitutions
+ * within interpolated strings.
+ */
+ @Test
+ public void testEval() {
+ IToken token = getNthToken(5);
+ assertEquals(6, scanner.getTokenLength());
+ assertEquals(12, scanner.getTokenOffset());
+ TextAttribute ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL));
+ }
+
+ /**
+ * Tests that we correctly highlight $(dollar-brace) style command
+ * substitutions within interpolated strings.
+ */
+ @Test
+ public void testDollarEval() {
+ IToken token = getNthToken(7);
+ assertEquals(7, scanner.getTokenLength());
+ assertEquals(19, scanner.getTokenOffset());
+ TextAttribute ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL));
+ }
+
+ /**
+ * Everything else should have the default highlighting for this partition
+ * type.
+ */
+ @Test
+ public void testDefault() {
+ IToken token = getNthToken(1);
+ assertEquals(1, scanner.getTokenLength());
+ assertEquals(0, scanner.getTokenOffset());
+ TextAttribute ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE));
+
+ token = getNthToken(2);
+ assertEquals(1, scanner.getTokenLength());
+ assertEquals(7, scanner.getTokenOffset());
+ ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE));
+
+ token = getNthToken(3);
+ assertEquals(1, scanner.getTokenLength());
+ assertEquals(18, scanner.getTokenOffset());
+ ta = (TextAttribute) token.getData();
+ assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE));
+ }
+}

Back to the top