This commit is contained in:
commit
bc8ff5f44a
6520 changed files with 426985 additions and 0 deletions
0
windows/exploits/ZIBE/pyreadline/test/__init__.py
Normal file
0
windows/exploits/ZIBE/pyreadline/test/__init__.py
Normal file
82
windows/exploits/ZIBE/pyreadline/test/common.py
Normal file
82
windows/exploits/ZIBE/pyreadline/test/common.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#*****************************************************************************
|
||||
# Copyright (C) 2006 Michael Graz. <mgraz@plan10.com>
|
||||
#
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
from pyreadline.modes.emacs import *
|
||||
from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
from pyreadline.keysyms.common import make_KeyPress_from_keydescr
|
||||
|
||||
import unittest
|
||||
class MockReadline:
|
||||
def __init__ (self):
|
||||
self.l_buffer=lineobj.ReadLineTextBuffer(u"")
|
||||
self._history=history.LineHistory()
|
||||
|
||||
def add_history (self, line):
|
||||
self._history.add_history (lineobj.TextLine (line))
|
||||
|
||||
def _print_prompt (self):
|
||||
pass
|
||||
|
||||
def _bell (self):
|
||||
pass
|
||||
|
||||
def insert_text(self, string):
|
||||
u'''Insert text into the command line.'''
|
||||
self.l_buffer.insert_text(string)
|
||||
|
||||
|
||||
class MockConsole:
|
||||
def __init__ (self):
|
||||
self.bell_count = 0
|
||||
self.text = ''
|
||||
|
||||
def size (self):
|
||||
return (1, 1)
|
||||
|
||||
def cursor(self, visible=None, size=None):
|
||||
pass
|
||||
|
||||
def bell (self):
|
||||
self.bell_count += 1
|
||||
|
||||
def write (self, text):
|
||||
self.text += text
|
||||
|
||||
|
||||
|
||||
|
||||
class Event:
|
||||
def __init__ (self, char):
|
||||
if char==u"escape":
|
||||
self.char=u'\x1b'
|
||||
elif char==u"backspace":
|
||||
self.char=u'\x08'
|
||||
elif char==u"tab":
|
||||
self.char=u'\t'
|
||||
elif char==u"space":
|
||||
self.char=u' '
|
||||
else:
|
||||
self.char = char
|
||||
|
||||
def keytext_to_keyinfo_and_event (keytext):
|
||||
keyinfo = keysyms.common.make_KeyPress_from_keydescr (keytext)
|
||||
if len(keytext) == 3 and keytext[0] == u'"' and keytext[2] == u'"':
|
||||
event = Event (keytext[1])
|
||||
else:
|
||||
event = Event (keyinfo.tuple() [3])
|
||||
return keyinfo, event
|
||||
|
||||
|
||||
|
||||
#override runTests from from main in unittest to remove sys.exit call
|
||||
class Tester(unittest.TestProgram):
|
||||
def runTests(self):
|
||||
if self.testRunner is None:
|
||||
self.testRunner = unittest.TextTestRunner(verbosity=self.verbosity)
|
||||
result = self.testRunner.run(self.test)
|
||||
# sys.exit(not result.wasSuccessful())
|
400
windows/exploits/ZIBE/pyreadline/test/test_emacs.py
Normal file
400
windows/exploits/ZIBE/pyreadline/test/test_emacs.py
Normal file
|
@ -0,0 +1,400 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#*****************************************************************************
|
||||
# Copyright (C) 2006 Michael Graz. <mgraz@plan10.com>
|
||||
# Copyright (C) 2006 Michael Graz. <mgraz@plan10.com>
|
||||
#
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
|
||||
import sys, unittest
|
||||
import pdb
|
||||
sys.path.append (u'../..')
|
||||
from pyreadline.modes.emacs import *
|
||||
from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
|
||||
from common import *
|
||||
from pyreadline.logger import log
|
||||
import pyreadline.logger as logger
|
||||
logger.sock_silent=True
|
||||
logger.show_event=[u"debug"]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class EmacsModeTest (EmacsMode):
|
||||
tested_commands={}
|
||||
def __init__ (self):
|
||||
EmacsMode.__init__ (self, MockReadline())
|
||||
self.mock_console = MockConsole ()
|
||||
self.init_editing_mode (None)
|
||||
self.lst_completions = []
|
||||
self.completer = self.mock_completer
|
||||
self.completer_delims = u' u'
|
||||
self.tabstop = 4
|
||||
self.mark_directories=False
|
||||
self.show_all_if_ambiguous=False
|
||||
|
||||
def get_mock_console (self):
|
||||
return self.mock_console
|
||||
console = property (get_mock_console)
|
||||
|
||||
def _set_line (self, text):
|
||||
self.l_buffer.set_line (text)
|
||||
|
||||
def get_line (self):
|
||||
return self.l_buffer.get_line_text ()
|
||||
line = property (get_line)
|
||||
|
||||
def get_line_cursor (self):
|
||||
return self.l_buffer.point
|
||||
line_cursor = property (get_line_cursor)
|
||||
|
||||
def input (self, keytext):
|
||||
if keytext[0:1] == u'"' and keytext[-1:] == u'"':
|
||||
lst_key = [u'"%s"' % c for c in keytext[1:-1]]
|
||||
else:
|
||||
lst_key = [keytext]
|
||||
for key in lst_key:
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (key)
|
||||
dispatch_func = self.key_dispatch.get(keyinfo.tuple(),self.self_insert)
|
||||
self.tested_commands[dispatch_func.__name__]=dispatch_func
|
||||
log(u"keydisp: %s %s"%( key,dispatch_func.__name__))
|
||||
dispatch_func (event)
|
||||
self.previous_func=dispatch_func
|
||||
|
||||
def accept_line (self, e):
|
||||
if EmacsMode.accept_line (self, e):
|
||||
# simulate return
|
||||
# self.add_history (self.line)
|
||||
self.l_buffer.reset_line ()
|
||||
|
||||
def mock_completer (self, text, state):
|
||||
return self.lst_completions [state]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TestsKeyinfo (unittest.TestCase):
|
||||
|
||||
def test_keyinfo (self):
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (u'"d"')
|
||||
self.assertEqual (u'd', event.char)
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (u'"D"')
|
||||
self.assertEqual (u'D', event.char)
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (u'"$"')
|
||||
self.assertEqual (u'$', event.char)
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (u'Escape')
|
||||
self.assertEqual (u'\x1b', event.char)
|
||||
|
||||
|
||||
class TestsMovement (unittest.TestCase):
|
||||
def test_cursor (self):
|
||||
r = EmacsModeTest ()
|
||||
self.assertEqual (r.line, u'')
|
||||
r.input(u'"First Second Third"')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Control-a')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'Control-e')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Home')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 1)
|
||||
r.input(u'Ctrl-f')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Ctrl-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 5)
|
||||
r.input(u'Ctrl-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 12)
|
||||
r.input(u'Ctrl-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Ctrl-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Ctrl-Left')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 13)
|
||||
r.input(u'Ctrl-Left')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 6)
|
||||
r.input(u'Ctrl-Left')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'Ctrl-Left')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
|
||||
|
||||
class TestsDelete (unittest.TestCase):
|
||||
def test_delete (self):
|
||||
r = EmacsModeTest ()
|
||||
self.assertEqual (r.line, u'')
|
||||
r.input(u'"First Second Third"')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Delete')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Left')
|
||||
r.input(u'Left')
|
||||
r.input(u'Delete')
|
||||
self.assertEqual (r.line, u'First Second Thid')
|
||||
self.assertEqual (r.line_cursor, 16)
|
||||
r.input(u'Delete')
|
||||
self.assertEqual (r.line, u'First Second Thi')
|
||||
self.assertEqual (r.line_cursor, 16)
|
||||
r.input(u'Backspace')
|
||||
self.assertEqual (r.line, u'First Second Th')
|
||||
self.assertEqual (r.line_cursor, 15)
|
||||
r.input(u'Home')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
self.assertEqual (r.line, u'First Second Th')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Backspace')
|
||||
self.assertEqual (r.line, u'Frst Second Th')
|
||||
self.assertEqual (r.line_cursor, 1)
|
||||
r.input(u'Backspace')
|
||||
self.assertEqual (r.line, u'rst Second Th')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'Backspace')
|
||||
self.assertEqual (r.line, u'rst Second Th')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'Escape')
|
||||
self.assertEqual (r.line, u'')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
|
||||
def test_delete_word (self):
|
||||
r = EmacsModeTest ()
|
||||
self.assertEqual (r.line, u'')
|
||||
r.input(u'"First Second Third"')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
r.input(u'Control-Backspace')
|
||||
self.assertEqual (r.line, u'First Second ')
|
||||
self.assertEqual (r.line_cursor, 13)
|
||||
r.input(u'Backspace')
|
||||
r.input(u'Left')
|
||||
r.input(u'Left')
|
||||
self.assertEqual (r.line, u'First Second')
|
||||
self.assertEqual (r.line_cursor, 10)
|
||||
r.input(u'Control-Backspace')
|
||||
self.assertEqual (r.line, u'First nd')
|
||||
self.assertEqual (r.line_cursor, 6)
|
||||
r.input(u'Escape')
|
||||
self.assertEqual (r.line, u'')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
r.input(u'"First Second Third"')
|
||||
r.input(u'Home')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
r.input(u'Control-Delete')
|
||||
self.assertEqual (r.line, u'FiSecond Third')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Control-Delete')
|
||||
self.assertEqual (r.line, u'FiThird')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Control-Delete')
|
||||
self.assertEqual (r.line, u'Fi')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Control-Delete')
|
||||
self.assertEqual (r.line, u'Fi')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input(u'Escape')
|
||||
self.assertEqual (r.line, u'')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
|
||||
|
||||
|
||||
class TestsSelectionMovement (unittest.TestCase):
|
||||
def test_cursor (self):
|
||||
r = EmacsModeTest ()
|
||||
self.assertEqual (r.line, u'')
|
||||
r.input(u'"First Second Third"')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 18)
|
||||
self.assertEqual (r.l_buffer.selection_mark, -1)
|
||||
r.input(u'Home')
|
||||
r.input(u'Shift-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 1)
|
||||
self.assertEqual (r.l_buffer.selection_mark, 0)
|
||||
r.input(u'Shift-Control-Right')
|
||||
self.assertEqual (r.line, u'First Second Third')
|
||||
self.assertEqual (r.line_cursor, 5)
|
||||
self.assertEqual (r.l_buffer.selection_mark, 0)
|
||||
r.input(u'"a"')
|
||||
self.assertEqual (r.line, u'a Second Third')
|
||||
self.assertEqual (r.line_cursor, 1)
|
||||
self.assertEqual (r.l_buffer.selection_mark, -1)
|
||||
r.input(u'Shift-End')
|
||||
self.assertEqual (r.line, u'a Second Third')
|
||||
self.assertEqual (r.line_cursor, 14)
|
||||
self.assertEqual (r.l_buffer.selection_mark, 1)
|
||||
r.input(u'Delete')
|
||||
self.assertEqual (r.line, u'a')
|
||||
self.assertEqual (r.line_cursor, 1)
|
||||
self.assertEqual (r.l_buffer.selection_mark, -1)
|
||||
|
||||
|
||||
|
||||
class TestsHistory (unittest.TestCase):
|
||||
def test_history_1 (self):
|
||||
r = EmacsModeTest ()
|
||||
r.add_history (u'aa')
|
||||
r.add_history (u'bbb')
|
||||
self.assertEqual (r.line, u'')
|
||||
r.input (u'Up')
|
||||
self.assertEqual (r.line, u'bbb')
|
||||
self.assertEqual (r.line_cursor, 3)
|
||||
r.input (u'Up')
|
||||
self.assertEqual (r.line, u'aa')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input (u'Up')
|
||||
self.assertEqual (r.line, u'aa')
|
||||
self.assertEqual (r.line_cursor, 2)
|
||||
r.input (u'Down')
|
||||
self.assertEqual (r.line, u'bbb')
|
||||
self.assertEqual (r.line_cursor, 3)
|
||||
r.input (u'Down')
|
||||
self.assertEqual (r.line, u'')
|
||||
self.assertEqual (r.line_cursor, 0)
|
||||
|
||||
def test_history_2 (self):
|
||||
r = EmacsModeTest ()
|
||||
r.add_history (u'aaaa')
|
||||
r.add_history (u'aaba')
|
||||
r.add_history (u'aaca')
|
||||
r.add_history (u'akca')
|
||||
r.add_history (u'bbb')
|
||||
r.add_history (u'ako')
|
||||
self.assert_line(r,'',0)
|
||||
r.input (u'"a"')
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'ako',1)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'akca',1)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'aaca',1)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'aaba',1)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'aaaa',1)
|
||||
r.input (u'Right')
|
||||
self.assert_line(r,'aaaa',2)
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'aaba',2)
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'aaca',2)
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'aaca',2)
|
||||
r.input (u'Left')
|
||||
r.input (u'Left')
|
||||
r.input (u'Down')
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'bbb',3)
|
||||
r.input (u'Left')
|
||||
self.assert_line(r,'bbb',2)
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'bbb',2)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'bbb',2)
|
||||
|
||||
|
||||
def test_history_3 (self):
|
||||
r = EmacsModeTest ()
|
||||
r.add_history (u'aaaa')
|
||||
r.add_history (u'aaba')
|
||||
r.add_history (u'aaca')
|
||||
r.add_history (u'akca')
|
||||
r.add_history (u'bbb')
|
||||
r.add_history (u'ako')
|
||||
self.assert_line(r,'',0)
|
||||
r.input (u'')
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'ako',3)
|
||||
r.input (u'Down')
|
||||
self.assert_line(r,'',0)
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'ako',3)
|
||||
|
||||
def test_history_3 (self):
|
||||
r = EmacsModeTest ()
|
||||
r.add_history (u'aaaa')
|
||||
r.add_history (u'aaba')
|
||||
r.add_history (u'aaca')
|
||||
r.add_history (u'akca')
|
||||
r.add_history (u'bbb')
|
||||
r.add_history (u'ako')
|
||||
self.assert_line(r,'',0)
|
||||
r.input (u'k')
|
||||
r.input (u'Up')
|
||||
self.assert_line(r,'k',1)
|
||||
|
||||
def test_complete (self):
|
||||
import rlcompleter
|
||||
logger.sock_silent = False
|
||||
|
||||
log("-" * 50)
|
||||
r = EmacsModeTest()
|
||||
completerobj = rlcompleter.Completer()
|
||||
def _nop(val, word):
|
||||
return word
|
||||
completerobj._callable_postfix = _nop
|
||||
r.completer = completerobj.complete
|
||||
r._bind_key("tab", r.complete)
|
||||
r.input(u'"exi(ksdjksjd)"')
|
||||
r.input(u'Control-a')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
r.input(u'Tab')
|
||||
self.assert_line(r, u"exit(ksdjksjd)", 4)
|
||||
|
||||
r.input(u'Escape')
|
||||
r.input(u'"exi"')
|
||||
r.input(u'Control-a')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
r.input(u'Right')
|
||||
r.input(u'Tab')
|
||||
self.assert_line(r, u"exit", 4)
|
||||
|
||||
|
||||
|
||||
def assert_line(self,r,line,cursor):
|
||||
self.assertEqual (r.line, line)
|
||||
self.assertEqual (r.line_cursor, cursor)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# utility functions
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if __name__ == u'__main__':
|
||||
Tester()
|
||||
tested=EmacsModeTest.tested_commands.keys()
|
||||
tested.sort()
|
||||
# print " Tested functions ".center(60,"-")
|
||||
# print "\n".join(tested)
|
||||
# print
|
||||
|
||||
all_funcs=dict([(x.__name__,x) for x in EmacsModeTest().key_dispatch.values()])
|
||||
all_funcs=all_funcs.keys()
|
||||
not_tested=[x for x in all_funcs if x not in tested]
|
||||
not_tested.sort()
|
||||
print " Not tested functions ".center(60,"-")
|
||||
print "\n".join(not_tested)
|
||||
|
||||
|
148
windows/exploits/ZIBE/pyreadline/test/test_history.py
Normal file
148
windows/exploits/ZIBE/pyreadline/test/test_history.py
Normal file
|
@ -0,0 +1,148 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
# Copyright (C) 2007 Jörgen Stenarson. <>
|
||||
|
||||
import sys, unittest
|
||||
sys.path.append (u'../..')
|
||||
#from pyreadline.modes.vi import *
|
||||
#from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
from pyreadline.lineeditor.history import LineHistory
|
||||
import pyreadline.lineeditor.history as history
|
||||
|
||||
import pyreadline.logger
|
||||
pyreadline.logger.sock_silent=False
|
||||
from pyreadline.logger import log
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
RL=lineobj.ReadLineTextBuffer
|
||||
|
||||
class Test_prev_next_history(unittest.TestCase):
|
||||
t = u"test text"
|
||||
|
||||
def setUp(self):
|
||||
self.q = q = LineHistory()
|
||||
for x in [u"aaaa", u"aaba", u"aaca", u"akca", u"bbb", u"ako"]:
|
||||
q.add_history(RL(x))
|
||||
|
||||
def test_previous_history (self):
|
||||
hist = self.q
|
||||
assert hist.history_cursor == 6
|
||||
l = RL(u"")
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"ako"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"bbb"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"akca"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"aaca"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"aaba"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"aaaa"
|
||||
hist.previous_history(l)
|
||||
assert l.get_line_text() == u"aaaa"
|
||||
|
||||
def test_next_history (self):
|
||||
hist=self.q
|
||||
hist.beginning_of_history()
|
||||
assert hist.history_cursor==0
|
||||
l=RL(u"")
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"aaba"
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"aaca"
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"akca"
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"bbb"
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"ako"
|
||||
hist.next_history(l)
|
||||
assert l.get_line_text()==u"ako"
|
||||
|
||||
class Test_prev_next_history(unittest.TestCase):
|
||||
t = u"test text"
|
||||
|
||||
def setUp(self):
|
||||
self.q = q = LineHistory()
|
||||
for x in [u"aaaa",u"aaba",u"aaca",u"akca",u"bbb",u"ako"]:
|
||||
q.add_history(RL(x))
|
||||
|
||||
def test_history_search_backward (self):
|
||||
q = LineHistory()
|
||||
for x in [u"aaaa",u"aaba",u"aaca",u" aacax",u"akca",u"bbb",u"ako"]:
|
||||
q.add_history(RL(x))
|
||||
a=RL(u"aa",point=2)
|
||||
for x in [u"aaca",u"aaba",u"aaaa",u"aaaa"]:
|
||||
res=q.history_search_backward(a)
|
||||
assert res.get_line_text()==x
|
||||
|
||||
def test_history_search_forward (self):
|
||||
q = LineHistory()
|
||||
for x in [u"aaaa",u"aaba",u"aaca",u" aacax",u"akca",u"bbb",u"ako"]:
|
||||
q.add_history(RL(x))
|
||||
q.beginning_of_history()
|
||||
a=RL(u"aa",point=2)
|
||||
for x in [u"aaba",u"aaca",u"aaca"]:
|
||||
res=q.history_search_forward(a)
|
||||
assert res.get_line_text()==x
|
||||
|
||||
class Test_history_search_incr_fwd_backwd(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.q = q = LineHistory()
|
||||
for x in [u"aaaa",u"aaba",u"aaca",u"akca",u"bbb",u"ako"]:
|
||||
q.add_history(RL(x))
|
||||
|
||||
def test_backward_1(self):
|
||||
q = self.q
|
||||
self.assertEqual(q.reverse_search_history(u"b"), u"bbb")
|
||||
self.assertEqual(q.reverse_search_history(u"b"), u"aaba")
|
||||
self.assertEqual(q.reverse_search_history(u"bb"), u"aaba")
|
||||
|
||||
def test_backward_2(self):
|
||||
q = self.q
|
||||
self.assertEqual(q.reverse_search_history(u"a"), u"ako")
|
||||
self.assertEqual(q.reverse_search_history(u"aa"), u"aaca")
|
||||
self.assertEqual(q.reverse_search_history(u"a"), u"aaca")
|
||||
self.assertEqual(q.reverse_search_history(u"ab"), u"aaba")
|
||||
|
||||
|
||||
def test_forward_1(self):
|
||||
q = self.q
|
||||
self.assertEqual(q.forward_search_history(u"a"), u"ako")
|
||||
|
||||
def test_forward_2(self):
|
||||
q = self.q
|
||||
q.history_cursor = 0
|
||||
self.assertEqual(q.forward_search_history(u"a"), u"aaaa")
|
||||
self.assertEqual(q.forward_search_history(u"a"), u"aaba")
|
||||
self.assertEqual(q.forward_search_history(u"ak"), u"akca")
|
||||
self.assertEqual(q.forward_search_history(u"akl"), u"akca")
|
||||
self.assertEqual(q.forward_search_history(u"ak"), u"akca")
|
||||
self.assertEqual(q.forward_search_history(u"ako"), u"ako")
|
||||
|
||||
class Test_empty_history_search_incr_fwd_backwd(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.q = q = LineHistory()
|
||||
|
||||
def test_backward_1(self):
|
||||
q = self.q
|
||||
self.assertEqual(q.reverse_search_history(u"b"), u"")
|
||||
|
||||
def test_forward_1(self):
|
||||
q = self.q
|
||||
self.assertEqual(q.forward_search_history(u"a"), u"")
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# utility functions
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if __name__ == u'__main__':
|
||||
unittest.main()
|
||||
|
||||
l=lineobj.ReadLineTextBuffer(u"First Second Third")
|
390
windows/exploits/ZIBE/pyreadline/test/test_lineeditor.py
Normal file
390
windows/exploits/ZIBE/pyreadline/test/test_lineeditor.py
Normal file
|
@ -0,0 +1,390 @@
|
|||
# Copyright (C) 2006 Michael Graz. <mgraz@plan10.com>
|
||||
|
||||
import sys, unittest
|
||||
sys.path.append (u'../..')
|
||||
#from pyreadline.modes.vi import *
|
||||
#from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Test_copy (unittest.TestCase):
|
||||
def test_copy1 (self):
|
||||
l=lineobj.ReadLineTextBuffer(u"first second")
|
||||
q=l.copy()
|
||||
self.assertEqual(q.get_line_text(),l.get_line_text())
|
||||
self.assertEqual(q.point,l.point)
|
||||
self.assertEqual(q.mark,l.mark)
|
||||
|
||||
def test_copy2 (self):
|
||||
l=lineobj.ReadLineTextBuffer(u"first second",point=5)
|
||||
q=l.copy()
|
||||
self.assertEqual(q.get_line_text(),l.get_line_text())
|
||||
self.assertEqual(q.point,l.point)
|
||||
self.assertEqual(q.mark,l.mark)
|
||||
|
||||
|
||||
class Test_linepos (unittest.TestCase):
|
||||
t="test text"
|
||||
def test_NextChar (self):
|
||||
t=self.t
|
||||
l=lineobj.ReadLineTextBuffer(t)
|
||||
for i in range(len(t)):
|
||||
self.assertEqual(i,l.point)
|
||||
l.point=lineobj.NextChar
|
||||
#advance past end of buffer
|
||||
l.point=lineobj.NextChar
|
||||
self.assertEqual(len(t),l.point)
|
||||
|
||||
def test_PrevChar (self):
|
||||
t=self.t
|
||||
l=lineobj.ReadLineTextBuffer(t,point=len(t))
|
||||
for i in range(len(t)):
|
||||
self.assertEqual(len(t)-i,l.point)
|
||||
l.point=lineobj.PrevChar
|
||||
#advance past beginning of buffer
|
||||
l.point=lineobj.PrevChar
|
||||
self.assertEqual(0,l.point)
|
||||
|
||||
def test_EndOfLine (self):
|
||||
t=self.t
|
||||
l=lineobj.ReadLineTextBuffer(t,point=len(t))
|
||||
for i in range(len(t)):
|
||||
l.point=i
|
||||
l.point=lineobj.EndOfLine
|
||||
self.assertEqual(len(t),l.point)
|
||||
|
||||
def test_StartOfLine (self):
|
||||
t=self.t
|
||||
l=lineobj.ReadLineTextBuffer(t,point=len(t))
|
||||
for i in range(len(t)):
|
||||
l.point=i
|
||||
l.point=lineobj.StartOfLine
|
||||
self.assertEqual(0,l.point)
|
||||
|
||||
|
||||
class Tests_linepos2(Test_linepos):
|
||||
t="kajkj"
|
||||
|
||||
class Tests_linepos3(Test_linepos):
|
||||
t=""
|
||||
|
||||
|
||||
class Test_movement (unittest.TestCase):
|
||||
def test_NextChar (self):
|
||||
cmd=lineobj.NextChar
|
||||
tests=[
|
||||
# u"First"
|
||||
(cmd,
|
||||
u"First",
|
||||
u"# u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First",
|
||||
u" # u",
|
||||
u" #"),
|
||||
(cmd,
|
||||
u"First",
|
||||
u" #",
|
||||
u" #"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_PrevChar (self):
|
||||
cmd=lineobj.PrevChar
|
||||
tests=[
|
||||
# u"First"
|
||||
(cmd,
|
||||
u"First",
|
||||
u" #",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First",
|
||||
u" # u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First",
|
||||
u"# u",
|
||||
u"# u"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
|
||||
|
||||
def test_PrevWordStart (self):
|
||||
cmd=lineobj.PrevWordStart
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u"# u"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_NextWordStart (self):
|
||||
cmd=lineobj.NextWordStart
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" #"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_NextWordEnd (self):
|
||||
cmd=lineobj.NextWordEnd
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" #"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_PrevWordEnd (self):
|
||||
cmd=lineobj.PrevWordEnd
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u"# u"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_WordEnd_1 (self):
|
||||
cmd=lineobj.WordEnd
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" #"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_WordEnd_2 (self):
|
||||
cmd=lineobj.WordEnd
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #"),
|
||||
]
|
||||
|
||||
for cmd,text,init_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
self.assertRaises(lineobj.NotAWordError,cmd,l)
|
||||
|
||||
|
||||
def test_WordStart_1 (self):
|
||||
cmd=lineobj.WordStart
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" # u"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_WordStart_2 (self):
|
||||
cmd=lineobj.WordStart
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #"),
|
||||
]
|
||||
|
||||
for cmd,text,init_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
self.assertRaises(lineobj.NotAWordError,cmd,l)
|
||||
|
||||
|
||||
def test_StartOfLine (self):
|
||||
cmd=lineobj.StartOfLine
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u"# u"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #",
|
||||
u"# u"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_EndOfLine (self):
|
||||
cmd=lineobj.EndOfLine
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u"# u",
|
||||
u" #"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" # u",
|
||||
u" #"),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
u" #",
|
||||
u" #"),
|
||||
]
|
||||
for cmd,text,init_point,expected_point in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,get_point_pos(init_point))
|
||||
l.point=cmd
|
||||
self.assertEqual(get_point_pos(expected_point),l.point)
|
||||
|
||||
def test_Point(self):
|
||||
cmd=lineobj.Point
|
||||
tests=[
|
||||
# u"First Second Third"
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
0),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
12),
|
||||
(cmd,
|
||||
u"First Second Third",
|
||||
18),
|
||||
]
|
||||
for cmd,text,p in tests:
|
||||
l=lineobj.ReadLineTextBuffer(text,p)
|
||||
self.assertEqual(p,cmd(l))
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# utility functions
|
||||
|
||||
def get_point_pos(pstr):
|
||||
return pstr.index(u"#")
|
||||
|
||||
def get_mark_pos(mstr):
|
||||
try:
|
||||
return mstr.index(u"#")
|
||||
except ValueError:
|
||||
return -1
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
if __name__ == u'__main__':
|
||||
unittest.main()
|
||||
|
||||
l=lineobj.ReadLineTextBuffer(u"First Second Third")
|
2146
windows/exploits/ZIBE/pyreadline/test/test_vi.py
Normal file
2146
windows/exploits/ZIBE/pyreadline/test/test_vi.py
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue