Moved testcase for partitionscanner from phpeclipse.php to phpeclipse.tests to elimin...
authormusk <musk>
Wed, 30 Apr 2003 18:13:50 +0000 (18:13 +0000)
committermusk <musk>
Wed, 30 Apr 2003 18:13:50 +0000 (18:13 +0000)
net.sourceforge.phpeclipse.tests/plugin.xml
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java [new file with mode: 0644]
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java [new file with mode: 0644]
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java

index 46a5d57..7cbb00e 100644 (file)
@@ -9,13 +9,13 @@
       <library name="coretests.jar"/>
    </runtime>
    <requires>
-      <import plugin="org.eclipse.core.resources"/>
       <import plugin="org.eclipse.ui"/>
-      <import plugin="org.eclipse.help"/>
-      <import plugin="org.eclipse.swt"/>
-      <import plugin="org.eclipse.debug.ui"/>
-      <import plugin="org.apache.xerces"/>
       <import plugin="org.junit"/>
-      <import plugin="org.eclipse.update.ui"/>
+      <import plugin="net.sourceforge.phpeclipse"/>
+      <import plugin="org.eclipse.core.runtime"/>
+      <import plugin="org.eclipse.jface.text"/>
+      <import plugin="org.eclipse.core.resources"/>
    </requires>
+
+
 </plugin>
diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DummyDocument.java
new file mode 100644 (file)
index 0000000..19ba311
--- /dev/null
@@ -0,0 +1,391 @@
+/*
+ * Created on 28.04.2003
+ *
+ */
+package net.sourceforge.phpeclipse.phpeditor.php.test;
+
+import org.eclipse.jface.text.*;
+
+/** 
+ * Mockobject for Testing.
+ * 
+ * @author Stefan Langer
+ * @version $Revision: 1.1 $
+ */
+public class DummyDocument implements IDocument
+{
+       private char[] fTextBuffer;
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getChar(int)
+     */
+    public char getChar(int offset) throws BadLocationException
+    {
+       if(offset >= 0 && offset < fTextBuffer.length)
+               return fTextBuffer[offset];
+        else
+               throw new BadLocationException("Offset out of range!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLength()
+     */
+    public int getLength()
+    {
+        return fTextBuffer.length;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#get()
+     */
+    public String get()
+    {
+        return String.copyValueOf(fTextBuffer);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#get(int, int)
+     */
+    public String get(int offset, int length) throws BadLocationException
+    {
+       if(offset >= 0 && (offset + length) < fTextBuffer.length)
+               return String.copyValueOf(fTextBuffer, offset, length);
+        else
+               throw new BadLocationException("Out of range!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#set(java.lang.String)
+     */
+    public void set(String text)
+    {
+       fTextBuffer = text.toCharArray();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String)
+     */
+    public void replace(int offset, int length, String text)
+        throws BadLocationException
+    {
+        throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addDocumentListener(org.eclipse.jface.text.IDocumentListener)
+     */
+    public void addDocumentListener(IDocumentListener listener)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removeDocumentListener(org.eclipse.jface.text.IDocumentListener)
+     */
+    public void removeDocumentListener(IDocumentListener listener)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addPrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
+     */
+    public void addPrenotifiedDocumentListener(IDocumentListener documentAdapter)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removePrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
+     */
+    public void removePrenotifiedDocumentListener(IDocumentListener documentAdapter)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String)
+     */
+    public void addPositionCategory(String category)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String)
+     */
+    public void removePositionCategory(String category)
+        throws BadPositionCategoryException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getPositionCategories()
+     */
+    public String[] getPositionCategories()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String)
+     */
+    public boolean containsPositionCategory(String category)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position)
+     */
+    public void addPosition(Position position) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removePosition(org.eclipse.jface.text.Position)
+     */
+    public void removePosition(Position position)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+     }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
+     */
+    public void addPosition(String category, Position position)
+        throws BadLocationException, BadPositionCategoryException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+     }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
+     */
+    public void removePosition(String category, Position position)
+        throws BadPositionCategoryException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String)
+     */
+    public Position[] getPositions(String category)
+        throws BadPositionCategoryException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#containsPosition(java.lang.String, int, int)
+     */
+    public boolean containsPosition(String category, int offset, int length)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#computeIndexInCategory(java.lang.String, int)
+     */
+    public int computeIndexInCategory(String category, int offset)
+        throws BadLocationException, BadPositionCategoryException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater)
+     */
+    public void addPositionUpdater(IPositionUpdater updater)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater)
+     */
+    public void removePositionUpdater(IPositionUpdater updater)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater, int)
+     */
+    public void insertPositionUpdater(IPositionUpdater updater, int index)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getPositionUpdaters()
+     */
+    public IPositionUpdater[] getPositionUpdaters()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLegalContentTypes()
+     */
+    public String[] getLegalContentTypes()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getContentType(int)
+     */
+    public String getContentType(int offset) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getPartition(int)
+     */
+    public ITypedRegion getPartition(int offset) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#computePartitioning(int, int)
+     */
+    public ITypedRegion[] computePartitioning(int offset, int length)
+        throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#addDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
+     */
+    public void addDocumentPartitioningListener(IDocumentPartitioningListener listener)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#removeDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
+     */
+    public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#setDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)
+     */
+    public void setDocumentPartitioner(IDocumentPartitioner partitioner)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getDocumentPartitioner()
+     */
+    public IDocumentPartitioner getDocumentPartitioner()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineLength(int)
+     */
+    public int getLineLength(int line) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineOfOffset(int)
+     */
+    public int getLineOfOffset(int offset) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineOffset(int)
+     */
+    public int getLineOffset(int line) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineInformation(int)
+     */
+    public IRegion getLineInformation(int line) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineInformationOfOffset(int)
+     */
+    public IRegion getLineInformationOfOffset(int offset)
+        throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getNumberOfLines()
+     */
+    public int getNumberOfLines()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getNumberOfLines(int, int)
+     */
+    public int getNumberOfLines(int offset, int length)
+        throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#computeNumberOfLines(java.lang.String)
+     */
+    public int computeNumberOfLines(String text)
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters()
+     */
+    public String[] getLegalLineDelimiters()
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int)
+     */
+    public String getLineDelimiter(int line) throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String, boolean, boolean, boolean)
+     */
+    public int search(
+        int startOffset,
+        String findString,
+        boolean forwardSearch,
+        boolean caseSensitive,
+        boolean wholeWord)
+        throws BadLocationException
+    {
+               throw new UnsupportedOperationException("Not implemented!");
+    }
+
+}
diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java
new file mode 100644 (file)
index 0000000..c94f098
--- /dev/null
@@ -0,0 +1,457 @@
+/*
+ * Created on 28.04.2003
+ *
+ */
+package net.sourceforge.phpeclipse.phpeditor.php.test;
+
+import junit.framework.*;
+import net.sourceforge.phpeclipse.phpeditor.php.*;
+
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.rules.*;
+
+/**
+ * Testcase for the PHPPartitionScanner
+ * @author Stefan Langer
+ * @version $Revision: 1.1 $
+ */
+public class PHPPartitionScannerTest extends TestCase
+{
+       private PHPPartitionScanner fScanner;
+       private IDocument fDocument;
+       
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        fScanner = new PHPPartitionScanner();   
+        fDocument = new DummyDocument();     
+    }
+
+    public void testPHPPartition()
+    {
+        String text =
+            "<?php\n"
+                + "$test = \"<?php this is a dummy text ?>\";\n"
+                + "function test()\n"
+                + "{echo 'Test!';}\n"
+                + "?>";
+        fDocument.set(text);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            fDocument.getLength(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(0, fScanner.getTokenOffset());
+    }
+
+    public void testBrokenPHPPartition()
+    {
+        String text =
+            "<?php\n"
+                + "$test = \"<?php this is a dummy text ?>;\n"
+                + "function test()\n"
+                + "{echo 'Tes";
+        fDocument.set(text);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            fDocument.getLength(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(0, fScanner.getTokenOffset());
+    }
+    
+    public void testPHP_PHPCOMMENT_HTML_Partition()
+    {
+        String php1 = "<? echo \"This is php with\"; ";
+        String phpcomment1 = "/** @param This is a comment ?> */";
+        String php2 = "echo \" short tags enabled!\"; ?>";
+        String html1 = "<html><head><title>";
+        String php3 =
+            "<? echo \"/** this is no comment */The ?> <?php Title\"?>";
+        String html2 = "</title></head><body>";
+        String php4 = "<? echo \"Some text ?>\"\n\r";
+        String phpcomment2 =
+            "/** This is another comment @param test @return test*/";
+        String php5 = " echo \" just to fill up another php partition\"?>";
+        String html3 = "<p>Copyright 2003 by PHPEclipse</body></html>";
+
+        fDocument.set(
+            php1
+                + phpcomment1
+                + php2
+                + html1
+                + php3
+                + html2
+                + php4
+                + phpcomment2
+                + php5
+                + html3);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        // php 1
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 1 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 1 not correct!",
+            php1.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 1 not correct!",
+            0,
+            fScanner.getTokenOffset());
+        // comment1  
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHPComment Partition 1 not recognized!",
+            IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHPComment Partition 1 not correct!",
+            phpcomment1.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHPComment Partition 1 not correct!",
+            php1.length(),
+            fScanner.getTokenOffset());
+
+        // php 2
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 2 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 2 not correct!",
+            php2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 2 not correct!",
+            php1.length() + phpcomment1.length(),
+            fScanner.getTokenOffset());
+
+        // check html 1
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 1 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 1 not correct!",
+            html1.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 1 not correct!",
+            php1.length() + phpcomment1.length() + php2.length(),
+            fScanner.getTokenOffset());
+
+        //     php 3
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 3 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 3 not correct!",
+            php3.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 3 not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length(),
+            fScanner.getTokenOffset());
+
+        //     check html 2
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 2 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 2 not correct!",
+            html2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 2 not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length()
+                + php3.length(),
+            fScanner.getTokenOffset());
+
+        //     php 4
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 4 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 4 not correct!",
+            php4.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 4 not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length()
+                + php3.length()
+                + html2.length(),
+            fScanner.getTokenOffset());
+
+        //     check comment 2
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Multilinecomment 2 not recognized!",
+            IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Multilinecomment 2  not correct!",
+            phpcomment2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Multilinecomment 2  not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length()
+                + php3.length()
+                + html2.length()
+                + php4.length(),
+            fScanner.getTokenOffset());
+
+        //     php 5
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 5 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 5 not correct!",
+            php5.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 5 not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length()
+                + php3.length()
+                + html2.length()
+                + php4.length()
+                + phpcomment2.length(),
+            fScanner.getTokenOffset());
+        //     check html 3
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 3 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 3 not correct!",
+            html3.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 3 not correct!",
+            php1.length()
+                + phpcomment1.length()
+                + php2.length()
+                + html1.length()
+                + php3.length()
+                + html2.length()
+                + php4.length()
+                + phpcomment2.length()
+                + php5.length(),
+            fScanner.getTokenOffset());
+
+    }
+
+    public void testPHP_HTML_Partition()
+    {
+        String php1 = "<? echo \"This is php with short tags enabled!\"; ?>";
+        String html1 = "<html><head><title>";
+        String php2 = "<? echo \"The ?> <?php Title\"?>";
+        String html2 = "</title></head><body>";
+        String php3 =
+            "<? echo \"Some text ?> just to fill up another php partition\"?>";
+        String html3 = "<p>Copyright 2003 by PHPEclipse</body></html>";
+
+        fDocument.set(php1 + html1 + php2 + html2 + php3 + html3);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        // php 1
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 1 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 1 not correct!",
+            php1.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 1 not correct!",
+            0,
+            fScanner.getTokenOffset());
+        // check html 1
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 1 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 1 not correct!",
+            html1.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 1 not correct!",
+            php1.length(),
+            fScanner.getTokenOffset());
+        //     php 2
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 2 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 2 not correct!",
+            php2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 2 not correct!",
+            html1.length() + php1.length(),
+            fScanner.getTokenOffset());
+        //     check html 2
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 2 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 2 not correct!",
+            html2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 2 not correct!",
+            php1.length() + html1.length() + php2.length(),
+            fScanner.getTokenOffset());
+        //     php 3
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition 3 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition 3 not correct!",
+            php3.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition 3 not correct!",
+            html2.length() + php2.length() + html1.length() + php1.length(),
+            fScanner.getTokenOffset());
+        //     check html 3
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "HTML 3 not recognized!",
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of HTML 3 not correct!",
+            html3.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of HTML 3 not correct!",
+            php1.length()
+                + html1.length()
+                + php2.length()
+                + html2.length()
+                + php3.length(),
+            fScanner.getTokenOffset());
+    }
+
+    public void testHTMLPartition()
+    {
+        String text =
+            "<html><head><title>Some Text</title></head><body>"
+                + "<h1>Test</h1><p>Nothing particular</body></html>";
+        fDocument.set(text);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            IPHPPartitionScannerConstants.HTML,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            fDocument.getLength(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(0, fScanner.getTokenOffset());
+    }
+
+    public void testPHPMultiLineCommentPartition()
+    {
+        String text = "<?php $test=\"Some <?php ?> /** */ data\";";
+        String text2 =
+            "/** A comment with <?php This is acutally not a php partition ?> some data \n"
+                + " * @param test A test parameter \n"
+                + " */";
+        String text3 =
+            "\nfunction test($test)\n"
+                + "{\n"
+                + "    echo \"Test <?php /** This is not a comment */function alsoItLooksLikeOne(){echo \"It is actually not a comment\";} ?>\";\n"
+                + "}?>";
+        fDocument.set(text + text2 + text3);
+        fScanner.setRange(fDocument, 0, fDocument.getLength());
+        // first half of php
+        IToken token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition part 1 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition part 1 not correct!",
+            text.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition part 1 not correct!",
+            0,
+            fScanner.getTokenOffset());
+        // check for multiline
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Multiline not recognized!",
+            IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Multinline not correct!",
+            text2.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Multiline not correct!",
+            text.length(),
+            fScanner.getTokenOffset());
+        // rest of php
+        token = fScanner.nextToken();
+        junit.framework.Assert.assertEquals(
+            "PHP Partition part 2 not recognized!",
+            IPHPPartitionScannerConstants.PHP,
+            (String) token.getData());
+        junit.framework.Assert.assertEquals(
+            "Length of PHP Partition part 2 not correct!",
+            text3.length(),
+            fScanner.getTokenLength());
+        junit.framework.Assert.assertEquals(
+            "Offset of PHP Partition part 2 not correct!",
+            text.length() + text2.length(),
+            fScanner.getTokenOffset());
+    }
+}
index 4a21c36..6091e18 100644 (file)
@@ -7,11 +7,10 @@ which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/cpl-v10.html
 **********************************************************************/
 
-import net.sourceforge.phpdt.internal.compiler.parser.Parser;
-import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import junit.framework.*;
+import net.sourceforge.phpdt.internal.compiler.parser.*;
 
-import org.eclipse.core.runtime.CoreException;
-import junit.framework.TestCase;
+import org.eclipse.core.runtime.*;
 
 /**
  *  Tests the php parser