home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2360 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  10.4 KB  |  271 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import unittest
  6. sys.path.append('../..')
  7. from pyreadline.lineeditor import lineobj
  8.  
  9. class Test_copy(unittest.TestCase):
  10.     
  11.     def test_copy1(self):
  12.         l = lineobj.ReadLineTextBuffer('first second')
  13.         q = l.copy()
  14.         self.assertEqual(q.get_line_text(), l.get_line_text())
  15.         self.assertEqual(q.point, l.point)
  16.         self.assertEqual(q.mark, l.mark)
  17.  
  18.     
  19.     def test_copy2(self):
  20.         l = lineobj.ReadLineTextBuffer('first second', point = 5)
  21.         q = l.copy()
  22.         self.assertEqual(q.get_line_text(), l.get_line_text())
  23.         self.assertEqual(q.point, l.point)
  24.         self.assertEqual(q.mark, l.mark)
  25.  
  26.  
  27.  
  28. class Test_linepos(unittest.TestCase):
  29.     t = 'test text'
  30.     
  31.     def test_NextChar(self):
  32.         t = self.t
  33.         l = lineobj.ReadLineTextBuffer(t)
  34.         for i in range(len(t)):
  35.             self.assertEqual(i, l.point)
  36.             l.point = lineobj.NextChar
  37.         
  38.         l.point = lineobj.NextChar
  39.         self.assertEqual(len(t), l.point)
  40.  
  41.     
  42.     def test_PrevChar(self):
  43.         t = self.t
  44.         l = lineobj.ReadLineTextBuffer(t, point = len(t))
  45.         for i in range(len(t)):
  46.             self.assertEqual(len(t) - i, l.point)
  47.             l.point = lineobj.PrevChar
  48.         
  49.         l.point = lineobj.PrevChar
  50.         self.assertEqual(0, l.point)
  51.  
  52.     
  53.     def test_EndOfLine(self):
  54.         t = self.t
  55.         l = lineobj.ReadLineTextBuffer(t, point = len(t))
  56.         for i in range(len(t)):
  57.             l.point = i
  58.             l.point = lineobj.EndOfLine
  59.             self.assertEqual(len(t), l.point)
  60.         
  61.  
  62.     
  63.     def test_StartOfLine(self):
  64.         t = self.t
  65.         l = lineobj.ReadLineTextBuffer(t, point = len(t))
  66.         for i in range(len(t)):
  67.             l.point = i
  68.             l.point = lineobj.StartOfLine
  69.             self.assertEqual(0, l.point)
  70.         
  71.  
  72.  
  73.  
  74. class Tests_linepos2(Test_linepos):
  75.     t = 'kajkj'
  76.  
  77.  
  78. class Tests_linepos3(Test_linepos):
  79.     t = ''
  80.  
  81.  
  82. class Test_movement(unittest.TestCase):
  83.     
  84.     def test_NextChar(self):
  85.         cmd = lineobj.NextChar
  86.         tests = [
  87.             (cmd, 'First', '#     ', ' #    '),
  88.             (cmd, 'First', '    # ', '     #'),
  89.             (cmd, 'First', '     #', '     #')]
  90.         for cmd, text, init_point, expected_point in tests:
  91.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  92.             l.point = cmd
  93.             self.assertEqual(get_point_pos(expected_point), l.point)
  94.         
  95.  
  96.     
  97.     def test_PrevChar(self):
  98.         cmd = lineobj.PrevChar
  99.         tests = [
  100.             (cmd, 'First', '     #', '    # '),
  101.             (cmd, 'First', ' #   ', '#    '),
  102.             (cmd, 'First', '#     ', '#     ')]
  103.         for cmd, text, init_point, expected_point in tests:
  104.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  105.             l.point = cmd
  106.             self.assertEqual(get_point_pos(expected_point), l.point)
  107.         
  108.  
  109.     
  110.     def test_PrevWordStart(self):
  111.         cmd = lineobj.PrevWordStart
  112.         tests = [
  113.             (cmd, 'First Second Third', '                  #', '             #     '),
  114.             (cmd, 'First Second Third', '             #     ', '      #            '),
  115.             (cmd, 'First Second Third', '     #             ', '#                  '),
  116.             (cmd, 'First Second Third', '#                  ', '#                  ')]
  117.         for cmd, text, init_point, expected_point in tests:
  118.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  119.             l.point = cmd
  120.             self.assertEqual(get_point_pos(expected_point), l.point)
  121.         
  122.  
  123.     
  124.     def test_NextWordStart(self):
  125.         cmd = lineobj.NextWordStart
  126.         tests = [
  127.             (cmd, 'First Second Third', '#                 ', '      #           '),
  128.             (cmd, 'First Second Third', '    #             ', '      #           '),
  129.             (cmd, 'First Second Third', '      #            ', '             #     '),
  130.             (cmd, 'First Second Third', '              #    ', '                  #')]
  131.         for cmd, text, init_point, expected_point in tests:
  132.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  133.             l.point = cmd
  134.             self.assertEqual(get_point_pos(expected_point), l.point)
  135.         
  136.  
  137.     
  138.     def test_NextWordEnd(self):
  139.         cmd = lineobj.NextWordEnd
  140.         tests = [
  141.             (cmd, 'First Second Third', '#                 ', '     #            '),
  142.             (cmd, 'First Second Third', '    #             ', '     #            '),
  143.             (cmd, 'First Second Third', '      #            ', '            #      '),
  144.             (cmd, 'First Second Third', '              #    ', '                  #')]
  145.         for cmd, text, init_point, expected_point in tests:
  146.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  147.             l.point = cmd
  148.             self.assertEqual(get_point_pos(expected_point), l.point)
  149.         
  150.  
  151.     
  152.     def test_PrevWordEnd(self):
  153.         cmd = lineobj.PrevWordEnd
  154.         tests = [
  155.             (cmd, 'First Second Third', '                  #', '            #      '),
  156.             (cmd, 'First Second Third', '            #      ', '     #             '),
  157.             (cmd, 'First Second Third', '     #             ', '#                  '),
  158.             (cmd, 'First Second Third', '#                  ', '#                  ')]
  159.         for cmd, text, init_point, expected_point in tests:
  160.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  161.             l.point = cmd
  162.             self.assertEqual(get_point_pos(expected_point), l.point)
  163.         
  164.  
  165.     
  166.     def test_WordEnd_1(self):
  167.         cmd = lineobj.WordEnd
  168.         tests = [
  169.             (cmd, 'First Second Third', '#                  ', '     #             '),
  170.             (cmd, 'First Second Third', ' #                 ', '     #             '),
  171.             (cmd, 'First Second Third', '             #     ', '                  #')]
  172.         for cmd, text, init_point, expected_point in tests:
  173.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  174.             l.point = cmd
  175.             self.assertEqual(get_point_pos(expected_point), l.point)
  176.         
  177.  
  178.     
  179.     def test_WordEnd_2(self):
  180.         cmd = lineobj.WordEnd
  181.         tests = [
  182.             (cmd, 'First Second Third', '     #             '),
  183.             (cmd, 'First Second Third', '            #      '),
  184.             (cmd, 'First Second Third', '                  #')]
  185.         for cmd, text, init_point in tests:
  186.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  187.             self.assertRaises(lineobj.NotAWordError, cmd, l)
  188.         
  189.  
  190.     
  191.     def test_WordStart_1(self):
  192.         cmd = lineobj.WordStart
  193.         tests = [
  194.             (cmd, 'First Second Third', '#                  ', '#                  '),
  195.             (cmd, 'First Second Third', ' #                 ', '#                  '),
  196.             (cmd, 'First Second Third', '               #   ', '             #     ')]
  197.         for cmd, text, init_point, expected_point in tests:
  198.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  199.             l.point = cmd
  200.             self.assertEqual(get_point_pos(expected_point), l.point)
  201.         
  202.  
  203.     
  204.     def test_WordStart_2(self):
  205.         cmd = lineobj.WordStart
  206.         tests = [
  207.             (cmd, 'First Second Third', '     #             '),
  208.             (cmd, 'First Second Third', '            #      '),
  209.             (cmd, 'First Second Third', '                  #')]
  210.         for cmd, text, init_point in tests:
  211.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  212.             self.assertRaises(lineobj.NotAWordError, cmd, l)
  213.         
  214.  
  215.     
  216.     def test_StartOfLine(self):
  217.         cmd = lineobj.StartOfLine
  218.         tests = [
  219.             (cmd, 'First Second Third', '#                 ', '#                 '),
  220.             (cmd, 'First Second Third', '         #         ', '#                  '),
  221.             (cmd, 'First Second Third', '                  #', '#                  ')]
  222.         for cmd, text, init_point, expected_point in tests:
  223.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  224.             l.point = cmd
  225.             self.assertEqual(get_point_pos(expected_point), l.point)
  226.         
  227.  
  228.     
  229.     def test_EndOfLine(self):
  230.         cmd = lineobj.EndOfLine
  231.         tests = [
  232.             (cmd, 'First Second Third', '#                 ', '                  #'),
  233.             (cmd, 'First Second Third', '         #         ', '                  #'),
  234.             (cmd, 'First Second Third', '                  #', '                  #')]
  235.         for cmd, text, init_point, expected_point in tests:
  236.             l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point))
  237.             l.point = cmd
  238.             self.assertEqual(get_point_pos(expected_point), l.point)
  239.         
  240.  
  241.     
  242.     def test_Point(self):
  243.         cmd = lineobj.Point
  244.         tests = [
  245.             (cmd, 'First Second Third', 0),
  246.             (cmd, 'First Second Third', 12),
  247.             (cmd, 'First Second Third', 18)]
  248.         for cmd, text, p in tests:
  249.             l = lineobj.ReadLineTextBuffer(text, p)
  250.             self.assertEqual(p, cmd(l))
  251.         
  252.  
  253.  
  254.  
  255. def get_point_pos(pstr):
  256.     return pstr.index('#')
  257.  
  258.  
  259. def get_mark_pos(mstr):
  260.     
  261.     try:
  262.         return mstr.index('#')
  263.     except ValueError:
  264.         return -1
  265.  
  266.  
  267. if __name__ == '__main__':
  268.     unittest.main()
  269.     l = lineobj.ReadLineTextBuffer('First Second Third')
  270.  
  271.