SmallSense__CompletionEngineTests.st
changeset 234 97857872ee47
child 238 d5a32e41181f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SmallSense__CompletionEngineTests.st	Fri May 23 12:58:31 2014 +0100
@@ -0,0 +1,87 @@
+"{ Encoding: utf8 }"
+
+"{ Package: 'jv:smallsense' }"
+
+"{ NameSpace: SmallSense }"
+
+Smalltalk::TestCase subclass:#CompletionEngineTests
+	instanceVariableNames:'engine context result'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'SmallSense-Tests'
+!
+
+!CompletionEngineTests class methodsFor:'queries'!
+
+isAbstract
+    "Return if this class is an abstract class.
+     True is returned here for myself only; false for subclasses.
+     Abstract subclasses must redefine again."
+
+    ^ self == SmallSense::CompletionEngineTests.
+! !
+
+!CompletionEngineTests methodsFor:'accessing'!
+
+environment
+   ^ Smalltalk
+
+    "Created: / 22-05-2014 / 16:50:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CompletionEngineTests methodsFor:'accessing-classes'!
+
+completionEngineClass
+    ^ self subclassResponsibility
+
+    "Created: / 22-05-2014 / 16:38:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CompletionEngineTests methodsFor:'running'!
+
+setUp
+    | service support codeView |
+    engine := self completionEngineClass new.
+
+    codeView := Tools::CodeView2 new.
+    service := EditService new.
+    service registerIn: codeView.  
+    support := GenericEditSupport new.
+    service updateSupport: support.  
+    context := CompletionContext new.
+    context support: support.
+    context environment: self environment.
+
+    "Created: / 22-05-2014 / 16:50:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+tearDown
+    engine := context := nil
+
+    "Created: / 22-05-2014 / 16:51:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CompletionEngineTests methodsFor:'utilities'!
+
+complete: aString
+     | list textView |
+
+    list := aString asStringCollection.
+    textView := context codeView textView.
+    textView list: list.
+    1 to: list size do:[:i |  
+        | line cursorCol |
+
+        line := list at: i.
+        cursorCol := line indexOf: '┃' first.
+        cursorCol ~~ 0 ifTrue:[ 
+            line := (line copyTo: cursorCol - 1) , (line copyFrom: cursorCol + 1).
+            list at: i put: line.
+            textView setCursorLine: i; setCursorCol: cursorCol.
+        ].
+    ].
+    ^ result := engine complete: context
+
+    "Created: / 22-05-2014 / 16:56:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+