diff options
Diffstat (limited to 'org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java')
-rw-r--r-- | org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java b/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java new file mode 100644 index 0000000..f7ba2e4 --- /dev/null +++ b/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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.ui.text.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.dltk.sh.ui.Activator; +import org.eclipse.dltk.sh.ui.IShellColorConstants; +import org.eclipse.dltk.sh.ui.text.EvalScanner; +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 command substitution partitions. + */ +public class EvalScannerTest extends AbstractScannerTester { + + @Override + protected RuleBasedScanner getScanner() { + return new EvalScanner(cm, Activator.getDefault().getPreferenceStore()); + } + + @Override + protected String getText() { + return "$vars in command ${substitutions}"; + } + + /** + * Tests that we correctly highlight $dollar style parameter expansions + * within command substitutions. + */ + @Test + public void testDollar() { + IToken token = getNextToken(); + assertEquals(5, scanner.getTokenLength()); + assertEquals(0, 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 command substitutions. + */ + @Test + public void testDollarBrace() { + IToken token = getNthToken(14); + assertEquals(16, scanner.getTokenLength()); + assertEquals(17, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); + } + + /** + * Everything else should have the default highlighting for this partition + * type. + */ + @Test + public void testDefault() { + IToken token = getNthToken(3); + assertEquals(1, scanner.getTokenLength()); + assertEquals(6, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); + } +} |