m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.9 KiB

6 months ago
  1. # -*- coding: UTF-8 -*-
  2. # Copyright (C) 2007 Jörgen Stenarson. <>
  3. from __future__ import print_function, unicode_literals, absolute_import
  4. import sys, unittest
  5. sys.path.append ('../..')
  6. #from pyreadline.modes.vi import *
  7. #from pyreadline import keysyms
  8. from pyreadline.lineeditor import lineobj
  9. from pyreadline.lineeditor.history import LineHistory
  10. import pyreadline.lineeditor.history as history
  11. import pyreadline.logger
  12. pyreadline.logger.sock_silent=False
  13. from pyreadline.logger import log
  14. #----------------------------------------------------------------------
  15. #----------------------------------------------------------------------
  16. RL=lineobj.ReadLineTextBuffer
  17. class Test_prev_next_history(unittest.TestCase):
  18. t = "test text"
  19. def setUp(self):
  20. self.q = q = LineHistory()
  21. for x in ["aaaa", "aaba", "aaca", "akca", "bbb", "ako"]:
  22. q.add_history(RL(x))
  23. def test_previous_history (self):
  24. hist = self.q
  25. assert hist.history_cursor == 6
  26. l = RL("")
  27. hist.previous_history(l)
  28. assert l.get_line_text() == "ako"
  29. hist.previous_history(l)
  30. assert l.get_line_text() == "bbb"
  31. hist.previous_history(l)
  32. assert l.get_line_text() == "akca"
  33. hist.previous_history(l)
  34. assert l.get_line_text() == "aaca"
  35. hist.previous_history(l)
  36. assert l.get_line_text() == "aaba"
  37. hist.previous_history(l)
  38. assert l.get_line_text() == "aaaa"
  39. hist.previous_history(l)
  40. assert l.get_line_text() == "aaaa"
  41. def test_next_history (self):
  42. hist=self.q
  43. hist.beginning_of_history()
  44. assert hist.history_cursor==0
  45. l=RL("")
  46. hist.next_history(l)
  47. assert l.get_line_text()=="aaba"
  48. hist.next_history(l)
  49. assert l.get_line_text()=="aaca"
  50. hist.next_history(l)
  51. assert l.get_line_text()=="akca"
  52. hist.next_history(l)
  53. assert l.get_line_text()=="bbb"
  54. hist.next_history(l)
  55. assert l.get_line_text()=="ako"
  56. hist.next_history(l)
  57. assert l.get_line_text()=="ako"
  58. class Test_prev_next_history(unittest.TestCase):
  59. t = "test text"
  60. def setUp(self):
  61. self.q = q = LineHistory()
  62. for x in ["aaaa","aaba","aaca","akca","bbb","ako"]:
  63. q.add_history(RL(x))
  64. def test_history_search_backward (self):
  65. q = LineHistory()
  66. for x in ["aaaa","aaba","aaca"," aacax","akca","bbb","ako"]:
  67. q.add_history(RL(x))
  68. a=RL("aa",point=2)
  69. for x in ["aaca","aaba","aaaa","aaaa"]:
  70. res=q.history_search_backward(a)
  71. assert res.get_line_text()==x
  72. def test_history_search_forward (self):
  73. q = LineHistory()
  74. for x in ["aaaa","aaba","aaca"," aacax","akca","bbb","ako"]:
  75. q.add_history(RL(x))
  76. q.beginning_of_history()
  77. a=RL("aa",point=2)
  78. for x in ["aaba","aaca","aaca"]:
  79. res=q.history_search_forward(a)
  80. assert res.get_line_text()==x
  81. class Test_history_search_incr_fwd_backwd(unittest.TestCase):
  82. def setUp(self):
  83. self.q = q = LineHistory()
  84. for x in ["aaaa","aaba","aaca","akca","bbb","ako"]:
  85. q.add_history(RL(x))
  86. def test_backward_1(self):
  87. q = self.q
  88. self.assertEqual(q.reverse_search_history("b"), "bbb")
  89. self.assertEqual(q.reverse_search_history("b"), "aaba")
  90. self.assertEqual(q.reverse_search_history("bb"), "aaba")
  91. def test_backward_2(self):
  92. q = self.q
  93. self.assertEqual(q.reverse_search_history("a"), "ako")
  94. self.assertEqual(q.reverse_search_history("aa"), "aaca")
  95. self.assertEqual(q.reverse_search_history("a"), "aaca")
  96. self.assertEqual(q.reverse_search_history("ab"), "aaba")
  97. def test_forward_1(self):
  98. q = self.q
  99. self.assertEqual(q.forward_search_history("a"), "ako")
  100. def test_forward_2(self):
  101. q = self.q
  102. q.history_cursor = 0
  103. self.assertEqual(q.forward_search_history("a"), "aaaa")
  104. self.assertEqual(q.forward_search_history("a"), "aaba")
  105. self.assertEqual(q.forward_search_history("ak"), "akca")
  106. self.assertEqual(q.forward_search_history("akl"), "akca")
  107. self.assertEqual(q.forward_search_history("ak"), "akca")
  108. self.assertEqual(q.forward_search_history("ako"), "ako")
  109. class Test_empty_history_search_incr_fwd_backwd(unittest.TestCase):
  110. def setUp(self):
  111. self.q = q = LineHistory()
  112. def test_backward_1(self):
  113. q = self.q
  114. self.assertEqual(q.reverse_search_history("b"), "")
  115. def test_forward_1(self):
  116. q = self.q
  117. self.assertEqual(q.forward_search_history("a"), "")
  118. #----------------------------------------------------------------------
  119. # utility functions
  120. #----------------------------------------------------------------------
  121. if __name__ == '__main__':
  122. unittest.main()
  123. l=lineobj.ReadLineTextBuffer("First Second Third")