aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/XiteQt.py4
-rw-r--r--test/XiteWin.py33
-rw-r--r--test/simpleTests.py59
3 files changed, 77 insertions, 19 deletions
diff --git a/test/XiteQt.py b/test/XiteQt.py
index d1ee5ea6b..b5900a308 100644
--- a/test/XiteQt.py
+++ b/test/XiteQt.py
@@ -18,6 +18,10 @@ scintillaScriptsDirectory = os.path.join(scintillaDirectory, "scripts")
sys.path.append(scintillaScriptsDirectory)
import Face
+scintillaIncludesLexers = False
+# Lexilla may optionally be tested it is built and can be loaded
+lexillaAvailable = False
+
class Form(QDialog):
def __init__(self, parent=None):
diff --git a/test/XiteWin.py b/test/XiteWin.py
index 158a2a83e..4d4179818 100644
--- a/test/XiteWin.py
+++ b/test/XiteWin.py
@@ -19,6 +19,10 @@ from MessageNumbers import msgs, sgsm
import ScintillaCallable
import XiteMenu
+scintillaIncludesLexers = False
+# Lexilla may optionally be tested it is built and can be loaded
+lexillaAvailable = False
+
scintillaDirectory = ".."
scintillaIncludeDirectory = os.path.join(scintillaDirectory, "include")
scintillaScriptsDirectory = os.path.join(scintillaDirectory, "scripts")
@@ -27,6 +31,19 @@ import Face
scintillaBinDirectory = os.path.join(scintillaDirectory, "bin")
+lexillaBinDirectory = os.path.join(scintillaDirectory, "..", "lexilla", "bin")
+lexName = "Lexilla.DLL"
+try:
+ lexillaDLLPath = os.path.join(lexillaBinDirectory, lexName)
+ lexillaLibrary = ctypes.cdll.LoadLibrary(lexillaDLLPath)
+ createLexer = lexillaLibrary.CreateLexer
+ createLexer.restype = ctypes.c_void_p
+ lexillaAvailable = True
+ print("Found Lexilla")
+except OSError:
+ print("Can't find " + lexName)
+ print("Python is built for " + " ".join(platform.architecture()))
+
WFUNC = ctypes.WINFUNCTYPE(c_int, HWND, c_uint, WPARAM, LPARAM)
WS_CHILD = 0x40000000
@@ -182,11 +199,15 @@ class XiteWin():
def OnCreate(self, hwnd):
self.win = hwnd
+ if scintillaIncludesLexers:
+ sciName = "SciLexer.DLL"
+ else:
+ sciName = "Scintilla.DLL"
try:
- scintillaDLLPath = os.path.join(scintillaBinDirectory, "SciLexer.DLL")
+ scintillaDLLPath = os.path.join(scintillaBinDirectory, sciName)
ctypes.cdll.LoadLibrary(scintillaDLLPath)
except OSError:
- print("Can't find SciLexer.DLL")
+ print("Can't find " + sciName)
print("Python is built for " + " ".join(platform.architecture()))
sys.exit()
self.sciHwnd = user32.CreateWindowExW(0,
@@ -206,6 +227,14 @@ class XiteWin():
self.FocusOnEditor()
+ def ChooseLexer(self, lexer):
+ if scintillaIncludesLexers:
+ self.ed.LexerLanguage = lexer
+ elif lexillaAvailable:
+ pLexilla = createLexer(lexer)
+ self.ed.SetILexer(0, pLexilla)
+ else: # No lexers available
+ pass
def Invalidate(self):
user32.InvalidateRect(self.win, 0, 0)
diff --git a/test/simpleTests.py b/test/simpleTests.py
index f1ba906c5..6bdad5de2 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -12,6 +12,10 @@ if sys.platform == "win32":
else:
import XiteQt as Xite
+# Unicode line ends are only available for lexers that support the feature so requires lexers
+lexersAvailable = Xite.lexillaAvailable or Xite.scintillaIncludesLexers
+unicodeLineEndsAvailable = lexersAvailable
+
class TestSimple(unittest.TestCase):
def setUp(self):
@@ -298,10 +302,11 @@ class TestSimple(unittest.TestCase):
# Several tests for unicode line ends U+2028 and U+2029
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testUnicodeLineEnds(self):
# Add two lines separated with U+2028 and ensure it is seen as two lines
# Then remove U+2028 and should be just 1 lines
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
self.ed.AddText(5, b"x\xe2\x80\xa8y")
@@ -326,13 +331,14 @@ class TestSimple(unittest.TestCase):
self.ed.AddText(4, b"x\xc2\x85y")
self.assertEquals(self.ed.LineCount, 1)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testUnicodeLineEndsSwitchToUnicodeAndBack(self):
# Add the Unicode line ends when not in Unicode mode
self.ed.SetCodePage(0)
self.ed.AddText(5, b"x\xe2\x80\xa8y")
self.assertEquals(self.ed.LineCount, 1)
# Into UTF-8 mode - should now be interpreting as two lines
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
self.assertEquals(self.ed.LineCount, 2)
@@ -340,6 +346,7 @@ class TestSimple(unittest.TestCase):
self.ed.SetCodePage(0)
self.assertEquals(self.ed.LineCount, 1)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testUFragmentedEOLCompletion(self):
# Add 2 starting bytes of UTF-8 line end then complete it
self.ed.ClearAll()
@@ -361,9 +368,10 @@ class TestSimple(unittest.TestCase):
self.assertEquals(self.ed.Contents(), b"x\xe2\x80\xa8y")
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testUFragmentedEOLStart(self):
# Add end of UTF-8 line end then insert start
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
self.assertEquals(self.ed.LineCount, 1)
@@ -373,10 +381,11 @@ class TestSimple(unittest.TestCase):
self.ed.AddText(1, b"\xe2")
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testUBreakApartEOL(self):
# Add two lines separated by U+2029 then remove and add back each byte ensuring
# only one line after each removal of any byte in line end and 2 lines after reinsertion
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
text = b"x\xe2\x80\xa9y";
@@ -398,9 +407,10 @@ class TestSimple(unittest.TestCase):
self.ed.ReplaceTarget(1, text[i:i+1])
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testURemoveEOLFragment(self):
# Add UTF-8 line end then delete each byte causing line end to disappear
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
for i in range(3):
@@ -414,10 +424,11 @@ class TestSimple(unittest.TestCase):
# Several tests for unicode NEL line ends U+0085
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testNELLineEnds(self):
# Add two lines separated with U+0085 and ensure it is seen as two lines
# Then remove U+0085 and should be just 1 lines
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
self.ed.AddText(4, b"x\xc2\x85y")
@@ -433,6 +444,7 @@ class TestSimple(unittest.TestCase):
self.assertEquals(self.ed.LineLength(0), 2)
self.assertEquals(self.ed.GetLineEndPosition(0), 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testNELFragmentedEOLCompletion(self):
# Add starting byte of UTF-8 NEL then complete it
self.ed.AddText(3, b"x\xc2y")
@@ -443,9 +455,10 @@ class TestSimple(unittest.TestCase):
self.assertEquals(self.ed.Contents(), b"x\xc2\x85y")
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testNELFragmentedEOLStart(self):
# Add end of UTF-8 NEL then insert start
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
self.assertEquals(self.ed.LineCount, 1)
@@ -455,10 +468,11 @@ class TestSimple(unittest.TestCase):
self.ed.AddText(1, b"\xc2")
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testNELBreakApartEOL(self):
# Add two lines separated by U+0085 then remove and add back each byte ensuring
# only one line after each removal of any byte in line end and 2 lines after reinsertion
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.ed.SetCodePage(65001)
self.ed.SetLineEndTypesAllowed(1)
text = b"x\xc2\x85y";
@@ -480,6 +494,7 @@ class TestSimple(unittest.TestCase):
self.ed.ReplaceTarget(1, text[i:i+1])
self.assertEquals(self.ed.LineCount, 2)
+ @unittest.skipUnless(unicodeLineEndsAvailable, "can not test Unicode line ends")
def testNELRemoveEOLFragment(self):
# Add UTF-8 NEL then delete each byte causing line end to disappear
self.ed.SetCodePage(65001)
@@ -1294,6 +1309,7 @@ class TestRepresentations(unittest.TestCase):
result = self.ed.GetRepresentation(ohmSign)
self.assertEquals(result, ohmExplained)
+@unittest.skipUnless(lexersAvailable, "no lexers included")
class TestProperties(unittest.TestCase):
def setUp(self):
@@ -1303,13 +1319,20 @@ class TestProperties(unittest.TestCase):
self.ed.EmptyUndoBuffer()
def testSet(self):
- self.ed.SetProperty(b"test", b"12")
- self.assertEquals(self.ed.GetPropertyInt(b"test"), 12)
- result = self.ed.GetProperty(b"test")
- self.assertEquals(result, b"12")
- self.ed.SetProperty(b"test.plus", b"[$(test)]")
- result = self.ed.GetPropertyExpanded(b"test.plus")
- self.assertEquals(result, b"[12]")
+ self.xite.ChooseLexer(b"cpp")
+ # For Lexilla, only known property names may work
+ propName = b"lexer.cpp.allow.dollars"
+ self.ed.SetProperty(propName, b"1")
+ self.assertEquals(self.ed.GetPropertyInt(propName), 1)
+ result = self.ed.GetProperty(propName)
+ self.assertEquals(result, b"1")
+ self.ed.SetProperty(propName, b"0")
+ self.assertEquals(self.ed.GetPropertyInt(propName), 0)
+ result = self.ed.GetProperty(propName)
+ self.assertEquals(result, b"0")
+ # No longer expands but should at least return the value
+ result = self.ed.GetPropertyExpanded(propName)
+ self.assertEquals(result, b"0")
class TestTextMargin(unittest.TestCase):
@@ -2216,6 +2239,7 @@ class TestCaseInsensitiveSearch(unittest.TestCase):
self.assertEquals(firstPosition, pos)
self.assertEquals(firstPosition+1, self.ed.TargetEnd)
+@unittest.skipUnless(lexersAvailable, "no lexers included")
class TestLexer(unittest.TestCase):
def setUp(self):
self.xite = Xite.xiteFrame
@@ -2224,11 +2248,11 @@ class TestLexer(unittest.TestCase):
self.ed.EmptyUndoBuffer()
def testLexerNumber(self):
- self.ed.Lexer = self.ed.SCLEX_CPP
+ self.xite.ChooseLexer(b"cpp")
self.assertEquals(self.ed.GetLexer(), self.ed.SCLEX_CPP)
def testLexerName(self):
- self.ed.LexerLanguage = b"cpp"
+ self.xite.ChooseLexer(b"cpp")
self.assertEquals(self.ed.GetLexer(), self.ed.SCLEX_CPP)
name = self.ed.GetLexerLanguage(0)
self.assertEquals(name, b"cpp")
@@ -2247,6 +2271,7 @@ class TestLexer(unittest.TestCase):
wordSet = self.ed.DescribeKeyWordSets()
self.assertNotEquals(wordSet, b"")
+@unittest.skipUnless(lexersAvailable, "no lexers included")
class TestSubStyles(unittest.TestCase):
''' These tests include knowledge of the current implementation in the cpp lexer
and may have to change when that implementation changes.