Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 210773 Details for
Bug 9503
Brace and parenthesis matching is one-off
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
patch for platform text tests
text-Bug-9503-Brace-and-parenthesis-matching-is-oneoff.txt (text/plain), 10.81 KB, created by
Deepak Azad
on 2012-02-08 23:44:15 EST
(
hide
)
Description:
patch for platform text tests
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2012-02-08 23:44:15 EST
Size:
10.81 KB
patch
obsolete
>diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java >index 1d6e394..2e7f6e0 100644 >--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java >+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2012 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 >@@ -26,6 +26,7 @@ > 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.DefaultCharacterPairMatcher; > import org.eclipse.jface.text.source.ICharacterPairMatcher; > > /** >@@ -44,6 +45,17 @@ > protected abstract ICharacterPairMatcher createMatcher(final String chars); > > /** >+ * Constructs a new character pair matcher. >+ * >+ * @param chars the characters to match >+ * @param caretInsideMatchedPair controls the matching behavior >+ * @return the character pair matcher >+ */ >+ protected ICharacterPairMatcher createMatcher(final String chars, boolean caretInsideMatchedPair) { >+ return new DefaultCharacterPairMatcher(chars.toCharArray(), getDocumentPartitioning(), caretInsideMatchedPair); >+ } >+ >+ /** > * Returns the partitioning treated by the matcher. > * > * @return the partition >@@ -59,14 +71,6 @@ > } > > /* --- 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. >@@ -105,12 +109,10 @@ > */ > public void testCloseMatches() throws BadLocationException { > final ICharacterPairMatcher matcher= createMatcher("()[]{}"); >- performMatch(matcher, "#()%"); > performMatch(matcher, "(%)#"); > performMatch(matcher, "#(())%"); > performMatch(matcher, "(%())#"); > performMatch(matcher, "((%)#)"); >- performMatch(matcher, "(#()%)"); > matcher.dispose(); > } > >@@ -125,7 +127,6 @@ > performMatch(matcher, "(% "); > performMatch(matcher, "%( )"); > performMatch(matcher, "( % )"); >- performMatch(matcher, "( %)"); > performMatch(matcher, "%"); > matcher.dispose(); > } >@@ -217,9 +218,10 @@ > * @param expectedPos the expected position > * @param expectedMatch the expected match > * @param expectedString the expected string >+ * @param caretInsideMatchedPair controls the matching behavior > */ >- private void performReaderTest(String testString, int expectedPos, int expectedMatch, String expectedString) { >- TestCase t0= createTestCase(testString); >+ protected void performReaderTest(String testString, int expectedPos, int expectedMatch, String expectedString, boolean caretInsideMatchedPair) { >+ TestCase t0= createTestCase(testString, caretInsideMatchedPair); > assertEquals(expectedPos, t0.fPos); > assertEquals(expectedMatch, t0.fMatch); > assertEquals(expectedString, t0.fString); >@@ -231,8 +233,17 @@ > * @param matcher the matcher > * @param testCase the test string > */ >- protected void performMatch(final ICharacterPairMatcher matcher, final String testCase) { >- final TestCase test= createTestCase(testCase); >+ protected abstract void performMatch(final ICharacterPairMatcher matcher, final String testCase); >+ >+ /** >+ * Checks that the given matcher matches the input as specified. >+ * >+ * @param matcher the matcher >+ * @param testCase the test string >+ * @param caretInsideMatchedPair controls the matching behavior >+ */ >+ protected void performMatch(final ICharacterPairMatcher matcher, final String testCase, boolean caretInsideMatchedPair) { >+ final TestCase test= createTestCase(testCase, caretInsideMatchedPair); > matcher.clear(); > final IRegion region= matcher.match(test.getDocument(), test.fPos); > if (test.fMatch == -1) { >@@ -244,11 +255,11 @@ > 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 >+ // If the match is forward, the cursor 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; >+ final int length= (isForward && !caretInsideMatchedPair) ? test.getLength() : test.getLength() + 1; > assertEquals(length, region.getLength()); > assertEquals(offset, region.getOffset()); > } >@@ -265,12 +276,23 @@ > * cursor and a '#' represents the position of the expected matching character. > * > * @param str the string for which to create the test case >+ * @param caretInsideMatchedPair controls the matching behavior > * @return the created test case > */ >- public TestCase createTestCase(String str) { >+ public TestCase createTestCase(String str, boolean caretInsideMatchedPair) { > int pos= str.indexOf("%"); > assertFalse(pos == -1); > int match= str.indexOf("#"); >+ >+ if (caretInsideMatchedPair) { >+ if (pos - 1 >= 0) { >+ char ch= str.charAt(pos - 1); >+ if ("()[]{}<>".indexOf(ch) % 2 == 1) { >+ pos-= 1; >+ } >+ } >+ } >+ > // account for the length of the first position marker, > // if there is one > if (match != -1 && match < pos) pos -= 1; >diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java >index a59d0ec..f4fc950 100644 >--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java >+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2012 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 >@@ -13,8 +13,8 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.jface.text.BadLocationException; > import org.eclipse.jface.text.IDocumentExtension3; >-import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; > import org.eclipse.jface.text.source.ICharacterPairMatcher; > > /** >@@ -24,13 +24,18 @@ > */ > public class DefaultPairMatcherTest extends AbstractPairMatcherTest { > >+ private static final boolean fgCaretInsideMatchedPair= false; >+ > public static Test suite() { > return new TestSuite(DefaultPairMatcherTest.class); > } > > protected ICharacterPairMatcher createMatcher(String chars) { >- return new DefaultCharacterPairMatcher(chars.toCharArray(), >- getDocumentPartitioning()); >+ return super.createMatcher(chars, fgCaretInsideMatchedPair); >+ } >+ >+ protected void performMatch(ICharacterPairMatcher matcher, String testCase) { >+ super.performMatch(matcher, testCase, fgCaretInsideMatchedPair); > } > > /* >@@ -41,4 +46,36 @@ > return IDocumentExtension3.DEFAULT_PARTITIONING; > } > >+ /** Tests that the test case reader works */ >+ public void testTestCaseReader() { >+ performReaderTest("#( )%", 3, 0, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("%( )#", 0, 3, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("( )%", 3, -1, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("#%", 0, 0, "", fgCaretInsideMatchedPair); >+ } >+ >+ /** >+ * Close matches. >+ * >+ * @throws BadLocationException >+ */ >+ public void testCloseMatches1() throws BadLocationException { >+ final ICharacterPairMatcher matcher= createMatcher("()[]{}"); >+ performMatch(matcher, "#()%"); >+ performMatch(matcher, "(#()%)"); >+ matcher.dispose(); >+ } >+ >+ >+ /** >+ * Checks of simple situations where no matches should be found. >+ * >+ * @throws BadLocationException >+ */ >+ public void testIncompleteMatch1() throws BadLocationException { >+ final ICharacterPairMatcher matcher= createMatcher("()[]{}"); >+ performMatch(matcher, "( %)"); >+ matcher.dispose(); >+ } >+ > } >diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest2.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest2.java >new file mode 100644 >index 0000000..06bed4b >--- /dev/null >+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest2.java >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 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.IDocumentExtension3; >+import org.eclipse.jface.text.source.ICharacterPairMatcher; >+ >+/** >+ * Tests for the default pair matcher. >+ * >+ * @since 3.8 >+ */ >+public class DefaultPairMatcherTest2 extends AbstractPairMatcherTest { >+ >+ private static final boolean fgCaretInsideMatchedPair= true; >+ >+ public static Test suite() { >+ return new TestSuite(DefaultPairMatcherTest2.class); >+ } >+ >+ protected ICharacterPairMatcher createMatcher(String chars) { >+ return super.createMatcher(chars, fgCaretInsideMatchedPair); >+ } >+ >+ protected void performMatch(ICharacterPairMatcher matcher, String testCase) { >+ super.performMatch(matcher, testCase, fgCaretInsideMatchedPair); >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.tests.AbstractPairMatcherTest#getDocumentPartitioning() >+ * @since 3.3 >+ */ >+ protected String getDocumentPartitioning() { >+ return IDocumentExtension3.DEFAULT_PARTITIONING; >+ } >+ >+ /** Tests that the test case reader works */ >+ public void testTestCaseReader() { >+ performReaderTest("#( )%", 2, 0, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("%( )#", 0, 3, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("( )%", 2, -1, "( )", fgCaretInsideMatchedPair); >+ performReaderTest("#%", 0, 0, "", fgCaretInsideMatchedPair); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 9503
:
210597
|
210598
|
210603
|
210646
|
210651
|
210731
|
210732
|
210772
| 210773