Commits

Anonymous committed 69afab0

(no commit message)

Comments (0)

Files changed (6)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.lispdev.editor.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+#Mon Jun 29 17:54:16 BST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

META-INF/MANIFEST.MF

+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Lisp Editor Test
+Bundle-SymbolicName: org.lispdev.editor.test
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: org.lispdev.editor;bundle-version="0.0.1"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit4
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

src/org/lispdev/editor/test/LispPartitionerTest.java

+package org.lispdev.editor.test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TypedRegion;
+import org.eclipse.jface.text.rules.IToken;
+import org.junit.Test;
+import org.lispdev.editor.ColorManager;
+import org.lispdev.editor.EditorPlugin;
+import org.lispdev.editor.LispPartitioner;
+import org.lispdev.editor.LispScanner;
+import org.lispdev.parser.tokens.TokenMLC;
+import org.lispdev.parser.tokens.TokenOutline;
+import org.lispdev.parser.tokens.TokenSLC;
+import org.lispdev.parser.tokens.TokenString;
+import org.lispdev.parser.tokens.TokenSymbol;
+
+public class LispPartitionerTest
+{
+
+  @Test
+  public void simplePartitioning()
+  {
+    final String code = "(defun f (x) \"thidss is a string\")\n\n\n\n"
+        + "(defun g (xad) \"2223\" 32)\n\n\n\n"
+        + "(a 1. a 2 \"aadfdaadfafdfa\" )";
+
+    Document doc = new Document(code);
+    LispPartitioner lp = new LispPartitioner();
+    lp.connect(doc);
+    ITypedRegion[] ac = lp.computePartitioning(0, doc.getLength());
+
+    ITypedRegion[] ex = new TypedRegion[]{
+        new TypedRegion(0, 34, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(34, 4, IDocument.DEFAULT_CONTENT_TYPE),
+        new TypedRegion(38, 25, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(63, 4, IDocument.DEFAULT_CONTENT_TYPE),
+        new TypedRegion(67, 28, LispPartitioner.TOP_LEVEL_FORM)};
+
+    assertArrayEquals(ex, ac);
+
+    ac = lp.computePartitioning(40, 38);
+    ex = new TypedRegion[]{
+        new TypedRegion(40, 23, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(63, 4, IDocument.DEFAULT_CONTENT_TYPE),
+        new TypedRegion(67, 11, LispPartitioner.TOP_LEVEL_FORM)};
+
+    assertArrayEquals(ex, ac);
+
+    assertNotNull(EditorPlugin.get().getAst(doc));
+  }
+
+  @Test
+  public void docChanged()
+  {
+    final String code = "(defun f (x) \"thidss is a string\")\n\n\n\n"
+        + "(defun g (xad) \"2223\" 32)\n\n\n\n"
+        + "(a 1. a 2 \"aadfdaadfafdfa\" )";
+
+    Document doc = new Document(code);
+    LispPartitioner lp = new LispPartitioner();
+    lp.connect(doc);
+    doc.setDocumentPartitioner(lp);
+
+    ITypedRegion[] ex = null;
+    ITypedRegion[] ac = null;
+
+    try
+    {
+      doc.replace(58, 1, ""); // removes " before 32
+      ac = doc.computePartitioning(0, doc.getLength());
+    }
+    catch(BadLocationException e)
+    {
+      e.printStackTrace();
+    }
+    ex = new TypedRegion[]{
+        new TypedRegion(0, 34, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(34, 4, IDocument.DEFAULT_CONTENT_TYPE),
+        new TypedRegion(38, 28, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(66, 28, LispPartitioner.TOP_LEVEL_FORM)
+        };
+    assertArrayEquals(ex, ac);
+
+    try
+    {
+      doc.replace(76, 1, ""); // removes " before aadfdaadfafdfa
+      ac = doc.computePartitioning(0, doc.getLength());
+    }
+    catch(BadLocationException e)
+    {
+      e.printStackTrace();
+    }
+    ex = new TypedRegion[]{
+        new TypedRegion(0, 34, LispPartitioner.TOP_LEVEL_FORM),
+        new TypedRegion(34, 4, IDocument.DEFAULT_CONTENT_TYPE),
+        new TypedRegion(38, 55, LispPartitioner.TOP_LEVEL_FORM)};
+    assertArrayEquals(ex, ac);
+  }
+
+  @Test
+  public void lispScannerTest1()
+  {
+    final String code = "(defun f (x) \"thidss is a string\" (1 2 \"this\"))";
+
+    Document doc = new Document(code);
+
+    ColorManager colorManager = EditorPlugin.get().getColorManager();
+    LispScanner scanner = new LispScanner();
+    scanner.addTokenType(TokenString.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_STRING)));
+    scanner.addTokenType(TokenSymbol.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_NUMBER)));
+
+    scanner.setRange(doc, 0, doc.getLength());
+    int[] acOffset = new int[19];
+    int[] acLength = new int[19];
+    int i = 0;
+    IToken token = scanner.nextToken();
+    while( !token.isEOF() )
+    {
+      acOffset[i] = scanner.getTokenOffset();
+      acLength[i] = scanner.getTokenLength();
+      ++i;
+      token = scanner.nextToken();
+    }
+    int[] exOffset = new int[]{0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 33, 34,
+        35, 36, 37, 38, 39, 45, 46};
+    int[] exLength = new int[]{1, 5, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1,
+        1, 1, 1, 6, 1, 1};
+    assertArrayEquals(exOffset, acOffset);
+    assertArrayEquals(exLength, acLength);
+  }
+
+ // @Test
+  public void lispScannerTest2()
+  {
+    // testing last hidden without real tokens
+    final String code = "(a f (x) \"this is a string\" "
+      + "(\"and this\" 1) \"finally this\")\n\n"
+      + "\n;;;;; 0.1 section\n"
+      + "(a 1 2 \"tt\")\n"
+      + ";;;; 1. section"
+      + "\n;;;;; 1.1 section \n\n"
+      + "(defun g (x) 3)\n\n"
+      + ";;;; 2. section";
+
+    Document doc = new Document(code);
+
+    ColorManager colorManager = EditorPlugin.get().getColorManager();
+    LispScanner scanner = new LispScanner();
+    scanner.addTokenType(TokenString.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_STRING)));
+    scanner.addTokenType(TokenSymbol.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_NUMBER)));
+    TextAttribute commentAttribute =
+      new TextAttribute(colorManager.getColor(ColorManager.DEFAULT_COMMENT));
+    scanner.addTokenType(TokenMLC.class, commentAttribute);
+    scanner.addTokenType(TokenSLC.class, commentAttribute);
+    scanner.addTokenType(TokenOutline.class, commentAttribute);
+
+    scanner.setRange(doc, 0, doc.getLength());
+    int[] acOffset = new int[23];
+    int[] acLength = new int[23];
+    int i = 0;
+    IToken token = scanner.nextToken();
+    while( !token.isEOF() )
+    {
+      acOffset[i] = scanner.getTokenOffset();
+      acLength[i] = scanner.getTokenLength();
+      ++i;
+      token = scanner.nextToken();
+    }
+    int[] exOffset = new int[]{0, 9,27,29,39,40,41,43,57,61,79,82,83,84,85,
+        86,90,92,108,127,141,142,145};
+    int[] exLength = new int[]{9,18, 2,10, 1, 1, 2,14, 4,18, 3, 1, 1, 1, 1,
+         4, 2,16, 19, 14,  1,  3, 15};
+    assertArrayEquals(exOffset, acOffset);
+    assertArrayEquals(exLength, acLength);
+  }
+
+ // @Test
+  public void lispScannerTest3()
+  {
+    // testing extending range to include last single line comment
+    final String code = "(a f (x) \"this is a string\" "
+      + "(\"and this\" 1) \"finally this\")\n\n"
+      + "\n;;;;; 0.1 section\n"
+      + "(a 1 2 \"tt\")\n"
+      + ";;;; 1. section"
+      + "\n;;;;; 1.1 section \n\n"
+      + "(defun g (x) 3)\n\n"
+      + ";;;; 2. section";
+
+    Document doc = new Document(code);
+
+    ColorManager colorManager = EditorPlugin.get().getColorManager();
+    LispScanner scanner = new LispScanner();
+    scanner.addTokenType(TokenString.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_STRING)));
+    scanner.addTokenType(TokenSymbol.class, new TextAttribute(colorManager
+        .getColor(ColorManager.DEFAULT_NUMBER)));
+    TextAttribute commentAttribute =
+      new TextAttribute(colorManager.getColor(ColorManager.DEFAULT_COMMENT));
+    scanner.addTokenType(TokenMLC.class, commentAttribute);
+    scanner.addTokenType(TokenSLC.class, commentAttribute);
+    scanner.addTokenType(TokenOutline.class, commentAttribute);
+
+    scanner.setRange(doc, 91, 16);
+    int[] acOffset = new int[2];
+    int[] acLength = new int[2];
+    int i = 0;
+    IToken token = scanner.nextToken();
+    while( !token.isEOF() )
+    {
+      acOffset[i] = scanner.getTokenOffset();
+      acLength[i] = scanner.getTokenLength();
+      ++i;
+      token = scanner.nextToken();
+    }
+    int[] exOffset = new int[]{91,92};
+    int[] exLength = new int[]{ 1,16};
+    assertArrayEquals(exOffset, acOffset);
+    assertArrayEquals(exLength, acLength);
+  }
+
+}