diff options
Diffstat (limited to 'tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface')
19 files changed, 0 insertions, 3687 deletions
diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java deleted file mode 100644 index 1d6e3947c..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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: - * Christian Plesner Hansen (plesner@quenta.org) - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextStore; -import org.eclipse.jface.text.rules.FastPartitioner; -import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.source.ICharacterPairMatcher; - -/** - * Generic test of simple character pair matchers - * - * @since 3.3 - */ -public abstract class AbstractPairMatcherTest extends TestCase { - - /** - * Constructs a new character pair matcher. - * - * @param chars the characters to match - * @return the character pair matcher - */ - protected abstract ICharacterPairMatcher createMatcher(final String chars); - - /** - * Returns the partitioning treated by the matcher. - * - * @return the partition - */ - protected abstract String getDocumentPartitioning(); - - public AbstractPairMatcherTest(String name) { - super(name); - } - - public AbstractPairMatcherTest() { - super(); - } - - /* --- T e s t s --- */ - - /** Tests that the test case reader works */ - public void testTestCaseReader() { - performReaderTest("#( )%", 3, 0, "( )"); - performReaderTest("%( )#", 0, 3, "( )"); - performReaderTest("( )%", 3, -1, "( )"); - performReaderTest("#%", 0, 0, ""); - } - - /** - * Very simple checks. - * - * @throws BadLocationException - */ - public void testSimpleMatchSameMatcher() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, "#( )%"); - performMatch(matcher, "#[ ]%"); - performMatch(matcher, "#{ }%"); - performMatch(matcher, "(% )#"); - performMatch(matcher, "[% ]#"); - performMatch(matcher, "{% }#"); - matcher.dispose(); - } - - /** - * Very simple checks. - * - * @throws BadLocationException - */ - public void testSimpleMatchDifferentMatchers() throws BadLocationException { - performMatch("()[]{}", "#( )%"); - performMatch("()[]{}", "#[ ]%"); - performMatch("()[]{}", "#{ }%"); - performMatch("()[]{}", "(% )#"); - performMatch("()[]{}", "[% ]#"); - performMatch("()[]{}", "{% }#"); - } - - /** - * Close matches. - * - * @throws BadLocationException - */ - public void testCloseMatches() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, "#()%"); - performMatch(matcher, "(%)#"); - performMatch(matcher, "#(())%"); - performMatch(matcher, "(%())#"); - performMatch(matcher, "((%)#)"); - performMatch(matcher, "(#()%)"); - matcher.dispose(); - } - - - /** - * Checks of simple situations where no matches should be found. - * - * @throws BadLocationException - */ - public void testIncompleteMatch() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, "(% "); - performMatch(matcher, "%( )"); - performMatch(matcher, "( % )"); - performMatch(matcher, "( %)"); - performMatch(matcher, "%"); - matcher.dispose(); - } - - /** - * Test that it doesn't match across different partitions. - * - * @throws BadLocationException - */ - public void testPartitioned() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, "(% |a a| )#"); - performMatch(matcher, "#( |a a| )%"); - performMatch(matcher, "|b #( )% b|"); - performMatch(matcher, "( |b )% b|"); - performMatch(matcher, "(% |b ) b|"); - performMatch(matcher, "|a ( a| )%"); - performMatch(matcher, "|a (% a| )"); - performMatch(matcher, "|c #( c| ) ( |c )% c|"); - performMatch(matcher, "|c (% c| ) ( |c )# c|"); - performMatch(matcher, "(% |a ) a| |b ) b| |c ) c| )#"); - matcher.dispose(); - } - - /** - * Test that it works properly next to partition boundaries. - * - * @throws BadLocationException - */ - public void testTightPartitioned() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, "(|b)%b|"); - performMatch(matcher, "(%|b)b|"); - performMatch(matcher, "|a(a|)%"); - performMatch(matcher, "|a(%a|)"); - performMatch(matcher, "|c#(c|)(|c)%c|"); - performMatch(matcher, "|c(%c|)(|c)#c|"); - performMatch(matcher, "(%|a)a||b)b||c)c|)#"); - matcher.dispose(); - } - - /** Test that nesting works properly */ - public void testNesting() { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - performMatch(matcher, " ( #( ( ( ) ) ( ) )% ) "); - performMatch(matcher, " ( (% ( ( ) ) ( ) )# ) "); - performMatch(matcher, " ( #( { ( ) } [ ] )% ) "); - performMatch(matcher, " ( (% { ( ) } [ ] )# ) "); - performMatch(matcher, " ( ( #{ ( ) }% [ ] ) ) "); - performMatch(matcher, " ( ( {% ( ) }# [ ] ) ) "); - performMatch(matcher, "a(b#(c(d(e)f)g(h)i)%j)k"); - performMatch(matcher, "a(b(%c(d(e)f)g(h)i)#j)k"); - performMatch(matcher, "a(b#(c{d(e)f}g[h]i)%j)k"); - performMatch(matcher, "a(b(%c{d(e)f}g[h]i)#j)k"); - performMatch(matcher, "a(b(c#{d(e)f}%g[h]i)j)k"); - performMatch(matcher, "a(b(c{%d(e)f}#g[h]i)j)k"); - matcher.dispose(); - } - - /** - * Test a few boundary conditions. - * - * * @throws BadLocationException - */ - public void testBoundaries() throws BadLocationException { - final ICharacterPairMatcher matcher= createMatcher("()[]{}"); - final StringDocument doc= new StringDocument("abcdefghijkl"); - assertNull(matcher.match(null, 0)); - assertNull(matcher.match(doc, -1)); - assertNull(matcher.match(doc, doc.getLength() + 1)); - matcher.dispose(); - } - - public void testBug156426() { - final ICharacterPairMatcher matcher= createMatcher("()[]{}<>"); - performMatch(matcher, " #( a < b )% "); - performMatch(matcher, " (% a < b )# "); - performMatch(matcher, " #( a > b )% "); - performMatch(matcher, " (% a > b )# "); - matcher.dispose(); - } - - /* --- U t i l i t i e s --- */ - - /** - * Checks that the test case reader reads the test case as specified. - * - * @param testString the string to test - * @param expectedPos the expected position - * @param expectedMatch the expected match - * @param expectedString the expected string - */ - private void performReaderTest(String testString, int expectedPos, int expectedMatch, String expectedString) { - TestCase t0= createTestCase(testString); - assertEquals(expectedPos, t0.fPos); - assertEquals(expectedMatch, t0.fMatch); - assertEquals(expectedString, t0.fString); - } - - /** - * Checks that the given matcher matches the input as specified. - * - * @param matcher the matcher - * @param testCase the test string - */ - protected void performMatch(final ICharacterPairMatcher matcher, final String testCase) { - final TestCase test= createTestCase(testCase); - matcher.clear(); - final IRegion region= matcher.match(test.getDocument(), test.fPos); - if (test.fMatch == -1) { - // if no match point has been specified there should be - // no match - if (region != null) System.out.println(region.getOffset()); - assertNull(region); - } else { - assertNotNull(region); - final boolean isForward= test.fPos > test.fMatch; - assertEquals(isForward, matcher.getAnchor() == ICharacterPairMatcher.RIGHT); - // If the match is forward, the curser is one character - // after the start of the match, so we need to count one - // step backwards - final int offset= isForward ? test.getOffset() : test.getOffset() - 1; - final int length= isForward ? test.getLength() : test.getLength() + 1; - assertEquals(length, region.getLength()); - assertEquals(offset, region.getOffset()); - } - } - - private void performMatch(final String delims, final String testCase) { - final ICharacterPairMatcher matcher= createMatcher(delims); - performMatch(matcher, testCase); - matcher.dispose(); - } - - /** - * Creates a text case from a string. In the given string a '%' represents the position of the - * cursor and a '#' represents the position of the expected matching character. - * - * @param str the string for which to create the test case - * @return the created test case - */ - public TestCase createTestCase(String str) { - int pos= str.indexOf("%"); - assertFalse(pos == -1); - int match= str.indexOf("#"); - // account for the length of the first position marker, - // if there is one - if (match != -1 && match < pos) pos -= 1; - if (pos < match) match -= 1; - final String stripped= str.replaceAll("%", "").replaceAll("#", ""); - return new TestCase(stripped, pos, match); - } - - private class TestCase { - - public final String fString; - public final int fPos, fMatch; - - public TestCase(String string, int pos, int match) { - fString= string; - fPos= pos; - fMatch= match; - } - - public IDocument getDocument() { - return new StringDocument(fString); - } - - public int getLength() { - return Math.abs(fPos - fMatch); - } - - public int getOffset() { - if (fPos > fMatch) return fMatch; - return fPos; - } - - } - - private class StringDocument extends Document { - - public StringDocument(String str) { - this.setTextStore(new StringTextStore(str)); - this.set(str); - final IDocumentPartitioner part= createPartitioner(); - this.setDocumentPartitioner(getDocumentPartitioning(), part); - part.connect(this); - } - - } - - private static class StringTextStore implements ITextStore { - - private String fString; - - public StringTextStore(final String str) { - fString= str; - } - - public char get(int offset) { - return fString.charAt(offset); - } - - public String get(int offset, int length) { - return fString.substring(offset, offset + length); - } - - public int getLength() { - return fString.length(); - } - - public void replace(int offset, int length, String text) { - throw new UnsupportedOperationException(); - } - - public void set(String text) { - fString= text; - } - - } - - private static String DEFAULT_PARTITION= IDocument.DEFAULT_CONTENT_TYPE; - - private static IDocumentPartitioner createPartitioner() { - final RuleBasedPartitionScanner scan= new RuleBasedPartitionScanner(); - final List/*<IPredicateRule>*/ rules= new ArrayList/*<IPredicateRule>*/(); - rules.add(new SingleLineRule("|a", "a|", new Token("a"))); - rules.add(new SingleLineRule("|b", "b|", new Token("b"))); - rules.add(new SingleLineRule("|c", "c|", new Token("c"))); - scan.setPredicateRules((IPredicateRule[]) rules.toArray(new IPredicateRule[rules.size()])); - scan.setDefaultReturnToken(new Token(DEFAULT_PARTITION)); - return new FastPartitioner(scan, new String[] { DEFAULT_PARTITION, "a", "b", "c" }); - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractUndoManagerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractUndoManagerTest.java deleted file mode 100644 index 361e701d4..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/AbstractUndoManagerTest.java +++ /dev/null @@ -1,508 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension4; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.IUndoManager; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler; -import org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry; -import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument; - -/** - * Tests for DefaultUndoManager. Changed from the JFace original to creates - * and test against a structured document. - */ -public abstract class AbstractUndoManagerTest extends TestCase { - - /** The maximum undo level. */ - private static final int MAX_UNDO_LEVEL= 256; - - /** The shell. */ - private Shell fShell; - /** The text viewer. */ - private ITextViewer fTextViewer; - /** The undo manager. */ - private IUndoManager fUndoManager; - - private static final int LOOP_COUNT= 20; - - //--- Static data sets for comparing scenarios - obtained from capturing random data --- - /** Original document */ - private static final String INITIAL_DOCUMENT_CONTENT= "+7cyg:/F!T4KnW;0+au$t1G%(`Z|u'7'_!-k?<c\"2Y.]CwsO.r"; - /** Replacement string */ - private static final String [] REPLACEMENTS= { ">", "F", "M/r-*", "-", "bl", "", "}%/#", "", "k&", "f", "\\g", "c!x", "TLG-", "NPO", "Rp9u", "", "X", "W(", ")z", "oe", "", "h*", "t", "I", "X=N>", "2yt", "&Z", "2)W=", ":K", "P9S", "s8t8o", "", "", "5{7", "%", "", "v3", "Wz", "sH", "3c", "8", "ol", ",6$", "94[#", ".~", "n", ">", "9", "W", ",(FW", "Q", "^", "Bq", "$", "re", "", "9", "8[", "Mx", "4b", "$6", "F", "8s]", "o", "-", "E&6", "S\\", "/", "z.a", "4ai", "b", ")", "", "l", "VU", "7M+Ql", "xZ?x", "xx", "lc", "b", "A", "!", "4pSU", "", "{J", "H", "l>_", "n&9", "", "&`", ";igQxq", "", ">", ";\"", "k\\`]G", "o{?", "", "K", "_6", "="}; - /** Position/offset pairs */ - private static final int [] POSITIONS= { 18, 2, 43, 1, 3, 2, 28, 3, 35, 1, 23, 5, 32, 2, 30, 1, 22, 1, 37, 0, 23, 3, 43, 2, 46, 1, 17, 1, 36, 6, 17, 5, 30, 4, 25, 1, 2, 2, 30, 0, 37, 3, 28, 1, 30, 2, 20, 5, 33, 1, 29, 1, 15, 2, 21, 2, 24, 4, 38, 3, 8, 0, 33, 2, 15, 2, 25, 0, 8, 2, 20, 3, 43, 2, 44, 1, 44, 2, 32, 2, 40, 2, 32, 3, 12, 2, 38, 3, 33, 2, 46, 0, 13, 3, 45, 0, 16, 2, 3, 2, 44, 0, 48, 0, 18, 5, 7, 6, 7, 3, 40, 0, 9, 1, 16, 3, 28, 3, 36, 1, 35, 2, 0, 3, 6, 1, 10, 4, 14, 2, 15, 3, 33, 1, 36, 0, 37, 0, 4, 3, 31, 3, 33, 3, 11, 3, 20, 2, 25, 3, 4, 3, 7, 3, 17, 0, 3, 1, 31, 3, 34, 1, 21, 0, 33, 1, 17, 4, 9, 1, 26, 3, 2, 3, 12, 1, 26, 3, 9, 5, 5, 0, 31, 3, 0, 3, 12, 1, 1, 1, 3, 0, 39, 0, 9, 2, 2, 0, 28, 2}; - - private static final boolean DEBUG= false; - - - /* - * @see TestCase#TestCase(String) - */ - public AbstractUndoManagerTest(final String name) { - super(name); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() { - fShell= new Shell(); - fUndoManager= createUndoManager(MAX_UNDO_LEVEL); - fTextViewer= new TextViewer(fShell, SWT.NONE); - fTextViewer.setUndoManager(fUndoManager); - fUndoManager.connect(fTextViewer); - } - - abstract protected IUndoManager createUndoManager(int maxUndoLevel); - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() { - fUndoManager.disconnect(); - fUndoManager= null; - fShell.dispose(); - fShell= null; - fTextViewer= null; - } - - /** - * Test for line delimiter conversion. - */ - public void testConvertLineDelimiters() { - final String original= "a\r\nb\r\n"; - final IDocument document= createDocument(original); - fTextViewer.setDocument(document); - - try { - document.replace(1, 2, "\n"); - document.replace(3, 2, "\n"); - } catch (BadLocationException e) { - assertTrue(false); - } - - assertTrue(fUndoManager.undoable()); - fUndoManager.undo(); - assertTrue(fUndoManager.undoable()); - fUndoManager.undo(); - - final String reverted= document.get(); - - assertEquals(original, reverted); - } - - /** - * Randomly applies document changes. - */ - public void testRandomAccess() { - final int RANDOM_STRING_LENGTH= 50; - final int RANDOM_REPLACE_COUNT= 100; - - assertTrue(RANDOM_REPLACE_COUNT >= 1); - assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL); - - String original= createRandomString(RANDOM_STRING_LENGTH); - final IDocument document= createDocument(original); - fTextViewer.setDocument(document); - - doChange(document, RANDOM_REPLACE_COUNT); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - - final String reverted= document.get(); - assertEquals(original, reverted); - } - - private void doChange(IDocument document, int count) { - try { - String before= document.get(); - - if (DEBUG) - System.out.println(before); - - Position [] positions= new Position[count]; - String [] strings= new String[count]; - for (int i= 0; i < count; i++) { - final Position position= createRandomPositionPoisson(document.getLength()); - final String string= createRandomStringPoisson(); - document.replace(position.getOffset(), position.getLength(), string); - positions[i]= position; - strings[i]= string; - } - - if (DEBUG) { - System.out.print("{ "); - for (int i=0; i<count; i++) { - System.out.print(positions[i].getOffset()); - System.out.print(", "); - System.out.print(positions[i].getLength()); - System.out.print(", "); - } - System.out.println(" }"); - System.out.print("{ "); - for (int i=0; i<count; i++) { - System.out.print("\""); - System.out.print(strings[i]); - System.out.print("\", "); - } - System.out.println(" }"); - } - } catch (BadLocationException e) { - assertTrue(false); - } - } - - // repeatable test case for comparing success/failure among different tests - private void doRepeatableChange(IDocument document) { - assertTrue(POSITIONS.length >= (2 * REPLACEMENTS.length)); - try { - for (int i= 0; i < REPLACEMENTS.length; i++) { - int offset= POSITIONS[i*2]; - int length= POSITIONS[i*2+1]; - if (document.getLength() > offset + length) - document.replace(offset, length, REPLACEMENTS[i]); - else - document.replace(0,0, REPLACEMENTS[i]); - } - } catch (BadLocationException e) { - assertTrue(false); - } - } - - public void testLoopRandomAccessAsCompound() { - int i= 0; - while (i < LOOP_COUNT) { - fUndoManager.reset(); - testRandomAccessAsCompound(); - i++; - } - } - - public void testLoopRandomAccess() { - int i= 0; - while (i < LOOP_COUNT) { - fUndoManager.reset(); - testRandomAccess(); - i++; - } - } - - public void testLoopRandomAccessAsUnclosedCompound() { - int i= 0; - while (i < LOOP_COUNT) { - fUndoManager.reset(); - testRandomAccessAsUnclosedCompound(); - i++; - } - } - - public void testLoopConvertLineDelimiters() { - int i= 0; - while (i < LOOP_COUNT) { - fUndoManager.reset(); - testConvertLineDelimiters(); - i++; - } - } - - public void testLoopRandomAccessWithMixedCompound() { - int i= 0; - while (i < LOOP_COUNT) { - fUndoManager.reset(); - testRandomAccessWithMixedCompound(); - i++; - } - } - - public void testRandomAccessAsCompound() { - final int RANDOM_STRING_LENGTH= 50; - final int RANDOM_REPLACE_COUNT= 100; - - assertTrue(RANDOM_REPLACE_COUNT >= 1); - assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL); - - String original= createRandomString(RANDOM_STRING_LENGTH); - final IDocument document= createDocument(original); - fTextViewer.setDocument(document); - - fUndoManager.beginCompoundChange(); - doChange(document, RANDOM_REPLACE_COUNT); - fUndoManager.endCompoundChange(); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - assertTrue(!fUndoManager.undoable()); - - final String reverted= document.get(); - - assertEquals(original, reverted); - } - - /** - * Test case for https://bugs.eclipse.org/bugs/show_bug.cgi?id=88172 - */ - public void testRandomAccessAsUnclosedCompound() { - - final int RANDOM_STRING_LENGTH= 50; - final int RANDOM_REPLACE_COUNT= 100; - - assertTrue(RANDOM_REPLACE_COUNT >= 1); - assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL); - - String original= createRandomString(RANDOM_STRING_LENGTH); - final IDocument document= createDocument(original); - fTextViewer.setDocument(document); - - fUndoManager.beginCompoundChange(); - doChange(document, RANDOM_REPLACE_COUNT); - // do not close the compound. - // fUndoManager.endCompoundChange(); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - assertTrue(!fUndoManager.undoable()); - - final String reverted= document.get(); - - assertEquals(original, reverted); - } - - public void testRandomAccessWithMixedCompound() { - - final int RANDOM_STRING_LENGTH= 50; - final int RANDOM_REPLACE_COUNT= 10; - final int NUMBER_COMPOUNDS= 5; - final int NUMBER_ATOMIC_PER_COMPOUND= 3; - - assertTrue(RANDOM_REPLACE_COUNT >= 1); - assertTrue(NUMBER_COMPOUNDS * (1 + NUMBER_ATOMIC_PER_COMPOUND) * RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL); - - String original= createRandomString(RANDOM_STRING_LENGTH); - final IDocument document= createDocument(original); - fTextViewer.setDocument(document); - - for (int i= 0; i < NUMBER_COMPOUNDS; i++) { - fUndoManager.beginCompoundChange(); - doChange(document, RANDOM_REPLACE_COUNT); - fUndoManager.endCompoundChange(); - assertTrue(fUndoManager.undoable()); - for (int j= 0; j < NUMBER_ATOMIC_PER_COMPOUND; j++) { - doChange(document, RANDOM_REPLACE_COUNT); - assertTrue(fUndoManager.undoable()); - } - } - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - assertTrue(!fUndoManager.undoable()); - - final String reverted= document.get(); - - assertEquals(original, reverted); - } - - public void testRepeatableAccess() { - assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL); - - final IDocument document= createDocument(INITIAL_DOCUMENT_CONTENT); - fTextViewer.setDocument(document); - - doRepeatableChange(document); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - - final String reverted= document.get(); - - assertEquals(INITIAL_DOCUMENT_CONTENT, reverted); - } - - public void testRepeatableAccessAsCompound() { - assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL); - - final IDocument document= createDocument(INITIAL_DOCUMENT_CONTENT); - fTextViewer.setDocument(document); - - fUndoManager.beginCompoundChange(); - doRepeatableChange(document); - fUndoManager.endCompoundChange(); - - assertTrue(fUndoManager.undoable()); - fUndoManager.undo(); - // with a single compound, there should be only one undo - assertFalse(fUndoManager.undoable()); - - final String reverted= document.get(); - - assertEquals(INITIAL_DOCUMENT_CONTENT, reverted); - } - - public void testRepeatableAccessAsUnclosedCompound() { - assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL); - - final IDocument document= createDocument(INITIAL_DOCUMENT_CONTENT); - fTextViewer.setDocument(document); - - fUndoManager.beginCompoundChange(); - doRepeatableChange(document); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - - final String reverted= document.get(); - - assertEquals(INITIAL_DOCUMENT_CONTENT, reverted); - } - - public void testRepeatableAccessWithMixedAndEmptyCompound() { - assertTrue(REPLACEMENTS.length + 2 <= MAX_UNDO_LEVEL); - - final IDocument document= createDocument(INITIAL_DOCUMENT_CONTENT); - fTextViewer.setDocument(document); - - fUndoManager.beginCompoundChange(); - doRepeatableChange(document); - fUndoManager.endCompoundChange(); - assertTrue(fUndoManager.undoable()); - - // insert an empty compound - fUndoManager.beginCompoundChange(); - fUndoManager.endCompoundChange(); - - // insert the atomic changes - doRepeatableChange(document); - - assertTrue(fUndoManager.undoable()); - while (fUndoManager.undoable()) - fUndoManager.undo(); - assertTrue(!fUndoManager.undoable()); - - final String reverted= document.get(); - - assertEquals(INITIAL_DOCUMENT_CONTENT, reverted); - } - - public void testDocumentStamp() { - final IDocument document= createDocument(INITIAL_DOCUMENT_CONTENT); - fTextViewer.setDocument(document); - long stamp= ((IDocumentExtension4)document).getModificationStamp(); - doChange(document, 1); - fUndoManager.undo(); - assertEquals(stamp, ((IDocumentExtension4)document).getModificationStamp()); - - } - - // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=109104 - public void testDocumentStamp2() throws BadLocationException { - final IDocument document= createDocument(""); - final int stringLength= 13; - fTextViewer.setDocument(document); - document.replace(0, 0, createRandomString(stringLength)); - long stamp= ((IDocumentExtension4)document).getModificationStamp(); - fUndoManager.undo(); - document.replace(0, 0, createRandomString(stringLength)); - assertFalse(stamp == ((IDocumentExtension4)document).getModificationStamp()); - - } - - private static String createRandomString(int length) { - final StringBuffer buffer= new StringBuffer(); - - for (int i= 0; i < length; i++) - buffer.append(getRandomCharacter()); - - return buffer.toString(); - } - - private static final char getRandomCharacter() { - // XXX should include \t - return (char) (32 + 95 * Math.random()); - } - - private static String createRandomStringPoisson() { - final int length= getRandomPoissonValue(2); - return createRandomString(length); - } - - private IDocument createDocument(String contents) { - IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.core.runtime.xml"); - BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument(); - document.set(contents); -// return new Document(contents); - return document; - } - - private static Position createRandomPositionPoisson(int documentLength) { - - float random= (float) Math.random(); - int offset= (int) (random * (documentLength + 1)); - - // Catch potential rounding issue - if (offset == documentLength + 1) - offset= documentLength; - - int length= getRandomPoissonValue(2); - if (offset + length > documentLength) - length= documentLength - offset; - - return new Position(offset, length); - } - - private static int getRandomPoissonValue(int mean) { - final int MAX_VALUE= 10; - - final float random= (float) Math.random(); - float probability= 0; - int i= 0; - while (probability < 1 && i < MAX_VALUE) { - probability += getPoissonDistribution(mean, i); - if (random <= probability) - break; - i++; - } - return i; - } - - private static float getPoissonDistribution(float lambda, int k) { - return (float) (Math.exp(-lambda) * Math.pow(lambda, k) / faculty(k)); - } - - /** - * Returns the faculty of k. - * - * @param k the <code>int</code> for which to get the faculty - * @return the faculty - */ - private static final int faculty(int k) { - return k == 0 - ? 1 - : k * faculty(k - 1); - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java deleted file mode 100644 index deafc45d6..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 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: - * Christian Plesner Hansen (plesner@quenta.org) - initial API and implementation - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; -import org.eclipse.jface.text.source.ICharacterPairMatcher; - -/** - * Tests for the default pair matcher. - * - * @since 3.3 - */ -public class DefaultPairMatcherTest extends AbstractPairMatcherTest { - - public static Test suite() { - return new TestSuite(DefaultPairMatcherTest.class); - } - - protected ICharacterPairMatcher createMatcher(String chars) { - return new DefaultCharacterPairMatcher(chars.toCharArray(), - getDocumentPartitioning()); - } - - /* - * @see org.eclipse.jface.text.tests.AbstractPairMatcherTest#getDocumentPartitioning() - * @since 3.3 - */ - protected String getDocumentPartitioning() { - return IDocumentExtension3.DEFAULT_PARTITIONING; - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultUndoManagerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultUndoManagerTest.java deleted file mode 100644 index ada6b8c39..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/DefaultUndoManagerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.jface.text.DefaultUndoManager; -import org.eclipse.jface.text.IUndoManager; - -/** - * Tests for DefaultUndoManager. - * - * @since 3.2 - */ -public class DefaultUndoManagerTest extends AbstractUndoManagerTest { - - public static Test suite() { - return new TestSuite(DefaultUndoManagerTest.class); - } - - /* - * @see TestCase#TestCase(String) - */ - public DefaultUndoManagerTest(final String name) { - super(name); - } - - /* - * @see org.eclipse.jface.text.tests.AbstractUndoManagerTest#createUndoManager(int) - * @since 3.2 - */ - protected IUndoManager createUndoManager(int maxUndoLevel) { - return new DefaultUndoManager(maxUndoLevel); - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/HTML2TextReaderTester.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/HTML2TextReaderTester.java deleted file mode 100644 index 4fa4c4a55..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/HTML2TextReaderTester.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.jface.internal.text.html.HTML2TextReader; - - -public class HTML2TextReaderTester extends TestCase { - - private static final boolean DEBUG= false; - - private static final String LD= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ - - public HTML2TextReaderTester(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(HTML2TextReaderTester.class); - } - - private void verify(String input, String expectedOutput) throws IOException{ - Reader reader= new StringReader(input); - HTML2TextReader htmlReader= new HTML2TextReader(reader, null); - String result= htmlReader.getString(); - if (DEBUG) - System.out.println("<"+ result +"/>"); - assertEquals(expectedOutput, result); - } - - public void test0() throws IOException{ - String string= "<code>3<5<code>"; - String expected= "3<5"; - verify(string, expected); - } - - public void test1() throws IOException{ - String string= "<dl><dt>@author</dt><dd>Foo Bar</dd></dl>"; - String expected= LD+ "@author"+LD+"\tFoo Bar"+LD; - verify(string, expected); - } - - public void test2() throws IOException{ - String string= "<code>3>5<code>"; - String expected= "3>5"; - verify(string, expected); - } - - public void test3() throws IOException{ - String string= "<a href= \"<p>this is only a string - not a tag<p>\">text</a>"; - String expected= "text"; - verify(string, expected); - } - - public void test4() throws IOException{ - String string= "<html><body text=\"#000000\" bgcolor=\"#FFFF88\"><font size=-1><h5>void p.Bb.fes()</h5><p><dl><dt>Parameters:</dt><dd><b>i</b> fred or <code>null</code></dd></dl></font></body></html>"; - String expected= "void p.Bb.fes()"+ LD + LD + LD+ "Parameters:"+ LD + "\ti fred or null"+LD; - verify(string, expected); - } - - public void test5() throws IOException{ - String string= "<code>1<2<3<4</code>"; - String expected= "1<2<3<4"; - verify(string, expected); - } - - public void test6() throws IOException{ - //test for bug 19070 - String string= "<p>Something.<p>Something more."; - String expected= LD + "Something." + LD + "Something more."; - verify(string, expected); - } - - public void testComments() throws Exception { - String string= "<!-- begin-user-doc -->no comment<!-- end-user-doc -->"; - String expected= "no comment"; - verify(string,expected); - } - -} - diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/JFaceTextTestSuite.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/JFaceTextTestSuite.java deleted file mode 100644 index 8abfeddcb..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/JFaceTextTestSuite.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - - -/** - * Test Suite for org.eclipse.jface.text. - * - * @since 3.0 - */ -public class JFaceTextTestSuite extends TestSuite { - - public static Test suite() { - TestSuite suite= new TestSuite("org.eclipse.jface.text Test Suite using BasicStructuredDocument"); //$NON-NLS-1$ -// suite.addTest(HTML2TextReaderTester.suite()); -// suite.addTest(TextHoverPopupTest.suite()); -// suite.addTest(TextPresentationTest.suite()); - suite.addTest(DefaultUndoManagerTest.suite()); - suite.addTest(TextViewerUndoManagerTest.suite()); -// suite.addTest(RulesTestSuite.suite()); -// suite.addTest(ReconcilerTestSuite.suite()); -// suite.addTest(DefaultPairMatcherTest.suite()); - return suite; - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextEvent.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextEvent.java deleted file mode 100644 index 584d5bb0b..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.TextEvent; - - -public class TestTextEvent extends TextEvent { - - TestTextEvent(DocumentEvent event, String replacedText) { - super(event.getOffset(), event.getLength(), event.getText(), replacedText, event, true); - } - - TestTextEvent(String text) { - super(0, 0, text, (String) null, (DocumentEvent) null, true); - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextViewer.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextViewer.java deleted file mode 100644 index 41859b308..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TestTextViewer.java +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; - -import org.eclipse.jface.viewers.ISelectionProvider; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IAutoIndentStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IEventConsumer; -import org.eclipse.jface.text.IFindReplaceTarget; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextDoubleClickStrategy; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.IUndoManager; -import org.eclipse.jface.text.IViewportListener; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.IAnnotationHover; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; - - - - -public class TestTextViewer implements ISourceViewer, IDocumentListener { - - - protected IDocument fDocument; - protected List fInputListeners= new ArrayList(); - protected List fTextListeners= new ArrayList(); - protected TextPresentation fTextPresentation; - protected Point fSelection= new Point(-1, -1); - protected String fDeletion; - - /** - * @see ITextViewer#setDocument(IDocument, int, int) - */ - public void setDocument(IDocument document, int p1, int p2) { - setDocument(document); - } - - /** - * @see ITextViewer#getDocument() - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * @see ITextViewer#setDocument(IDocument) - */ - public void setDocument(IDocument document) { - IDocument oldDoc= fDocument; - fireTextInputChanged(oldDoc, document, true); - - if (oldDoc != null) - oldDoc.removeDocumentListener(this); - - fDocument= document; - - if (fDocument != null) { - fireTextChanged(new TestTextEvent(fDocument.get())); - fDocument.addDocumentListener(this); - } - - fireTextInputChanged(oldDoc, document, false); - } - - /** - * @see ITextViewer#removeTextInputListener(ITextInputListener) - */ - public void removeTextInputListener(ITextInputListener listener) { - fInputListeners.remove(listener); - } - - /** - * @see ITextViewer#addTextInputListener(ITextInputListener) - */ - public void addTextInputListener(ITextInputListener listener) { - if (!fInputListeners.contains(listener)) - fInputListeners.add(listener); - } - - protected void fireTextInputChanged(IDocument oldDoc, IDocument newDoc, boolean about) { - Iterator e= new ArrayList(fInputListeners).iterator(); - while (e.hasNext()) { - ITextInputListener l= (ITextInputListener) e.next(); - if (about) - l.inputDocumentAboutToBeChanged(oldDoc, newDoc); - else - l.inputDocumentChanged(oldDoc, newDoc); - } - } - - /** - * @see ITextViewer#changeTextPresentation(TextPresentation, boolean) - */ - public void changeTextPresentation(TextPresentation presentation, boolean p1) { - fTextPresentation= presentation; - } - - /** - * @see ITextViewer#invalidateTextPresentation() - */ - public void invalidateTextPresentation() { - } - - public TextPresentation getTextPresentation() { - return fTextPresentation; - } - - public void documentAboutToBeChanged(DocumentEvent event) { - try { - fDeletion= fDocument.get(event.getOffset(), event.getLength()); - } catch (BadLocationException x) { - } - } - - public void documentChanged(DocumentEvent event) { - fireTextChanged(new TestTextEvent(event, fDeletion)); - } - - /** - * @see ITextViewer#getFindReplaceTarget() - */ - public IFindReplaceTarget getFindReplaceTarget() { - return null; - } - - /** - * @see ITextViewer#getTextOperationTarget() - */ - public ITextOperationTarget getTextOperationTarget() { - return null; - } - - /** - * @see ITextViewer#setTextColor(Color, int, int, boolean) - */ - public void setTextColor(Color p0, int p1, int p2, boolean p3) { - } - - /** - * @see ITextViewer#setTextColor(Color) - */ - public void setTextColor(Color p0) { - } - - /** - * @see ITextViewer#overlapsWithVisibleRegion(int, int) - */ - public boolean overlapsWithVisibleRegion(int p0, int p1) { - return false; - } - - /** - * @see ITextViewer#getVisibleRegion() - */ - public IRegion getVisibleRegion() { - return null; - } - - /** - * @see ITextViewer#resetVisibleRegion() - */ - public void resetVisibleRegion() { - } - - /** - * @see ITextViewer#setVisibleRegion(int, int) - */ - public void setVisibleRegion(int p0, int p1) { - } - - /** - * @see ITextViewer#setIndentPrefixes(String[], String) - */ - public void setIndentPrefixes(String[] p0, String p1) { - } - - /** - * @see ITextViewer#setDefaultPrefixes(String[], String) - */ - public void setDefaultPrefixes(String[] p0, String p1) { - } - - /** - * @see ITextViewer#setAutoIndentStrategy(IAutoIndentStrategy, String) - */ - public void setAutoIndentStrategy(IAutoIndentStrategy p0, String p1) { - } - - /** - * @see ITextViewer#setTextDoubleClickStrategy(ITextDoubleClickStrategy, String) - */ - public void setTextDoubleClickStrategy(ITextDoubleClickStrategy p0, String p1) { - } - - /** - * @see ITextViewer#setUndoManager(IUndoManager) - */ - public void setUndoManager(IUndoManager p0) { - } - - /** - * @see ITextViewer#getTextWidget() - */ - public StyledText getTextWidget() { - return null; - } - - public void setTextHover(ITextHover p0, String p1) { - } - - /** - * @see ITextViewer#activatePlugins() - */ - public void activatePlugins() { - } - - /** - * @see ITextViewer#resetPlugins() - */ - public void resetPlugins() { - } - - /** - * @see ITextViewer#getTopInset() - */ - public int getTopInset() { - return 0; - } - - /** - * @see ITextViewer#getBottomIndexEndOffset() - */ - public int getBottomIndexEndOffset() { - return 0; - } - - /** - * @see ITextViewer#getBottomIndex() - */ - public int getBottomIndex() { - return 0; - } - - /** - * @see ITextViewer#getTopIndexStartOffset() - */ - public int getTopIndexStartOffset() { - return 0; - } - - /** - * @see ITextViewer#getTopIndex() - */ - public int getTopIndex() { - return 0; - } - - /** - * @see ITextViewer#setTopIndex(int) - */ - public void setTopIndex(int p0) { - } - - /** - * @see ITextViewer#revealRange(int, int) - */ - public void revealRange(int p0, int p1) { - } - - /** - * @see ITextViewer#getSelectedRange() - */ - public Point getSelectedRange() { - return fSelection; - } - - /** - * @see ITextViewer#setSelectedRange(int, int) - */ - public void setSelectedRange(int offset, int length) { - fSelection.x= offset; - fSelection.y= length; - } - - /** - * @see ITextViewer#isEditable() - */ - public boolean isEditable() { - return true; - } - - /** - * @see ITextViewer#setEditable(boolean) - */ - public void setEditable(boolean p0) { - } - - /** - * @see ITextViewer#setEventConsumer(IEventConsumer) - */ - public void setEventConsumer(IEventConsumer p0) { - } - - /** - * @see ITextViewer#removeTextListener(ITextListener) - */ - public void removeTextListener(ITextListener listener) { - fTextListeners.remove(listener); - } - - protected void fireTextChanged(TextEvent event) { - Iterator e= new ArrayList(fTextListeners).iterator(); - while (e.hasNext()) { - ITextListener l= (ITextListener) e.next(); - l.textChanged(event); - } - } - - /** - * @see ITextViewer#addTextListener(ITextListener) - */ - public void addTextListener(ITextListener listener) { - if (!fTextListeners.contains(listener)) - fTextListeners.add(listener); - } - - /** - * @see ITextViewer#removeViewportListener(IViewportListener) - */ - public void removeViewportListener(IViewportListener p0) { - } - - /** - * @see ITextViewer#addViewportListener(IViewportListener) - */ - public void addViewportListener(IViewportListener p0) { - } - - /** - * @see ISourceViewer#getSelectionProvider() - */ - public ISelectionProvider getSelectionProvider() { - return null; - } - - /** - * @see ISourceViewer#showAnnotations(boolean) - */ - public void showAnnotations(boolean p0) { - } - - /** - * @see ISourceViewer#removeRangeIndication() - */ - public void removeRangeIndication() { - } - - /** - * @see ISourceViewer#getRangeIndication() - */ - public IRegion getRangeIndication() { - return null; - } - - /** - * @see ISourceViewer#setRangeIndication(int, int, boolean) - */ - public void setRangeIndication(int p0, int p1, boolean p2) { - } - - /** - * @see ISourceViewer#setRangeIndicator(Annotation) - */ - public void setRangeIndicator(Annotation p0) { - } - - /** - * @see ISourceViewer#getAnnotationModel() - */ - public IAnnotationModel getAnnotationModel() { - return null; - } - - /** - * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int) - */ - public void setDocument(IDocument p0, IAnnotationModel p1, int p2, int p3) { - } - - /** - * @see ISourceViewer#setDocument(IDocument, IAnnotationModel) - */ - public void setDocument(IDocument p0, IAnnotationModel p1) { - } - - /** - * @see ISourceViewer#setAnnotationHover(IAnnotationHover) - */ - public void setAnnotationHover(IAnnotationHover p0) { - } - - /** - * @see ISourceViewer#configure(SourceViewerConfiguration) - */ - public void configure(SourceViewerConfiguration p0) { - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextHoverPopupTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextHoverPopupTest.java deleted file mode 100644 index abfa697f6..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextHoverPopupTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - - -public class TextHoverPopupTest extends TestCase { - - - public TextHoverPopupTest(String name) { - super(name); - } - - protected void setUp() { - } - - public static Test suite() { - return new TestSuite(TextHoverPopupTest.class); - } - - protected void tearDown() { - } - - - protected int search(int[] array, int x) { - int low= 0; - int high= array.length -1; - - while (high > low) { - int offset= (low + high) / 2; - int lookup= array[offset]; - if (lookup > x) - high= offset - 1; - else if (lookup < x) - low= offset + 1; - else - low= high= offset; - } - - return high; - } - - public void testSearch() { - int[] values= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - for (int i= 0; i < 10; i++) { - int result= search(values, i); - assertTrue(i == result); - } - - int[] values2= { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27 }; - for (int i= 0; i < 10; i++) { - int result= search(values2, i * 3); - assertTrue(i == result); - } - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextPresentationTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextPresentationTest.java deleted file mode 100644 index 689e8dc81..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextPresentationTest.java +++ /dev/null @@ -1,624 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import java.util.Iterator; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextPresentation; - -public class TextPresentationTest extends TestCase { - - private static final int NORMAL= SWT.NORMAL; - private static final int BOLD= SWT.BOLD; -// private static final int ITALIC= SWT.ITALIC; - - private TextPresentation fTextPresentation; - private StyleRange[] fAllRanges; - private StyleRange[] fNonDefaultRanges; - - public static Test suite() { - return new TestSuite(TextPresentationTest.class); - } - - protected void setUp() { - setUpStyleRanges(); - setUpTextPresentation(); - } - - private void setUpStyleRanges() { - fAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL) - }; - - fNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD) - }; - } - - private void setUpTextPresentation() { - fTextPresentation= new TextPresentation(); - fTextPresentation.setDefaultStyleRange(createStyleRange(0, 140, NORMAL)); - for (int i= 0; i < fAllRanges.length; i++) - fTextPresentation.addStyleRange(fAllRanges[i]); - } - - private StyleRange createStyleRange(int start, int end, int style) { - return createStyleRange(start, end, null, null, style); - } - - private StyleRange createStyleRange(int start, int end, Color foreground, Color background, int style) { - return new StyleRange(start, end - start, foreground, background, style); - } - - private StyleRange createStyleRange(int start, int end, int foreground, int background, int style) { - return createStyleRange(start, end, createColor(foreground, foreground, foreground), createColor(background, background, background), style); - } - - private Display fDisplay= Display.getDefault(); - - /** - * Creates a new color. - * - * @param red the amount of red in the color - * @param green the amount of green in the color - * @param blue the amount of blue in the color - * @return <code>null</code> if any of the parameters is smaller than 0 or greater than 255 - */ - private Color createColor(int red, int green, int blue) { - if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) - return null; - return new Color(fDisplay, red, green, blue); - } - - private void checkRegions(StyleRange[] expectedAllRanges, StyleRange[] expectedNonDefaultRanges) { - Iterator e= fTextPresentation.getAllStyleRangeIterator(); - for (int i= 0; i < expectedAllRanges.length; i++) { - assertTrue(e.hasNext()); - assertEquals(expectedAllRanges[i], e.next()); - } - assertTrue(!e.hasNext()); - - e= fTextPresentation.getNonDefaultStyleRangeIterator(); - for (int i= 0; i < expectedNonDefaultRanges.length; i++) { - assertTrue(e.hasNext()); - assertEquals(expectedNonDefaultRanges[i], e.next()); - } - assertTrue(!e.hasNext()); - } - - public void testUnclippedRegions() { - checkRegions(fAllRanges, fNonDefaultRanges); - } - - public void testClippedRegions1() { - fTextPresentation.setResultWindow(new Region(0, 140)); - checkRegions(fAllRanges, fNonDefaultRanges); - } - - public void testClippedRegions2() { - - fTextPresentation.setResultWindow(new Region(30, 70)); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 17, NORMAL), - createStyleRange( 17, 24, BOLD), - createStyleRange( 24, 66, NORMAL), - createStyleRange( 66, 70, BOLD) - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 17, 24, BOLD), - createStyleRange( 66, 70, BOLD) - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at start of first existing range. - */ - public void testMergeStyleRange1() { - StyleRange range= createStyleRange(0, 2, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange(0, 2, 1, -1, NORMAL), - createStyleRange( 2, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange(0, 2, 1, -1, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at end of last existing range. - */ - public void testMergeStyleRange2() { - StyleRange range= createStyleRange(138, 140, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 138, NORMAL), - createStyleRange(138, 140, 1, -1, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - createStyleRange(138, 140, 1, -1, NORMAL), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at start of existing default range. - */ - public void testMergeStyleRange3() { - StyleRange range= createStyleRange(20, 22, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 22, 1, -1, NORMAL), - createStyleRange( 22, 47, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 22, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range within existing default range. - */ - public void testMergeStyleRange4() { - StyleRange range= createStyleRange(22, 24, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 22, NORMAL), - createStyleRange(22, 24, 1, -1, NORMAL), - createStyleRange( 24, 47, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(22, 24, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at end of existing default range. - */ - public void testMergeStyleRange5() { - StyleRange range= createStyleRange(45, 47, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 45, NORMAL), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at start of existing non-default range. - */ - public void testMergeStyleRange6() { - StyleRange range= createStyleRange(47, 49, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range within existing non-default range. - */ - public void testMergeStyleRange7() { - StyleRange range= createStyleRange(49, 51, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 49, BOLD), - createStyleRange(49, 51, 1, -1, BOLD), - createStyleRange( 51, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 49, BOLD), - createStyleRange(49, 51, 1, -1, BOLD), - createStyleRange( 51, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range at end of existing non-default range. - */ - public void testMergeStyleRange8() { - StyleRange range= createStyleRange(52, 54, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range from existing default to non-default range. - */ - public void testMergeStyleRange9() { - StyleRange range= createStyleRange(45, 49, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 45, NORMAL), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range from existing non-default to default range. - */ - public void testMergeStyleRange10() { - StyleRange range= createStyleRange(52, 56, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange(54, 56, 1, -1, NORMAL), - createStyleRange( 56, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange(54, 56, 1, -1, NORMAL), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range from existing default over non-default to default range. - */ - public void testMergeStyleRange11() { - StyleRange range= createStyleRange(45, 56, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 45, NORMAL), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 54, 1, -1, BOLD), - createStyleRange(54, 56, 1, -1, NORMAL), - createStyleRange( 56, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 54, 1, -1, BOLD), - createStyleRange(54, 56, 1, -1, NORMAL), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range from existing non-default over default to non-default range. - */ - public void testMergeStyleRange12() { - StyleRange range= createStyleRange(52, 98, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange(54, 96, 1, -1, NORMAL), - createStyleRange(96, 98, 1, -1, BOLD), - createStyleRange( 98, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange( 47, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange(54, 96, 1, -1, NORMAL), - createStyleRange(96, 98, 1, -1, BOLD), - createStyleRange( 98, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range over existing default range. - */ - public void testMergeStyleRange13() { - StyleRange range= createStyleRange(20, 47, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 47, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 47, 1, -1, NORMAL), - createStyleRange( 47, 54, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - /** - * Merge range over existing non-default range. - */ - public void testMergeStyleRange14() { - StyleRange range= createStyleRange(47, 54, 1, -1, NORMAL); - fTextPresentation.mergeStyleRange(range); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange( 0, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange( 20, 47, NORMAL), - createStyleRange(47, 54, 1, -1, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 140, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange( 4, 20, BOLD), - createStyleRange(47, 54, 1, -1, BOLD), - createStyleRange( 96, 102, BOLD), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - - public void testMergeStyleRanges1() { - StyleRange[] ranges= new StyleRange[] { - createStyleRange(0, 2, 1, -1, NORMAL), // at start of first existing - createStyleRange(20, 22, 1, -1, NORMAL), // at start of existing default - createStyleRange(24, 26, 1, -1, NORMAL), // within existing default - createStyleRange(45, 47, 1, -1, NORMAL), // at end of existing default - createStyleRange(47, 49, 1, -1, NORMAL), // at start of existing non-default - createStyleRange(50, 51, 1, -1, NORMAL), // within existing non-default - createStyleRange(52, 54, 1, -1, NORMAL), // at end of existing non-default - createStyleRange(138, 140, 1, -1, NORMAL), // at end of last existing - }; - fTextPresentation.mergeStyleRanges(ranges); - - StyleRange[] expectedAllRanges= new StyleRange[] { - createStyleRange(0, 2, 1, -1, NORMAL), - createStyleRange( 2, 4, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 22, 1, -1, NORMAL), - createStyleRange( 22, 24, NORMAL), - createStyleRange(24, 26, 1, -1, NORMAL), - createStyleRange( 26, 45, NORMAL), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 50, BOLD), - createStyleRange(50, 51, 1, -1, BOLD), - createStyleRange( 51, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange( 54, 96, NORMAL), - createStyleRange( 96, 102, BOLD), - createStyleRange(102, 138, NORMAL), - createStyleRange(138, 140, 1, -1, NORMAL), - }; - - StyleRange[] expectedNonDefaultRanges= new StyleRange[] { - createStyleRange(0, 2, 1, -1, NORMAL), - createStyleRange( 4, 20, BOLD), - createStyleRange(20, 22, 1, -1, NORMAL), - createStyleRange(24, 26, 1, -1, NORMAL), - createStyleRange(45, 47, 1, -1, NORMAL), - createStyleRange(47, 49, 1, -1, BOLD), - createStyleRange( 49, 50, BOLD), - createStyleRange(50, 51, 1, -1, BOLD), - createStyleRange( 51, 52, BOLD), - createStyleRange(52, 54, 1, -1, BOLD), - createStyleRange( 96, 102, BOLD), - createStyleRange(138, 140, 1, -1, NORMAL), - }; - - checkRegions(expectedAllRanges, expectedNonDefaultRanges); - } - -// Template -// -// public void testMergeStyleRange0() { -//// StyleRange range= createStyleRange(0, 2, 1, -1, NORMAL); -//// fTextPresentation.mergeStyleRange(range); -// -//// StyleRange[] ranges= new StyleRange[] { -//// createStyleRange(0, 2, 1, -1, NORMAL), -//// }; -//// fTextPresentation.mergeStyleRanges(ranges); -// -// StyleRange[] expectedAllRanges= new StyleRange[] { -// createStyleRange( 0, 4, NORMAL), -// createStyleRange( 4, 20, BOLD), -// createStyleRange( 20, 47, NORMAL), -// createStyleRange( 47, 54, BOLD), -// createStyleRange( 54, 96, NORMAL), -// createStyleRange( 96, 102, BOLD), -// createStyleRange(102, 140, NORMAL), -// }; -// -// StyleRange[] expectedNonDefaultRanges= new StyleRange[] { -// createStyleRange( 4, 20, BOLD), -// createStyleRange( 47, 54, BOLD), -// createStyleRange( 96, 102, BOLD), -// }; -// -// checkRegions(expectedAllRanges, expectedNonDefaultRanges); -// } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextViewerUndoManagerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextViewerUndoManagerTest.java deleted file mode 100644 index effd2878d..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/TextViewerUndoManagerTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.operations.AbstractOperation; -import org.eclipse.core.commands.operations.IUndoableOperation; -import org.eclipse.core.commands.operations.OperationHistoryFactory; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import org.eclipse.text.undo.DocumentUndoEvent; -import org.eclipse.text.undo.DocumentUndoManager; -import org.eclipse.text.undo.IDocumentUndoListener; - -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IUndoManager; -import org.eclipse.jface.text.TextViewerUndoManager; - -/** - * Tests for TextViewerUndoManager. - * - * @since 3.2 - */ -public class TextViewerUndoManagerTest extends AbstractUndoManagerTest { - - public static Test suite() { - return new TestSuite(TextViewerUndoManagerTest.class); - } - - /* - * @see TestCase#TestCase(String) - */ - public TextViewerUndoManagerTest(final String name) { - super(name); - } - - /* - * @see org.eclipse.jface.text.tests.AbstractUndoManagerTest#createUndoManager(int) - * @since 3.2 - */ - protected IUndoManager createUndoManager(int maxUndoLevel) { - return new TextViewerUndoManager(maxUndoLevel); - } - - //--- DocumentUndoManager only --- - - public void internalTestTransferNonTextOp(final boolean isUndoable) throws Exception { - Object context= new Object(); - DocumentUndoManager tempUndoManager= new DocumentUndoManager(new Document()); - tempUndoManager.connect(context); - - IUndoableOperation operation= new AbstractOperation("") { - public boolean canUndo() { - return isUndoable; - } - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - return Status.OK_STATUS; - } - public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - return Status.OK_STATUS; - } - public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - return Status.OK_STATUS; - } - }; - operation.addContext(tempUndoManager.getUndoContext()); - OperationHistoryFactory.getOperationHistory().add(operation); - - assertEquals(isUndoable, tempUndoManager.undoable()); - - final DocumentUndoManager undoManager= new DocumentUndoManager(new Document()); - Object newContext= new Object(); - undoManager.connect(newContext); - - undoManager.addDocumentUndoListener(new IDocumentUndoListener() { - public void documentUndoNotification(DocumentUndoEvent event) { - fail(); - } - }); - - undoManager.transferUndoHistory(tempUndoManager); - tempUndoManager.disconnect(context); - - assertEquals(isUndoable, undoManager.undoable()); - undoManager.undo(); - assertEquals(false, undoManager.undoable()); - - undoManager.disconnect(newContext); - } - - public void testTransferNonUndoableNonTextOp() throws Exception { - internalTestTransferNonTextOp(false); - } - - public void testTransferUndoableNonTextOp() throws Exception { - internalTestTransferNonTextOp(true); - } - - public void testCanUndo() throws Exception { - IDocument doc= new Document(); - final DocumentUndoManager undoManager= new DocumentUndoManager(doc); - Object context= new Object(); - undoManager.connect(context); - - undoManager.addDocumentUndoListener(new IDocumentUndoListener() { - - public void documentUndoNotification(DocumentUndoEvent event) { - if (event.getEventType() == DocumentUndoEvent.ABOUT_TO_UNDO) - assertEquals(true, undoManager.undoable()); - else if (event.getEventType() == DocumentUndoEvent.UNDONE) - assertEquals(false, undoManager.undoable()); - } - }); - - doc.set("foo"); - - assertEquals(true, undoManager.undoable()); - undoManager.undo(); - assertEquals(false, undoManager.undoable()); - - undoManager.disconnect(context); - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/AbstractReconcilerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/AbstractReconcilerTest.java deleted file mode 100644 index a20fbaff5..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/AbstractReconcilerTest.java +++ /dev/null @@ -1,367 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests.reconciler; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.text.tests.Accessor; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.reconciler.AbstractReconciler; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.jface.text.tests.TestTextViewer; - - -/** - * Reconciler tests. Uses barrier synchronization and a call log to assert - * correct order of reconciling events. - * - * TODO test reconciler arguments (delay > 0 etc.) - * TODO incremental reconciler tests - * - * @since 3.1 - */ -public class AbstractReconcilerTest extends TestCase { - - /** - * Modified barrier: there are two threads: the main (testing) thread - * creating the barrier, and the reconciler thread. When both threads have - * met at the barrier, the main thread is released and can perform - * assertions while being sure that the reconciler is dormant. After the - * tests have been performed, the main thread must call <code>wakeAll</code> - * to release the reconciler thread. - */ - static class Barrier { - private final Object fMutex= new Object(); - private final int fParticipants; - private final Thread fMainThread; - - private int fWaiting= 0; - private boolean fMainThreadArrived= false; - private boolean fIsInactive= false; - - Barrier() { - fParticipants= 2; - fMainThread= Thread.currentThread(); - } - - public void await() { - synchronized (fMutex) { - if (fIsInactive) - return; - - fWaiting++; - - boolean isMainThread= Thread.currentThread() == fMainThread; - if (isMainThread) - fMainThreadArrived= true; - - if (allArrived()) { - if (!fMainThreadArrived) { - fWaiting--; - throw new RuntimeException(getClass() + " can't join barrier if only the main thread is missing!"); - } - - if (!isMainThread) - notifyMainThread(); - } - if (!allArrived() || !isMainThread) { - try { - if (!isMainThread) - fMutex.wait(); - else { - fMutex.wait(5000); // don't wait forever for bad reconcilers - if (!allArrived()) - fail("reconciler never ran in 5 seconds"); - } - } catch (InterruptedException e) { - // threads must not be interrupted - throw new Error(); - } - } - } - } - - private boolean allArrived() { - return fWaiting == fParticipants; - } - - private void notifyMainThread() { - fMutex.notify(); - } - - public void wakeAll() { - synchronized (fMutex) { - fWaiting= 0; - fMainThreadArrived= false; - fMutex.notifyAll(); - } - } - - public void shutdown() { - synchronized (fMutex) { - fIsInactive= true; - fMutex.notifyAll(); - } - } - } - - private Accessor fAccessor; - private Barrier fBarrier; - private List fCallLog; - private ITextViewer fViewer; - protected AbstractReconciler fReconciler; - private Document fDocument; - - protected void setUp() { - fBarrier= new Barrier(); - fCallLog= Collections.synchronizedList(new ArrayList()); - fReconciler= new AbstractReconciler() { - protected void initialProcess() { - fCallLog.add("initialProcess"); - fBarrier.await(); - } - protected void process(DirtyRegion dirtyRegion) { - fCallLog.add("process"); - fBarrier.await(); - } - protected void reconcilerDocumentChanged(IDocument newDocument) { - fCallLog.add("reconcilerDocumentChanged"); - } - protected void aboutToBeReconciled() { - fCallLog.add("aboutToBeReconciled"); - } - protected void reconcilerReset() { - fCallLog.add("reconcilerReset"); - } - public IReconcilingStrategy getReconcilingStrategy(String contentType) { - return null; - } - }; - fReconciler.setIsIncrementalReconciler(false); - fReconciler.setDelay(50); // make tests run faster - - fViewer= new TestTextViewer(); - fReconciler.install(fViewer); - - fAccessor= new Accessor(fReconciler, AbstractReconciler.class); - Object object= fAccessor.get("fThread"); - fAccessor= new Accessor(object, object.getClass()); - } - - - protected void tearDown() throws Exception { - fBarrier.shutdown(); - fReconciler.uninstall(); - } - - public void testInitialReconcile() throws InterruptedException { - // initially the reconciler is neither active nor dirty - // XXX shouldn't it be dirty? - assertFalse(isActive()); - assertFalse(isDirty()); - - // set up initial document - fDocument= new Document("foo"); - fViewer.setDocument(fDocument); - assertEquals("reconcilerDocumentChanged", fCallLog.remove(0)); - assertEquals("aboutToBeReconciled", fCallLog.remove(0)); - - fBarrier.await(); - assertEquals("initialProcess", fCallLog.remove(0)); - // XXX shouldn't it be dirty and active during initialProcess? - assertFalse(isActive()); - assertFalse(isDirty()); - fBarrier.wakeAll(); - - // wait until clean - pollUntilClean(); - assertFalse(isActive()); - assertFalse(isDirty()); - } - - public void testDirtyingWhenClean() throws BadLocationException, InterruptedException { - installDocument(); - - dirty(); - assertEquals("aboutToBeReconciled", fCallLog.remove(0)); - assertEquals("reconcilerReset", fCallLog.remove(0)); - - fBarrier.await(); - assertEquals("process", fCallLog.remove(0)); - assertTrue(isActive()); - assertTrue(isDirty()); - fBarrier.wakeAll(); - - // wait until clean - pollUntilClean(); - assertFalse(isActive()); - assertFalse(isDirty()); - } - - - private void dirty() throws BadLocationException { - fDocument.replace(0,0,"bar"); - } - - - public void testDirtyingWhenRunning() throws InterruptedException, BadLocationException { - installDocument(); - - dirty(); - fBarrier.await(); - assertTrue(isActive()); - assertTrue(isDirty()); - fCallLog.clear(); - dirty(); - // no aboutToBeReconciled since the reconciler is still running - // when the second edition comes in - assertEquals("reconcilerReset", fCallLog.remove(0)); - fBarrier.wakeAll(); - - fBarrier.await(); - assertEquals("process", fCallLog.remove(0)); - fBarrier.wakeAll(); - pollUntilClean(); - assertFalse(isActive()); - assertFalse(isDirty()); - } - - public void testCancellingWhenClean() throws InterruptedException, BadLocationException { - installDocument(); - - // dirty again - dirty(); - fBarrier.await(); - fBarrier.wakeAll(); - - // cancel - fCallLog.clear(); - fReconciler.uninstall(); - pollUntilInactive(); - assertTrue(fCallLog.isEmpty()); - assertFalse(isActive()); - // XXX fails since AbstractReconciler does not update state before leaving -// assertFalse(isDirty()); // fails - } - - public void testCancellingWhenRunning() throws InterruptedException, BadLocationException { - installDocument(); - - // dirty and cancel - dirty(); - fBarrier.await(); - fCallLog.clear(); - fReconciler.uninstall(); - fBarrier.wakeAll(); - pollUntilInactive(); - assertTrue(fCallLog.isEmpty()); - assertFalse(isActive()); - // XXX fails since AbstractReconciler does not update state before leaving -// assertFalse(isDirty()); - } - - public void testReplacingDocumentWhenClean() throws InterruptedException { - installDocument(); - - // replace - fCallLog.clear(); - fViewer.setDocument(new Document("bar")); - assertEquals("reconcilerDocumentChanged", fCallLog.remove(0)); - assertEquals("aboutToBeReconciled", fCallLog.remove(0)); - assertEquals("reconcilerReset", fCallLog.remove(0)); - fBarrier.await(); - assertEquals("process", fCallLog.remove(0)); - fBarrier.wakeAll(); - - pollUntilClean(); - assertFalse(isActive()); - assertFalse(isDirty()); - } - - public void testReplacingDocumentWhenRunning() throws InterruptedException, BadLocationException { - installDocument(); - - // dirty and replace - dirty(); - fBarrier.await(); - fCallLog.clear(); - fViewer.setDocument(new Document("bar")); - assertEquals("reconcilerDocumentChanged", fCallLog.remove(0)); - assertEquals("reconcilerReset", fCallLog.remove(0)); - assertTrue(fCallLog.isEmpty()); - fBarrier.wakeAll(); - - // XXX this fails, which is a bug - replacing the document should - // cancel the progress monitor -// fBarrier.await(); -// assertEquals("process", fCallLog.remove(0)); -// fBarrier.wakeAll(); - } - - void installDocument() throws InterruptedException { - fDocument= new Document("foo"); - fViewer.setDocument(fDocument); - - // initial process - fBarrier.await(); - fBarrier.wakeAll(); - - pollUntilClean(); - fCallLog.clear(); - } - - void pollUntilClean() throws InterruptedException { - // wait for reconciler to become clean - long start= System.currentTimeMillis(); - while (isDirty()) { - long current= System.currentTimeMillis(); - if (current > start + 5000) - fail("waited > 5s for reconciler to complete"); - synchronized (this) { - wait(50); - } - } - } - - void pollUntilInactive() throws InterruptedException { - // wait for reconciler to become clean - long start= System.currentTimeMillis(); - while (isActive()) { - long current= System.currentTimeMillis(); - if (current > start + 5000) - fail("waited > 5s for reconciler to complete"); - synchronized (this) { - wait(50); - } - } - } - - boolean isActive() { - Object bool= fAccessor.invoke("isActive", null); - return ((Boolean) bool).booleanValue(); - } - - boolean isDirty() { - Object bool= fAccessor.invoke("isDirty", null); - return ((Boolean) bool).booleanValue(); - } - - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/ReconcilerTestSuite.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/ReconcilerTestSuite.java deleted file mode 100644 index 32dfe189e..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/reconciler/ReconcilerTestSuite.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - *******************************************************************************/ - -package org.eclipse.jface.text.tests.reconciler; - -import junit.framework.Test; -import junit.framework.TestSuite; - - -/** - * - * @since 3.0 - */ -public class ReconcilerTestSuite { - - public static Test suite() { - TestSuite suite= new TestSuite("Test Suite org.eclipse.jface.text.tests.reconciler"); - //$JUnit-BEGIN$ - suite.addTestSuite(AbstractReconcilerTest.class); - //$JUnit-END$ - return suite; - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java deleted file mode 100644 index 4dc114b07..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests.rules; - -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.rules.DefaultPartitioner; -import org.eclipse.jface.text.rules.IPartitionTokenScanner; - -public class DefaultPartitionerTest extends FastPartitionerTest { - protected IDocumentPartitioner createPartitioner(IPartitionTokenScanner scanner) { - return new DefaultPartitioner(scanner, new String[] { DEFAULT, COMMENT }); - } - - /* - * @see org.eclipse.jface.text.tests.rules.FastPartitionerTest#testPR130900() - */ - public void testPR130900() throws Exception { - System.out.println("Bug130900 not fixed in DefaultPartitioner"); - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java deleted file mode 100644 index 9e1792aa2..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/DefaultPartitionerZeroLengthTest.java +++ /dev/null @@ -1,265 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - *******************************************************************************/ - -package org.eclipse.jface.text.tests.rules; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.rules.FastPartitioner; -import org.eclipse.jface.text.rules.IPartitionTokenScanner; -import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.MultiLineRule; -import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; -import org.eclipse.jface.text.rules.Token; - - -/** - * @since 3.0 - */ -public class DefaultPartitionerZeroLengthTest extends TestCase { - - private static final String COMMENT= "comment"; - private static final String DEFAULT= IDocument.DEFAULT_CONTENT_TYPE; - - private IDocument fDoc; - private FastPartitioner fPartitioner; - - public void setUp() { - fDoc= new Document(); - IPartitionTokenScanner scanner= new RuleBasedPartitionScanner() { - { - IToken comment= new Token(COMMENT); - IPredicateRule[] rules= new IPredicateRule[] { new MultiLineRule("/*", "*/", comment) }; - setPredicateRules(rules); - - } - }; - fPartitioner= new FastPartitioner(scanner, new String[] { DEFAULT, COMMENT }); - fDoc.setDocumentPartitioner(fPartitioner); - fPartitioner.connect(fDoc); - } - - public void testGetZeroLengthPartition() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertGetZeroLengthPartition_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthPartitionEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertGetZeroLengthPartition_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthPartitionEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertGetZeroLengthPartition_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthPartitionEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertGetZeroLengthPartition_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthContentType() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertGetZeroLengthContentType_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthContentTypeEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertGetZeroLengthContentType_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthContentTypeEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertGetZeroLengthContentType_InterleavingPartitions(offsets); - } - - public void testGetZeroLengthContentTypeEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertGetZeroLengthContentType_InterleavingPartitions(offsets); - } - - public void testComputeZeroLengthPartitioning() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(offsets); - } - - public void testComputeZeroLengthPartitioningEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(offsets); - } - - public void testComputeZeroLengthPartitioningEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(offsets); - } - - public void testComputeZeroLengthPartitioningEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(offsets); - } - - public void testComputePartitioningSubrangeBeforeBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(12, 38, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeOnBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(13, 39, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeOnBoundaries2() { - fDoc.set("/* comment *//* comment *//* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(13, 26, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeAfterBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 26, 26, 39 }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(14, 40, offsets, COMMENT); - } - - public void testComputePartitioningSubrangeInBoundaries1() { - fDoc.set("/* comment */"); - - int[] offsets= new int[] { }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(1, 12, offsets, COMMENT); - } - - public void testComputePartitioningSubrangeInBoundaries2() { - fDoc.set("docu ment"); - - int[] offsets= new int[] { }; - assertComputeZeroLengthPartitioning_InterleavingPartitions(1, 12, offsets, DEFAULT); - } - - private void assertComputeZeroLengthPartitioning_InterleavingPartitions(int[] offsets) { - assertComputeZeroLengthPartitioning_InterleavingPartitions(0, fDoc.getLength(), offsets, DEFAULT); - } - - private void assertComputeZeroLengthPartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) { - ITypedRegion[] regions= fPartitioner.computePartitioning(startOffset, endOffset - startOffset, true); - - String type= startType; - int previousOffset= startOffset; - - assertEquals(offsets.length + 1, regions.length); - for (int i= 0; i <= offsets.length; i++) { - int currentOffset= (i == offsets.length) ? endOffset : offsets[i]; - ITypedRegion region= regions[i]; - - assertTypedRegion(region, previousOffset, currentOffset, type); - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= currentOffset; - } - } - - private void assertGetZeroLengthContentType_InterleavingPartitions(int[] offsets) { - String type= DEFAULT; - int previousOffset= 0; - for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; - assertEqualPartitionType(previousOffset, offset, type); - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= offset; - } - } - - private void assertGetZeroLengthPartition_InterleavingPartitions(int[] offsets) { - String type= DEFAULT; - int previousOffset= 0; - for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; - assertEqualPartition(previousOffset, offset, type); - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= offset; - } - } - - private boolean isOpenType(String type) { - return type.equals(DEFAULT); - } - - private void assertEqualPartition(int offset, int inclusiveEnd, String type) { - int from= isOpenType(type) ? offset : offset + 1; - int to= isOpenType(type) ? inclusiveEnd : inclusiveEnd - 1; - for (int i= from; i <= to; i++) { - ITypedRegion region= fPartitioner.getPartition(i, true); - assertTypedRegion(region, offset, inclusiveEnd, type); - } - } - - private void assertTypedRegion(ITypedRegion region, int offset, int inclusiveEnd, String type) { - assertEquals(offset, region.getOffset()); - assertEquals(inclusiveEnd - offset, region.getLength()); - assertEquals(type, region.getType()); - } - - private void assertEqualPartitionType(int offset, int inclusiveEnd, String type) { - int from= isOpenType(type) ? offset : offset + 1; - int to= isOpenType(type) ? inclusiveEnd : inclusiveEnd - 1; - for (int i= from; i <= to; i++) { - assertEquals(type, fPartitioner.getContentType(i, true)); - } - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/FastPartitionerTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/FastPartitionerTest.java deleted file mode 100644 index f67016165..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/FastPartitionerTest.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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 - *******************************************************************************/ - -package org.eclipse.jface.text.tests.rules; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.rules.FastPartitioner; -import org.eclipse.jface.text.rules.IPartitionTokenScanner; -import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.MultiLineRule; -import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.Token; - - -/** - * @since 3.0 - */ -public class FastPartitionerTest extends TestCase { - - protected static final String COMMENT= "comment"; - protected static final String DEFAULT= IDocument.DEFAULT_CONTENT_TYPE; - - private IDocument fDoc; - private IDocumentPartitioner fPartitioner; - - public void setUp() { - fDoc= new Document(); - IPartitionTokenScanner scanner= new RuleBasedPartitionScanner() { - { - IToken comment= new Token(COMMENT); - IPredicateRule[] rules= new IPredicateRule[] { new MultiLineRule("/*", "*/", comment) }; - setPredicateRules(rules); - - } - }; - fPartitioner= createPartitioner(scanner); - fDoc.setDocumentPartitioner(fPartitioner); - fPartitioner.connect(fDoc); - } - - protected IDocumentPartitioner createPartitioner(IPartitionTokenScanner scanner) { - return new FastPartitioner(scanner, new String[] { DEFAULT, COMMENT }); - } - - public void testGetPartition() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertGetPartition_InterleavingPartitions(offsets); - } - - public void testGetPartitionEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertGetPartition_InterleavingPartitions(offsets); - } - - public void testGetPartitionEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertGetPartition_InterleavingPartitions(offsets); - } - - public void testGetPartitionEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertGetPartition_InterleavingPartitions(offsets); - } - - public void testGetContentType() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertGetContentType_InterleavingPartitions(offsets); - } - - public void testGetContentTypeEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertGetContentType_InterleavingPartitions(offsets); - } - - public void testGetContentTypeEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertGetContentType_InterleavingPartitions(offsets); - } - - public void testGetContentTypeEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertGetContentType_InterleavingPartitions(offsets); - } - - public void testComputePartitioning() { - fDoc.set("docu ment/* comment */docu ment"); - - int[] offsets= new int[] { 13, 26 }; - assertComputePartitioning_InterleavingPartitions(offsets); - } - - public void testComputePartitioningEmptyMiddle() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertComputePartitioning_InterleavingPartitions(offsets); - } - - public void testComputePartitioningEmptyStart() { - fDoc.set("/* comment */docu ment"); - - int[] offsets= new int[] { 0, 13 }; - assertComputePartitioning_InterleavingPartitions(offsets); - } - - public void testComputePartitioningEmptyEnd() { - fDoc.set("docu ment/* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertComputePartitioning_InterleavingPartitions(offsets); - } - - public void testComputePartitioningSubrangeBeforeBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26 }; - assertComputePartitioning_InterleavingPartitions(12, 38, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeOnBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 13, 26, 26, 39 }; - assertComputePartitioning_InterleavingPartitions(13, 39, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeOnBoundaries2() { - fDoc.set("/* comment *//* comment *//* comment */"); - - int[] offsets= new int[] { 13, 26 }; - assertComputePartitioning_InterleavingPartitions(13, 26, offsets, DEFAULT); - } - - public void testComputePartitioningSubrangeAfterBoundaries() { - fDoc.set("docu ment/* comment *//* comment */docu ment"); - - int[] offsets= new int[] { 26, 26, 39 }; - assertComputePartitioning_InterleavingPartitions(14, 40, offsets, COMMENT); - } - - public void testComputePartitioningSubrangeInBoundaries1() { - fDoc.set("/* comment */"); - - int[] offsets= new int[] { }; - assertComputePartitioning_InterleavingPartitions(1, 12, offsets, COMMENT); - } - - public void testComputePartitioningSubrangeInBoundaries2() { - fDoc.set("docu ment"); - - int[] offsets= new int[] { }; - assertComputePartitioning_InterleavingPartitions(1, 12, offsets, DEFAULT); - } - - public void testPR101014() throws BadLocationException { - fDoc.set( - "package pr101014;\n" + - "\n" + - "class X {\n" + - "String s= \n" + - " /*foo*/;\n" + - "}\n"); - - int[] offsets= {41, 48}; - assertComputePartitioning_InterleavingPartitions(offsets); - - fDoc.replace(40, 8, " /*foo*/"); - assertComputePartitioning_InterleavingPartitions(offsets); - } - - public void testPR130900() throws Exception { - fPartitioner.disconnect(); - IPartitionTokenScanner scanner= new RuleBasedPartitionScanner() { - { - IToken comment= new Token(COMMENT); - IPredicateRule[] rules= new IPredicateRule[] { new SingleLineRule("#", null, comment, (char) 0, true, false) }; - setPredicateRules(rules); - } - }; - fPartitioner= createPartitioner(scanner); - fDoc.setDocumentPartitioner(fPartitioner); - fPartitioner.connect(fDoc); - - fDoc.set("#"); - int[] offsets= new int[] { 0, 1 }; - assertComputePartitioning_InterleavingPartitions(offsets); - - } - - private void assertComputePartitioning_InterleavingPartitions(int[] offsets) { - assertComputePartitioning_InterleavingPartitions(0, fDoc.getLength(), offsets, DEFAULT); - } - - private void assertComputePartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) { - ITypedRegion[] regions= fPartitioner.computePartitioning(startOffset, endOffset - startOffset); - - String type= startType; - int previousOffset= startOffset; - - int j= 0; - for (int i= 0; i <= offsets.length; i++) { - int currentOffset= (i == offsets.length) ? endOffset : offsets[i]; - if (currentOffset - previousOffset != 0) { // don't do empty partitions - ITypedRegion region= regions[j++]; - - assertTypedRegion(region, previousOffset, currentOffset, type); - } - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= currentOffset; - } - } - - private void assertGetContentType_InterleavingPartitions(int[] offsets) { - String type= DEFAULT; - int previousOffset= 0; - for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; - assertEqualPartitionType(previousOffset, offset, type); - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= offset; - } - } - - private void assertGetPartition_InterleavingPartitions(int[] offsets) { - String type= DEFAULT; - int previousOffset= 0; - for (int i= 0; i <= offsets.length; i++) { - int offset= (i == offsets.length) ? fDoc.getLength() : offsets[i]; - assertEqualPartition(previousOffset, offset, type); - - // advance - if (type == DEFAULT) - type= COMMENT; - else - type= DEFAULT; - previousOffset= offset; - } - } - - private void assertEqualPartition(int offset, int end, String type) { - int from= offset; - int to= end - 1; - for (int i= from; i <= to; i++) { - ITypedRegion region= fPartitioner.getPartition(i); - assertTypedRegion(region, offset, end, type); - } - } - - private void assertTypedRegion(ITypedRegion region, int offset, int end, String type) { - assertEquals(offset, region.getOffset()); - assertEquals(end - offset, region.getLength()); - assertEquals(type, region.getType()); - } - - private void assertEqualPartitionType(int offset, int end, String type) { - int from= offset; - int to= end - 1; - for (int i= from; i <= to; i++) { - assertEquals(type, fPartitioner.getContentType(i)); - } - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/RulesTestSuite.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/RulesTestSuite.java deleted file mode 100644 index 48deb6de6..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/RulesTestSuite.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests.rules; - -import junit.framework.Test; -import junit.framework.TestSuite; - - -/** - * @since 3.0 - */ -public class RulesTestSuite { - - public static Test suite() { - TestSuite suite= new TestSuite( - "Test Suite org.eclipse.jface.text.tests.rules"); - // $JUnit-BEGIN$ - suite.addTestSuite(FastPartitionerTest.class); - suite.addTestSuite(DefaultPartitionerTest.class); - suite.addTestSuite(DefaultPartitionerZeroLengthTest.class); - suite.addTestSuite(WordRuleTest.class); - suite.addTestSuite(ScannerColumnTest.class); - // $JUnit-END$ - return suite; - } -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/ScannerColumnTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/ScannerColumnTest.java deleted file mode 100644 index 1b0c8b670..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/ScannerColumnTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests.rules; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; -import org.eclipse.jface.text.rules.RuleBasedScanner; - - -/** - * @since 3.4 - */ -public class ScannerColumnTest extends TestCase { - - private IDocument fDocument; - - protected void setUp() throws Exception { - fDocument= new Document("scanner test"); - } - - protected void tearDown() throws Exception { - fDocument= null; - } - - public void testRuleBasedScannerColumnRead() { - _testScannerColumnRead(new RuleBasedScanner()); - } - - public void testRuleBasedScannerColumnUnread() { - _testScannerColumnUnread(new RuleBasedScanner()); - } - - public void testBufferedRuleBasedScannerColumnRead() { - _testScannerColumnRead(new BufferedRuleBasedScanner(100)); - } - - public void testBufferedRuleBasedScannerColumnUnread() { - _testScannerColumnUnread(new BufferedRuleBasedScanner(100)); - } - - private void _testScannerColumnRead(RuleBasedScanner scanner) { - scanner.setRange(fDocument, 0, 10); - assertEquals(0, scanner.getColumn()); - assertEquals('s', scanner.read()); - assertEquals(1, scanner.getColumn()); - scanner.unread(); - assertEquals(0, scanner.getColumn()); - } - - private void _testScannerColumnUnread(RuleBasedScanner scanner) { - scanner.setRange(fDocument, 0, 10); - assertEquals(0, scanner.getColumn()); - assertEquals('s', scanner.read()); - assertEquals(1, scanner.getColumn()); - scanner.unread(); - assertEquals(0, scanner.getColumn()); - } - -} diff --git a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/WordRuleTest.java b/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/WordRuleTest.java deleted file mode 100644 index 6f5ecfd11..000000000 --- a/tests/org.eclipse.wst.sse.ui.tests/jface.text.tests/org/eclipse/jface/text/tests/rules/WordRuleTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 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 - *******************************************************************************/ -package org.eclipse.jface.text.tests.rules; - -import junit.framework.TestCase; - -import org.eclipse.swt.SWT; - -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.PatternRule; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WordRule; - -/** - * @since 3.3 - */ -public class WordRuleTest extends TestCase { - - - private static class SimpleWordDetector implements IWordDetector { - public boolean isWordStart(char c) { - return !Character.isWhitespace(c); - } - - public boolean isWordPart(char c) { - return !Character.isWhitespace(c); - } - } - - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=163116 - */ - public void testBug163116() throws Exception { - IWordDetector detector= new IWordDetector() { - - public boolean isWordPart(char c) { - return true; - } - - public boolean isWordStart(char c) { - return true; - } - - }; - - WordRule rule= new WordRule(detector, new Token(this)); - - RuleBasedScanner scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] { rule }); - scanner.setRange(new Document(), 0, 0); - - IToken token= null; - int i= 0; - while (token != Token.EOF && i++ < 1000) - token= scanner.nextToken(); - - assertTrue(i < 1000); - - } - - /* - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=144355 - */ - public void testBug144355() throws Exception { - IWordDetector detector= new SimpleWordDetector(); - - String defaultTokenString= "defaultToken"; - Token defaultToken= new Token(defaultTokenString); - - String testTokenStringNormal= "TestTokenString"; - String testTokenStringDifferentCapitalization= "TestTOKENString"; - String testTokenStringCompletelyDifferent= "XXX"; - Token normalToken= new Token(testTokenStringNormal); - - WordRule rule= new WordRule(detector, defaultToken, true); - rule.addWord(testTokenStringNormal, normalToken); - - // scenario 1 - // pre: pass in a normal string ("TestTokenString") - // post: expect the normal token to be returned - RuleBasedScanner scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] {rule}); - scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length()); - assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal)); - - // scenario 2 - // pre: pass in a normal string but different capitalization ("TestTOKENString") - // post: expect the normal token to be returned - scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] {rule}); - scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length()); - assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal)); - - // scenario 3 - // pre: pass in a completely different string ("XXX") - // post: expect the default token to be returned because the string can't be matched - scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] {rule}); - scanner.setRange(new Document(testTokenStringCompletelyDifferent), 0, testTokenStringCompletelyDifferent.length()); - assertTrue(scanner.nextToken().getData().equals(defaultTokenString)); - - WordRule ruleWithoutIgnoreCase= new WordRule(detector, defaultToken); - ruleWithoutIgnoreCase.addWord(testTokenStringNormal, normalToken); - - // scenario 4 - // pre: pass in a normal string ("TestTokenString") - // post: expect the normal token to be returned - scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] {ruleWithoutIgnoreCase}); - scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length()); - assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal)); - - // scenario 5 - // pre: pass in a normal string but different capitalization ("TestTOKENString") - // post: expect the default token to be returned - scanner= new RuleBasedScanner(); - scanner.setRules(new IRule[] {ruleWithoutIgnoreCase}); - scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length()); - assertTrue(scanner.nextToken().getData().equals(defaultTokenString)); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712 - public void testBug175712_1() throws Exception { - IRule[] rules= new IRule[2]; - - IToken stepToken= new Token(new TextAttribute(null, null, SWT.BOLD)); - PatternRule stepRule= new PatternRule("(((", ")", stepToken, (char) 0,false); - stepRule.setColumnConstraint(-1); - rules[1]= stepRule; - - IToken titleToken= new Token(new TextAttribute(null, null, SWT.BOLD)); - WordRule wordRule= new WordRule(new SimpleWordDetector()); - wordRule.addWord("((", titleToken); - rules[0]= wordRule; - - IDocument document= new Document("((( \n((\n- Cheese\n- Wine"); - RuleBasedScanner scanner= new RuleBasedScanner(); - scanner.setRules(rules); - scanner.setRange(document, 0, document.getLength()); - - IToken defaultToken= new Token(this); - scanner.setDefaultReturnToken(defaultToken); - - IToken token= scanner.nextToken(); - assertSame(defaultToken, token); - - token= scanner.nextToken(); - assertSame(defaultToken, token); - - token= scanner.nextToken(); - assertSame(defaultToken, token); - - token= scanner.nextToken(); - assertSame(titleToken, token); - - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712 - public void testBug175712_2() throws Exception { - IRule[] rules= new IRule[2]; - - IToken stepToken= new Token(new TextAttribute(null, null, SWT.BOLD)); - PatternRule stepRule= new PatternRule("(((", ")", stepToken, (char) 0,false); - stepRule.setColumnConstraint(-1); - rules[1]= stepRule; - - IToken titleToken= new Token(new TextAttribute(null, null, SWT.BOLD)); - WordRule wordRule= new WordRule(new SimpleWordDetector()); - wordRule.addWord("((", titleToken); - rules[0]= wordRule; - - IDocument document= new Document("((\n((\n- Cheese\n- Wine"); - RuleBasedScanner scanner= new RuleBasedScanner(); - scanner.setRules(rules); - scanner.setRange(document, 0, document.getLength()); - - IToken defaultToken= new Token(this); - scanner.setDefaultReturnToken(defaultToken); - - IToken token= scanner.nextToken(); - assertSame(titleToken, token); - - } - - -} |