2 * Created on 28.04.2003
5 package net.sourceforge.phpeclipse.phpeditor.php.test;
7 import org.eclipse.jface.text.*;
8 import org.eclipse.jface.text.rules.*;
10 import net.sourceforge.phpeclipse.phpeditor.php.*;
11 import junit.framework.*;
14 * Testcase for the PHPPartitionScanner
15 * @author Stefan Langer
16 * @version $Revision: 1.1 $
18 public class PHPPartitionScannerTest extends TestCase
20 private PHPPartitionScanner fScanner;
21 private IDocument fDocument;
24 * @see junit.framework.TestCase#setUp()
26 protected void setUp() throws Exception
28 fScanner = new PHPPartitionScanner();
29 fDocument = new DummyDocument();
32 public void testPHPPartition()
36 + "$test = \"<?php this is a dummy text ?>\";\n"
41 fScanner.setRange(fDocument, 0, fDocument.getLength());
42 IToken token = fScanner.nextToken();
43 junit.framework.Assert.assertEquals(
44 IPHPPartitionScannerConstants.PHP,
45 (String) token.getData());
46 junit.framework.Assert.assertEquals(
47 fDocument.getLength(),
48 fScanner.getTokenLength());
49 junit.framework.Assert.assertEquals(0, fScanner.getTokenOffset());
52 public void testHTMLPartition()
55 "<html><head><title>Some Text</title></head><body>"
56 + "<h1>Test</h1><p>Nothing particular</body></html>";
58 fScanner.setRange(fDocument, 0, fDocument.getLength());
59 IToken token = fScanner.nextToken();
60 junit.framework.Assert.assertEquals(
61 IPHPPartitionScannerConstants.HTML,
62 (String) token.getData());
63 junit.framework.Assert.assertEquals(
64 fDocument.getLength(),
65 fScanner.getTokenLength());
66 junit.framework.Assert.assertEquals(0, fScanner.getTokenOffset());
69 public void testPHPMultiLineCommentPartition()
71 String text = "<?php $test=\"Some data\";";
73 "/** A comment with some data \n"
74 + " * @param test A test parameter \n"
77 "\nfunction test($test)\n"
79 + " echo \"Test <?php ?>\";\n"
81 fDocument.set(text + text2 + text3);
82 fScanner.setRange(fDocument, 0, fDocument.getLength());
84 IToken token = fScanner.nextToken();
85 junit.framework.Assert.assertEquals(
86 "PHP Partition part 1 not recognized!",
87 IPHPPartitionScannerConstants.PHP,
88 (String) token.getData());
89 junit.framework.Assert.assertEquals(
90 "Length of PHP Partition part 1 not correct!",
92 fScanner.getTokenLength());
93 junit.framework.Assert.assertEquals(
94 "Offset of PHP Partition part 1 not correct!",
96 fScanner.getTokenOffset());
97 // check for multiline
98 token = fScanner.nextToken();
99 junit.framework.Assert.assertEquals(
100 "PHP Multiline not recognized!",
101 IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
102 (String) token.getData());
103 junit.framework.Assert.assertEquals(
104 "Length of PHP Multinline not correct!",
106 fScanner.getTokenLength());
107 junit.framework.Assert.assertEquals(
108 "Offset of PHP Multiline not correct!",
110 fScanner.getTokenOffset());
112 token = fScanner.nextToken();
113 junit.framework.Assert.assertEquals(
114 "PHP Partition part 2 not recognized!",
115 IPHPPartitionScannerConstants.PHP,
116 (String) token.getData());
117 junit.framework.Assert.assertEquals(
118 "Length of PHP Partition part 2 not correct!",
120 fScanner.getTokenLength());
121 junit.framework.Assert.assertEquals(
122 "Offset of PHP Partition part 2 not correct!",
123 text.length() + text2.length(),
124 fScanner.getTokenOffset());