#! /usr/bin/python3 import pexpect import unittest import re import os import subprocess import signal import time keytab = { "": "\033[1~", "": "\033[1;2H", "": "\033[1;5H", "": "\033[4~", "": "\033[1;2F", "": "\033[1;5F", "": "\033[2~", "": "\033[2;2~", "": "\033[2;5~", "": "\033[3~", "": "\033[3;2~", "": "\033[3;5~", "": "\033[5~", "": "\033[5;5~", "": "\033[6~", "": "\033[6;5~", "": "", "": "\t", "": "\r", "": "\n", "": "\033[D", "": "\033[1;2D", "": "\033OD", "": "\033[C", "": "\033[1;2C", "": "\033OC", "": "\033[A", "": "\033[1;2A", "": "\033OA", "": "\033[B", "": "\033[1;2B", "": "\033OB", "": "\033[1;5D", "": "\033[1;5C", "": "\033[1;5A", "": "\033[1;5B", "": "\033[1;3D", "": "\033[1;3C", "": "\033[1;3A", "": "\033[1;3B", "": "", "": "", "": "", "": "", "": "", "": "", "": " ", "": " ", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "\033b", "": "\033c", "": "\033d", "": "\033f", "": "\033l", "": "\033n", "": "\033p", "": "\033u", "": "\033y", "": "\033.", "": "\033\177", "": "\033OP", "": "\033OQ", "": "\033OR", "": "\033OS", "": "\033[15~", "": "\033[17~", "": "\033[18~", "": "\033[19~", "": "\033[20~", "": "\033[21~", "": "\033[23~", "": "\033[24~", "": "\033[1;2P", "": "\033[1;2Q", "": "\033[1;2R", "": "\033[1;2S", "": "\033[15;2~", "": "\033[17;2~", "": "\033[18;2~", "": "\033[19;2~", "": "\033[20;2~", "": "\033[21;2~", "": "\033[23;2~", "": "\033[24;2~", "": "\033[1;5P", "": "\033[1;5Q", "": "\033[1;5R", "": "\033[1;5S", "": "\033[15;5~", "": "\033[17;5~", "": "\033[18;5~", "": "\033[19;5~", "": "\033[20;5~", "": "\033[21;5~", "": "\033[23;5~", "": "\033[24;5~", "": "\033[Z", "": "\033[200~", "": "\033[201~" } termseq = { "\x1bc": "", "\x1b[0m": "", "\x1b[H": "", "\x1b[2J": "", "\x1b[J": "", "\x1b[0;22;30m": "", "\x1b[0;22;31m": "", "\x1b[0;22;32m": "", "\x1b[0;22;33m": "", "\x1b[0;22;34m": "", "\x1b[0;22;35m": "", "\x1b[0;22;36m": "", "\x1b[0;22;37m": "", "\x1b[0;1;30m": "", "\x1b[0;1;31m": "", "\x1b[0;1;32m": "", "\x1b[0;1;33m": "", "\x1b[0;1;34m": "", "\x1b[0;1;35m": "", "\x1b[0;1;36m": "", "\x1b[0;1;37m": "", "\x1b[1;32m": "", "\x1b[101;1;33m": "", "\x07": "", "\x1b[2~": "", "\x1b[?2004h": "", "\x1b[?2004l": "" } colRe = re.compile( "\\x1b\\[(\\d+)G" ) upRe = re.compile( "\\x1b\\[(\\d+)A" ) downRe = re.compile( "\\x1b\\[(\\d+)B" ) def sym_to_raw( str_ ): for sym, seq in keytab.items(): if isinstance( str_, Rapid ): str_ = Rapid( str_.replace( sym, seq ) ) else: str_ = str_.replace( sym, seq ) return str_ def seq_to_sym( str_ ): for seq, sym in termseq.items(): str_ = str_.replace( seq, sym ) str_ = colRe.sub( "", str_ ) str_ = upRe.sub( "", str_ ) str_ = downRe.sub( "", str_ ) return str_ _words_ = [ "ada", "algol" "bash", "basic", "clojure", "cobol", "csharp", "eiffel", "erlang", "forth", "fortran", "fsharp", "go", "groovy", "haskell", "huginn", "java", "javascript", "julia", "kotlin", "lisp", "lua", "modula", "nemerle", "ocaml", "perl", "php", "prolog", "python", "rebol", "ruby", "rust", "scala", "scheme", "sql", "swift", "typescript" ] def skip( test_ ): return "SKIP" in os.environ and os.environ["SKIP"].find( test_ ) >= 0 verbosity = None class Rapid( str ): pass def rapid( item ): if isinstance( item, str ): r = Rapid( item ) return r return list( map( Rapid, item ) ) class ReplxxTests( unittest.TestCase ): _prompt_ = "\033\\[1;32mreplxx\033\\[0m> " _cxxSample_ = "./build/debug/replxx-example-cxx-api" _cSample_ = "./build/debug/replxx-example-c-api" _end_ = "\r\nExiting Replxx\r\n" def send_str( self_, str_, intraKeyDelay_ ): if isinstance(str_, Rapid): self_._replxx.send( str_ ) return for char in str_: self_._replxx.send( char ) time.sleep( intraKeyDelay_ ) def check_scenario( self_, seq_, expected_, history = "one\ntwo\nthree\n", term = "xterm", command = _cxxSample_, dimensions = ( 25, 80 ), prompt = _prompt_, end = _prompt_ + _end_, encoding = "utf-8", pause = 0.25, intraKeyDelay = 0.002 ): with open( "replxx_history.txt", "wb" ) as f: f.write( history.encode( encoding ) ) f.close() os.environ["TERM"] = term if isinstance( command, str ): command = command.replace( "\n", "~" ) if verbosity >= 2: print( "\nTERM: {}, SIZE: {}, CMD: {}".format( term, dimensions, command ) ) prompt = prompt.replace( "\n", "\r\n" ).replace( "\r\r", "\r" ) end = end.replace( "\n", "\r\n" ).replace( "\r\r", "\r" ) if isinstance( command, str ): self_._replxx = pexpect.spawn( command, maxread = 1, encoding = encoding, dimensions = dimensions ) else: self_._replxx = pexpect.spawn( command[0], args = command[1:], maxread = 1, encoding = encoding, dimensions = dimensions ) self_._replxx.expect( prompt ) self_.maxDiff = None if isinstance( seq_, str ): if isinstance( seq_, Rapid ): seqs = rapid( seq_.split( "" ) ) else: seqs = seq_.split( "" ) for seq in seqs: last = seq is seqs[-1] if not last: seq += "" self_.send_str( sym_to_raw( seq ), intraKeyDelay ) if not last: time.sleep( pause ) self_._replxx.kill( signal.SIGCONT ) else: for seq in seq_: last = seq is seq_[-1] self_.send_str( sym_to_raw( seq ), intraKeyDelay ) if not last: time.sleep( pause ) self_._replxx.expect( end ) if isinstance( expected_, str ): self_.assertSequenceEqual( seq_to_sym( self_._replxx.before ), expected_ ) else: try: self_.assertIn( seq_to_sym( self_._replxx.before ), expected_ ) except: self_.assertSequenceEqual( seq_to_sym( self_._replxx.before ), "" ) def test_unicode( self_ ): self_.check_scenario( "", "a贸膮 熄 饟 髢攢 " "a贸膮 熄 饟 髢攢 \r\n" "a贸膮 熄 饟 髢攢 \r\n", "a贸膮 熄 饟 髢攢 \n" ) self_.check_scenario( "a贸膮 熄 饟 髢攢 ", "aa贸a贸膮a贸膮 " "a贸膮 熄a贸膮 熄 " "a贸膮 熄 饟a贸膮 熄 饟 " "a贸膮 熄 饟 " "a贸膮 熄 饟 髢攢a贸膮 熄 饟 髢攢 " "a贸膮 熄 饟 髢攢 " "a贸膮 熄 饟 髢攢 \r\n" "a贸膮 熄 饟 髢攢 \r\n" ) @unittest.skipIf( skip( "8bit_encoding" ), "broken platform" ) def test_8bit_encoding( self_ ): LC_CTYPE = "LC_CTYPE" exists = LC_CTYPE in os.environ lcCtype = None if exists: lcCtype = os.environ[LC_CTYPE] os.environ[LC_CTYPE] = "pl_PL.ISO-8859-2" self_.check_scenario( "", "text ~贸~text ~贸~\r\ntext ~贸~\r\n", "text ~贸~\n", encoding = "iso-8859-2" ) if exists: os.environ[LC_CTYPE] = lcCtype else: del os.environ[LC_CTYPE] def test_bad_term( self_ ): self_.check_scenario( "a line of text", "a line of text\r\na line of text\r\n", term = "dumb" ) def test_ctrl_c( self_ ): self_.check_scenario( "abc", "aababcabc^C\r" "\r\n" ) def test_ctrl_z( self_ ): self_.check_scenario( "", "threereplxx> " "threethree\r\n" "three\r\n" ) self_.check_scenario( "w", "(reverse-i-search)`': " "(reverse-i-search)`w': " "two(reverse-i-search)`w': " "tworeplxx> " "two\r\n" "two\r\n" ) def test_ctrl_l( self_ ): self_.check_scenario( "", "\r\n" "replxx> \r\n" "replxx> \r\n" "replxx> replxx> " "", end = "\r\nExiting Replxx\r\n" ) self_.check_scenario( "", "\r\n" "replxx> first " "secondfirst " "secondreplxx> " "first secondfirst second\r\n" "first second\r\n", "first second\n" ) def test_backspace( self_ ): self_.check_scenario( "", "one two threeone two " "threeone two threeone two " "threeone tw threeone t " "threeone threeone " "threeone three\r\n" "one three\r\n", "one two three\n" ) def test_delete( self_ ): self_.check_scenario( "", "one two threeone two " "threeone two threeone wo " "threeone o threeone " "threeone threeone three\r\n" "one three\r\n", "one two three\n" ) def test_home_key( self_ ): self_.check_scenario( "abcz", "aababcabczabczabc\r\n" "zabc\r\n" ) def test_end_key( self_ ): self_.check_scenario( "abczq", "aababcabczabczabczabcqzabcq\r\n" "zabcq\r\n" ) def test_left_key( self_ ): self_.check_scenario( "abcxy", "aababcabcabxcabxcabxcaybxcaybxc\r\n" "aybxc\r\n" ) def test_right_key( self_ ): self_.check_scenario( "abcxy", "aababcabcabcaxbcaxbcaxbycaxbyc\r\n" "axbyc\r\n" ) def test_prev_word_key( self_ ): self_.check_scenario( "abc def ghix", "aababcabc " "abc dabc " "deabc defabc " "def abc def " "gabc def ghabc " "def ghiabc def ghiabc def " "ghiabc xdef ghiabc xdef " "ghi\r\n" "abc xdef ghi\r\n" ) def test_next_word_key( self_ ): self_.check_scenario( "abc def ghix", "aababcabc " "abc dabc " "deabc defabc " "def abc def " "gabc def ghabc " "def ghiabc def ghiabc def " "ghiabc def ghiabc defx " "ghiabc defx ghi\r\n" "abc defx ghi\r\n" ) def test_hint_show( self_ ): self_.check_scenario( "co\r", "cco\r\n" " color_black\r\n" " color_red\r\n" " color_greenco\r\n" "co\r\n" ) self_.check_scenario( "", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " "color_brightgreenzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " "color_brightgreen\r\n" "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz color_brightgreen\r\n", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz color_brightgreen\n", dimensions = ( 64, 16 ) ) def test_hint_scroll_down( self_ ): self_.check_scenario( "co", "cco\r\n" " color_black\r\n" " color_red\r\n" " " "color_greencolor_black\r\n" " color_red\r\n" " color_green\r\n" " " "color_browncolor_red\r\n" " color_green\r\n" " color_brown\r\n" " " "color_bluecolor_redcolor_red\r\n" "color_red\r\n" ) def test_hint_scroll_up( self_ ): self_.check_scenario( "co", "cco\r\n" " color_black\r\n" " color_red\r\n" " " "color_greencolor_normal\r\n" " co\r\n" " color_black\r\n" " " "color_redcolor_white\r\n" " color_normal\r\n" " co\r\n" " " "color_blackcolor_whitecolor_white\r\n" "color_white\r\n" ) def test_history( self_ ): self_.check_scenario( "four", "threetwoonetwothreeffofoufourfour\r\n" "four\r\n" ) with open( "replxx_history.txt", "rb" ) as f: data = f.read().decode() self_.assertSequenceEqual( data[:-33], "### 0000-00-00 00:00:00.000\none\n### 0000-00-00 00:00:00.000\ntwo\n### 0000-00-00 00:00:00.000\nthree\n" ) self_.assertSequenceEqual( data[-5:], "four\n" ) def test_paren_matching( self_ ): self_.check_scenario( "ab(cd)ef", "aabab(ab(cab(cdab(cd)ab(cd)eab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)efab(cd)ef\r\n" "ab(cd)ef\r\n" ) def test_paren_not_matched( self_ ): self_.check_scenario( "a(b[c)d", "aa(a(ba(b[a(b[ca(b[c)a(b[c)da(b[c)da(b[c)da(b[c)da(b[c)da(b[c)da(b[c)da(b[c)da(b[c)d\r\n" "a(b[c)d\r\n" ) def test_tab_completion( self_ ): self_.check_scenario( "cobrib", "cco\r\n" " color_black\r\n" " color_red\r\n" " color_greencolor_\r\n" " color_black\r\n" " color_red\r\n" " color_greencolor_\r\n" "color_black " "color_cyan " "color_brightblue\r\n" "color_red " "color_lightgray " "color_brightmagenta\r\n" "color_green " "color_gray " "color_brightcyan\r\n" "color_brown " "color_brightred color_white\r\n" "color_blue " "color_brightgreen color_normal\r\n" "color_magenta color_yellow\r\n" "replxx> color_\r\n" " color_black\r\n" " color_red\r\n" " color_greencolor_b\r\n" " color_black\r\n" " color_brown\r\n" " color_bluecolor_br\r\n" " color_brown\r\n" " color_brightred\r\n" " " "color_brightgreencolor_bri\r\n" " color_brightred\r\n" " color_brightgreen\r\n" " " "color_brightbluecolor_bright\r\n" " color_brightred\r\n" " color_brightgreen\r\n" " " "color_brightbluecolor_brightbluecolor_brightbluecolor_brightblue\r\n" "color_brightblue\r\n" ) self_.check_scenario( "n", "nn\r\nn\r\n", dimensions = ( 4, 32 ), command = [ ReplxxTests._cSample_, "q1", "e0" ] ) self_.check_scenario( "n", "\r\n" "db\r\n" "hello\r\n" "hallo\r\n" "--More--\r" "\t\t\t\t\r" "replxx> " "\r\n", dimensions = ( 4, 24 ), command = ReplxxTests._cSample_ + " q1 e1" ) self_.check_scenario( "co", "abcd()" "abcd()" "cabcd()" "coabcd()" "color_abcd()" "color_abcd()\r\n" "color_abcd()\r\n", "abcd()\n" ) def test_completion_shorter_result( self_ ): self_.check_scenario( "", "\\pi\r\n" "蟺\r\n", "\\pi\n" ) def test_completion_pager( self_ ): cmd = ReplxxTests._cSample_ + " q1 x" + ",".join( _words_ ) self_.check_scenario( "py", "\r\n" "ada groovy perl\r\n" "algolbash haskell php\r\n" "basic huginn prolog\r\n" "clojure java python\r\n" "cobol javascript rebol\r\n" "csharp julia ruby\r\n" "eiffel kotlin rust\r\n" "erlang lisp scala\r\n" "forth lua scheme\r\n" "--More--\r" "\t\t\t\t\r" "fortran modula sql\r\n" "fsharp nemerle swift\r\n" "go ocaml typescript\r\n" "replxx> " "\r\n", dimensions = ( 10, 40 ), command = cmd ) self_.check_scenario( "", "\r\n" "ada groovy perl\r\n" "algolbash haskell php\r\n" "basic huginn prolog\r\n" "clojure java python\r\n" "cobol javascript rebol\r\n" "csharp julia ruby\r\n" "eiffel kotlin rust\r\n" "erlang lisp scala\r\n" "forth lua scheme\r\n" "--More--\r" "\t\t\t\t\r" "fortran modula sql\r\n" "--More--\r" "\t\t\t\t\r" "fsharp nemerle swift\r\n" "--More--\r" "\t\t\t\t\r" "go ocaml typescript\r\n" "replxx> " "\r\n", dimensions = ( 10, 40 ), command = cmd ) self_.check_scenario( "", "\r\n" "ada kotlin\r\n" "algolbash lisp\r\n" "basic lua\r\n" "clojure modula\r\n" "cobol nemerle\r\n" "csharp ocaml\r\n" "eiffel perl\r\n" "--More--^C\r\n" "replxx> " "\r\n", dimensions = ( 8, 32 ), command = cmd ) self_.check_scenario( "q", "\r\n" "ada kotlin\r\n" "algolbash lisp\r\n" "basic lua\r\n" "clojure modula\r\n" "cobol nemerle\r\n" "csharp ocaml\r\n" "eiffel perl\r\n" "--More--\r" "\t\t\t\t\r" "replxx> " "\r\n", dimensions = ( 8, 32 ), command = cmd ) def test_double_tab_completion( self_ ): cmd = ReplxxTests._cSample_ + " d1 q1 x" + ",".join( _words_ ) self_.check_scenario( "for", "f\r\n" " forth\r\n" " fortran\r\n" " fsharpfo\r\n" " forth\r\n" " fortranfort\r\n" " forth\r\n" " " "fortranfortranfortranfortran\r\n" "fortran\r\n", command = cmd ) def test_beep_on_ambiguous_completion( self_ ): cmd = ReplxxTests._cSample_ + " b1 d1 q1 x" + ",".join( _words_ ) self_.check_scenario( "for", "f\r\n" " forth\r\n" " fortran\r\n" " fsharpfo\r\n" " forth\r\n" " fortranfort\r\n" " forth\r\n" " " "fortranfortranfortranfortran\r\n" "fortran\r\n", command = cmd ) def test_history_search_backward( self_ ): self_.check_scenario( "repl", "(reverse-i-search)`': " "(reverse-i-search)`r': echo repl " "golf(reverse-i-search)`re': echo repl " "golf(reverse-i-search)`rep': echo repl " "golf(reverse-i-search)`repl': echo repl " "golf(reverse-i-search)`repl': charlie repl " "deltareplxx> charlie repl " "delta\r\n" "charlie repl delta\r\n", "some command\n" "alfa repl bravo\n" "other request\n" "charlie repl delta\n" "misc input\n" "echo repl golf\n" "final thoughts\n" ) self_.check_scenario( "fors", "(reverse-i-search)`': " "(reverse-i-search)`f': " "swift(reverse-i-search)`fo': " "fortran(reverse-i-search)`for': " "fortran(reverse-i-search)`fo': " "fortran(reverse-i-search)`f': " "swift(reverse-i-search)`fs': " "fsharpreplxx> " "fsharp\r\n" "fsharp\r\n", "\n".join( _words_ ) + "\n" ) self_.check_scenario( "mod", "(reverse-i-search)`': " "(reverse-i-search)`m': " "scheme(reverse-i-search)`mo': " "modula(reverse-i-search)`mod': " "modulareplxx> " "replxx> " "\r\n", "\n".join( _words_ ) + "\n" ) def test_history_search_forward( self_ ): self_.check_scenario( "repl", "(i-search)`': (i-search)`r': " "(i-search)`re': (i-search)`rep': " "(i-search)`repl': " "(i-search)`repl': " "replxx> \r\n", "charlie repl delta\r\n", "some command\n" "alfa repl bravo\n" "other request\n" "charlie repl delta\n" "misc input\n" "echo repl golf\n" "final thoughts\n" ) self_.check_scenario( "repl", "final thoughts(i-search)`': final " "thoughts(i-search)`r': echo repl " "golf(i-search)`re': echo repl " "golf(i-search)`rep': echo repl " "golf(i-search)`repl': echo repl " "golf(i-search)`repl': alfa repl " "bravoreplxx> alfa repl bravofinal " "thoughts\r\n" "alfa repl bravo\r\n", "final thoughts\n" "echo repl golf\n" "misc input\n" "charlie repl delta\n" "other request\n" "alfa repl bravo\n" "some command\n" "charlie repl delta\r\n", ) self_.check_scenario( "fors", "(i-search)`': (i-search)`f': " "(i-search)`fo': (i-search)`for': " "(i-search)`fo': (i-search)`f': " "(i-search)`fs': " "replxx> \r\n", "\n".join( _words_[::-1] ) + "\n" ) self_.check_scenario( "fors", "typescript(i-search)`': " "typescript(i-search)`f': swift(i-search)`fo': " "fortran(i-search)`for': fortran(i-search)`fo': " "fortran(i-search)`f': swift(i-search)`fs': " "fsharpreplxx> " "fsharptypescript\r\n" "fsharp\r\n", "\n".join( _words_[::-1] ) + "\n" ) self_.check_scenario( "mod", "(i-search)`': (i-search)`m': " "(i-search)`mo': (i-search)`mod': " "replxx> " "replxx> " "\r\n", "\n".join( _words_[::-1] ) + "\n" ) self_.check_scenario( "mod", "typescript(i-search)`': " "typescript(i-search)`m': scheme(i-search)`mo': " "modula(i-search)`mod': " "modulareplxx> " "typescriptreplxx> " "typescripttypescript\r\n" "typescript\r\n", "\n".join( _words_[::-1] ) + "\n" ) def test_history_search_backward_position( self_ ): self_.check_scenario( "req", "(reverse-i-search)`': " "(reverse-i-search)`r': echo repl " "golf(reverse-i-search)`re': echo repl " "golf(reverse-i-search)`req': other " "requestreplxx> other requestalfa " "repl bravoalfa repl bravo\r\n" "alfa repl bravo\r\n", "some command\n" "alfa repl bravo\n" "other request\n" "charlie repl delta\n" "misc input\n" "echo repl golf\n" "final thoughts\n" ) def test_history_search_overlong_line( self_ ): self_.check_scenario( "lo", "(reverse-i-search)`': " "(reverse-i-search)`l': some very long line of text, much " "longer then a witdth of a terminal, " "seriously(reverse-i-search)`lo': some very long line of " "text, much longer then a witdth of a terminal, " "seriouslyreplxx> some very long line of " "text, much longer then a witdth of a terminal, " "seriously\r\n" "some very long line of text, much longer then a witdth of a terminal, " "seriously\r\n", "fake\nsome very long line of text, much longer then a witdth of a terminal, seriously\nanother fake", dimensions = ( 24, 64 ) ) def test_history_prefix_search_backward( self_ ): self_.check_scenario( "repl", "rrerepreplrepl_echo " "golfrepl_charlie " "deltarepl_charlie delta\r\n" "repl_charlie delta\r\n", "some command\n" "repl_alfa bravo\n" "other request\n" "repl_charlie delta\n" "misc input\n" "repl_echo golf\n" "final thoughts\n" ) def test_history_prefix_search_backward_position( self_ ): self_.check_scenario( "repl", "rrerepreplrepl_echo " "golfmisc inputmisc " "input\r\n" "misc input\r\n", "some command\n" "repl_alfa bravo\n" "other request\n" "repl_charlie delta\n" "misc input\n" "repl_echo golf\n" "final thoughts\n" ) def test_history_listing( self_ ): self_.check_scenario( "", ".history.history\r\n" " 0: some command\r\n" " 1: repl_alfa bravo\r\n" " 2: other request\r\n" " 3: repl_charlie delta\r\n" " 4: misc input\r\n" " 5: repl_echo golf\r\n" " 6: .history\r\n", "some command\n" "repl_alfa bravo\n" "other request\n" "repl_charlie delta\n" "misc input\n" "repl_echo golf\n" ".history\n" ) self_.check_scenario( "", "/history/history\r\n" " 0: some command\r\n" " 1: repl_alfa bravo\r\n" " 2: other request\r\n" " 3: repl_charlie delta\r\n" " 4: misc input\r\n" " 5: repl_echo golf\r\n" " 6: /history\r\n" "/history\r\n", "some command\n" "repl_alfa bravo\n" "other request\n" "repl_charlie delta\n" "misc input\n" "repl_echo golf\n" "/history\n", command = ReplxxTests._cSample_ + " q1" ) def test_history_browse( self_ ): self_.check_scenario( "", "twelve" "eleven" "one" "two" "one" "two" "" "twelve" "" "twelve" "twelve\r\n" "twelve\r\n", "one\n" "two\n" "three\n" "four\n" "five\n" "six\n" "seven\n" "eight\n" "nine\n" "ten\n" "eleven\n" "twelve\n" ) def test_history_max_size( self_ ): self_.check_scenario( "a", "threeaa\r\n" "a\r\n" "replxx> " "fourfour\r\n" "four\r\n", "one\n" "two\n" "three\n" "four\n" "five\n", command = ReplxxTests._cSample_ + " q1 s3" ) def test_history_unique( self_ ): self_.check_scenario( "abab", "aa\r\n" "a\r\n" "replxx> bb\r\n" "b\r\n" "replxx> aa\r\n" "a\r\n" "replxx> bb\r\n" "b\r\n" "replxx> " "bacc\r\n" "c\r\n", "a\nb\nc\n", command = ReplxxTests._cSample_ + " u1 q1" ) self_.check_scenario( "abab", "aa\r\n" "a\r\n" "replxx> bb\r\n" "b\r\n" "replxx> aa\r\n" "a\r\n" "replxx> bb\r\n" "b\r\n" "replxx> " "babb\r\n" "b\r\n", "a\nb\nc\n", command = ReplxxTests._cSample_ + " u0 q1" ) self_.check_scenario( rapid( "/history\n/unique\n/history\n" ), "//history\r\n" " 0: a\r\n" " 1: b\r\n" " 2: c\r\n" " 3: b\r\n" " 4: c\r\n" " 5: d\r\n" " 6: a\r\n" " 7: c\r\n" " 8: c\r\n" " 9: a\r\n" "/history\r\n" "replxx> /unique\r\n" "/unique\r\n" "replxx> /history\r\n" " 0: b\r\n" " 1: d\r\n" " 2: c\r\n" " 3: a\r\n" " 4: /history\r\n" " 5: /unique\r\n" "/history\r\n", "a\nb\nc\nb\nc\nd\na\nc\nc\na\n", command = ReplxxTests._cSample_ + " u0 q1" ) def test_history_recall_most_recent( self_ ): self_.check_scenario( "", "aaaabbbbbbbb\r\n" "bbbb\r\n" "replxx> " "cccccccc\r\n" "cccc\r\n", "aaaa\nbbbb\ncccc\ndddd\n" ) def test_history_abort_incremental_history_search_position( self_ ): self_.check_scenario( "cc", "hhhhgggg(reverse-i-search)`': " "gggg(reverse-i-search)`c': " "cccc(reverse-i-search)`cc': " "ccccreplxx> " "ggggggggffffffff\r\n" "ffff\r\n", "aaaa\nbbbb\ncccc\ndddd\neeee\nffff\ngggg\nhhhh\n" ) def test_capitalize( self_ ): self_.check_scenario( "", "abc defg ijklmn zzxqabc defg ijklmn " "zzxqabc defg ijklmn zzxqaBc defg " "ijklmn zzxqaBc Defg ijklmn zzxqaBc " "Defg ijklmn zzxqaBc Defg ijklmn " "zzxqaBc Defg iJklmn zzxqaBc Defg " "iJklmn ZzxqaBc Defg iJklmn Zzxq\r\n" "aBc Defg iJklmn Zzxq\r\n", "abc defg ijklmn zzxq\n" ) def test_make_upper_case( self_ ): self_.check_scenario( "", "abcdefg hijklmno pqrstuvwabcdefg " "hijklmno pqrstuvwabcdefg hijklmno " "pqrstuvwabcdefg hijklmno " "pqrstuvwabcdefg hijklmno " "pqrstuvwabcDEFG hijklmno " "pqrstuvwabcDEFG HIJKLMNO " "pqrstuvwabcDEFG HIJKLMNO " "pqrstuvwabcDEFG HIJKLMNO " "PQRSTUVWabcDEFG HIJKLMNO " "PQRSTUVW\r\n" "abcDEFG HIJKLMNO PQRSTUVW\r\n", "abcdefg hijklmno pqrstuvw\n" ) def test_make_lower_case( self_ ): self_.check_scenario( "", "ABCDEFG HIJKLMNO PQRSTUVWABCDEFG " "HIJKLMNO PQRSTUVWABCDEFG HIJKLMNO " "PQRSTUVWABCDEFG HIJKLMNO " "PQRSTUVWABCDEFG HIJKLMNO " "PQRSTUVWABCdefg HIJKLMNO " "PQRSTUVWABCdefg hijklmno " "PQRSTUVWABCdefg hijklmno " "PQRSTUVWABCdefg hijklmno " "pqrstuvwABCdefg hijklmno " "pqrstuvw\r\n" "ABCdefg hijklmno pqrstuvw\r\n", "ABCDEFG HIJKLMNO PQRSTUVW\n" ) def test_transpose( self_ ): self_.check_scenario( "", "abcd" "abcd" "abcd" "bacd" "bcad" "bcda" "bcad" "bcda" "bcda\r\n" "bcda\r\n", "abcd\n" ) def test_kill_to_beginning_of_line( self_ ): self_.check_scenario( "", "+abc defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq+-ijklmn " "zzxq+-ijklmn " "zzxq+-ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc defg-\r\n" "-ijklmn zzxq++abc defg-\r\n", "+abc defg--ijklmn zzxq+\n" ) def test_kill_to_end_of_line( self_ ): self_.check_scenario( "", "+abc defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc " "defg-+abc " "defg--ijklmn " "zzxq++abc " "defg--ijklmn " "zzxq++abc defg-\r\n" "-ijklmn zzxq++abc defg-\r\n", "+abc defg--ijklmn zzxq+\n" ) def test_kill_next_word( self_ ): self_.check_scenario( "", "alpha charlie bravo deltaalpha " "charlie bravo deltaalpha charlie bravo " "deltaalpha bravo deltaalpha bravo " "deltaalpha bravo charlie deltaalpha " "bravo charlie delta\r\n" "alpha bravo charlie delta\r\n", "alpha charlie bravo delta\n" ) def test_kill_prev_word_to_white_space( self_ ): self_.check_scenario( "", "alpha charlie bravo deltaalpha " "charlie bravo deltaalpha charlie " "deltaalpha charlie deltaalpha bravo " "charlie deltaalpha bravo charlie delta\r\n" "alpha bravo charlie delta\r\n", "alpha charlie bravo delta\n" ) def test_kill_prev_word( self_ ): self_.check_scenario( "", "alpha.charlie " "bravo.deltaalpha.charlie " "bravo.deltaalpha.charlie " "deltaalpha.charlie " "deltaalpha.bravo.charlie " "deltaalpha.bravo.charlie " "delta\r\n" "alpha.bravo.charlie delta\r\n", "alpha.charlie bravo.delta\n" ) def test_kill_ring( self_ ): self_.check_scenario( " ", "delta charlie bravo alphadelta " "charlie bravo delta charlie " "bravodelta charlie " "delta " "charliedelta " "" "delta" "" "delta" "charlie" "bravo" "alpha" "alpha " "alpha " "alphaalpha " "deltaalpha " "charliealpha " "bravoalpha bravo " "alpha bravo " "bravoalpha bravo " "alphaalpha bravo " "deltaalpha bravo " "charliealpha bravo charlie " "alpha bravo charlie " "charliealpha bravo charlie " "bravoalpha bravo charlie " "alphaalpha bravo charlie " "deltaalpha bravo charlie delta\r\n" "alpha bravo charlie delta\r\n", "delta charlie bravo alpha\n" ) self_.check_scenario( " ", "charlie delta alpha bravocharlie " "delta alpha charlie delta " "charlie " "deltacharlie deltaalpha " "bravocharlie deltaalpha bravo charlie " "deltaalpha bravo charlie delta\r\n" "alpha bravo charlie delta\r\n", "charlie delta alpha bravo\n" ) self_.check_scenario( " ", "charlie delta alpha bravocharlie " "delta alpha bravo delta alpha bravo " "alpha bravoalpha bravoalpha " "bravoalpha bravo " "alpha bravo charlie " "deltaalpha bravo charlie delta\r\n" "alpha bravo charlie delta\r\n", "charlie delta alpha bravo\n" ) self_.check_scenario( "" "" "", "a b c d e f g h i j ka b c d e f g " "h i j a b c d e f g h i " "ja b c d e f g h i " "a b c d e f g h " "ia b c d e f g h " "a b c d e f g " "ha b c d e f g " "a b c d e f ga " "b c d e f a b c d e " "fa b c d e a b " "c d ea b c d a " "b c da b c a b " "ca b a " "ba " "" "a" "" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "a" "a\r\n" "a\r\n", "a b c d e f g h i j k\n" ) def test_yank_last_arg( self_ ): self_.check_scenario( "0123", "0" "01" "012" "0123" "0123" "0123" "01cat23" "01trillion23" "01twelve23" "01twelve23\r\n" "01twelve23\r\n", "one two three\nten eleven twelve\nmillion trillion\ndog cat\n" ) self_.check_scenario( " ", "dog catmillion trillionten " "eleven twelveten eleven twelve ten " "eleven twelve catten eleven twelve " "trillionten eleven twelve trillion\r\n" "ten eleven twelve trillion\r\n", "one two three\nten eleven twelve\nmillion trillion\ndog cat\n" ) def test_tab_completion_cutoff( self_ ): self_.check_scenario( "ny", "\r\n" "Display all 9 possibilities? (y or n)\r\n" "replxx> " "\r\n" "Display all 9 possibilities? (y or n)\r\n" "db hallo hansekogge quetzalcoatl power\r\n" "hello hans seamann quit\r\n" "replxx> " "\r\n", command = ReplxxTests._cSample_ + " q1 c3" ) self_.check_scenario( "n", "\r\n" "Display all 9 possibilities? (y or n)\r\n" "replxx> " "\r\n", command = ReplxxTests._cSample_ + " q1 c3" ) self_.check_scenario( "", "\r\n" "Display all 9 possibilities? (y or n)^C\r\n" "replxx> " "\r\n", command = ReplxxTests._cSample_ + " q1 c3" ) self_.check_scenario( ["", ""], "\r\n" "Display all 9 possibilities? (y or n)^C\r\n" "replxx> " "\r\n", command = ReplxxTests._cSample_ + " q1 c3 H200" ) def test_preload( self_ ): self_.check_scenario( "", "Alice has a cat." "Alice has a cat.\r\n" "Alice has a cat.\r\n", command = ReplxxTests._cSample_ + " q1 'iAlice has a cat.'" ) self_.check_scenario( "", "Cat eats mice. " "Cat eats mice. " "\r\n" "Cat eats mice. " "\r\n", command = ReplxxTests._cSample_ + " q1 'iCat\teats\tmice.\r\n'" ) self_.check_scenario( "", "Cat eats mice. " "Cat eats mice. " "\r\n" "Cat eats mice. " "\r\n", command = ReplxxTests._cSample_ + " q1 'iCat\teats\tmice.\r\n\r\n\n\n'" ) self_.check_scenario( "", "M Alice has a cat." "M Alice has a cat.\r\n" "M Alice has a cat.\r\n", command = ReplxxTests._cSample_ + " q1 'iMAlice has a cat.'" ) self_.check_scenario( "", "M Alice has a cat." "M Alice has a cat.\r\n" "M Alice has a cat.\r\n", command = ReplxxTests._cSample_ + " q1 'iM\t\t\t\tAlice has a cat.'" ) def test_prompt( self_ ): prompt = "date: now\nrepl> " self_.check_scenario( "", "threethree\r\n" "three\r\n" "date: now\r\n" "repl> " "threetwotwo\r\n" "two\r\n", command = ReplxxTests._cSample_ + " q1 'p{}'".format( prompt ), prompt = prompt, end = prompt + ReplxxTests._end_ ) prompt = "repl>\n" self_.check_scenario( "a", "aa\r\na\r\n", command = ReplxxTests._cSample_ + " q1 'p{}'".format( prompt ), prompt = prompt, end = prompt + ReplxxTests._end_ ) def test_long_line( self_ ): self_.check_scenario( "~~~~~~~~~~~~", "ada clojure eiffel fortran groovy java kotlin modula perl python " "rust sqlada clojure eiffel fortran groovy " "java kotlin modula perl python rust sqlada " "clojure eiffel fortran groovy java kotlin modula perl python rust " "~sqlada clojure eiffel fortran groovy java " "kotlin modula perl python rust ~sqlada clojure " "eiffel fortran groovy java kotlin modula perl python ~rust " "~sqlada clojure eiffel fortran groovy java " "kotlin modula perl python ~rust ~sqlada clojure " "eiffel fortran groovy java kotlin modula perl ~python ~rust " "~sqlada clojure eiffel fortran groovy java " "kotlin modula perl ~python ~rust ~sqlada clojure " "eiffel fortran groovy java kotlin modula ~perl ~python ~rust " "~sqlada clojure eiffel fortran groovy java " "kotlin modula ~perl ~python ~rust ~sqlada " "clojure eiffel fortran groovy java kotlin ~modula ~perl ~python ~rust " "~sqlada clojure eiffel fortran groovy java " "kotlin ~modula ~perl ~python ~rust ~sqlada " "clojure eiffel fortran groovy java ~kotlin ~modula ~perl ~python ~rust " "~sqlada clojure eiffel fortran groovy java " "~kotlin ~modula ~perl ~python ~rust ~sqlada " "clojure eiffel fortran groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sqlada clojure eiffel fortran groovy ~java " "~kotlin ~modula ~perl ~python ~rust ~sqlada clojure " "eiffel fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sqlada clojure eiffel fortran ~groovy ~java ~kotlin " "~modula ~perl ~python ~rust ~sqlada clojure eiffel " "~fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sqlada clojure eiffel ~fortran ~groovy ~java " "~kotlin ~modula ~perl ~python ~rust ~sqlada clojure " "~eiffel ~fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sqlada clojure ~eiffel ~fortran ~groovy ~java " "~kotlin ~modula ~perl ~python ~rust ~sqlada ~clojure " "~eiffel ~fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sqlada ~clojure ~eiffel ~fortran ~groovy ~java " "~kotlin ~modula ~perl ~python ~rust ~sql~ada ~clojure " "~eiffel ~fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sql~ada ~clojure ~eiffel ~fortran ~groovy ~java " "~kotlin ~modula ~perl ~python ~rust ~sql~ada ~clojure " "~eiffel ~fortran ~groovy ~java ~kotlin ~modula ~perl ~python ~rust " "~sql\r\n" "~ada ~clojure ~eiffel ~fortran ~groovy ~java ~kotlin ~modula ~perl ~python " "~rust ~sql\r\n", " ".join( _words_[::3] ) + "\n", dimensions = ( 10, 40 ) ) def test_colors( self_ ): self_.check_scenario( "", "color_black color_red " "color_green color_brown color_blue " "color_magenta color_cyan " "color_lightgray color_gray " "color_brightred color_brightgreen " "color_yellow color_brightblue " "color_brightmagenta color_brightcyan " "color_whitecolor_black " "color_red color_green color_brown " "color_blue color_magenta color_cyan " "color_lightgray color_gray " "color_brightred color_brightgreen " "color_yellow color_brightblue " "color_brightmagenta color_brightcyan " "color_white\r\n" "color_black color_red color_green color_brown color_blue color_magenta " "color_cyan color_lightgray color_gray color_brightred color_brightgreen " "color_yellow color_brightblue color_brightmagenta color_brightcyan " "color_white\r\n", "color_black color_red color_green color_brown color_blue color_magenta color_cyan color_lightgray" " color_gray color_brightred color_brightgreen color_yellow color_brightblue color_brightmagenta color_brightcyan color_white\n" ) def test_word_break_characters( self_ ): self_.check_scenario( "xxxxxx", "one_two three-four five_six " "seven-eightone_two three-four five_six " "seven-eightone_two three-four five_six " "seven-xeightone_two three-four five_six " "seven-xeightone_two three-four five_six " "seven-xeightone_two three-four five_six " "xseven-xeightone_two three-four five_six " "xseven-xeightone_two three-four five_six " "xseven-xeightone_two three-four xfive_six " "xseven-xeightone_two three-four xfive_six " "xseven-xeightone_two three-four xfive_six " "xseven-xeightone_two three-xfour xfive_six " "xseven-xeightone_two three-xfour xfive_six " "xseven-xeightone_two three-xfour xfive_six " "xseven-xeightone_two xthree-xfour xfive_six " "xseven-xeightone_two xthree-xfour xfive_six " "xseven-xeightone_two xthree-xfour xfive_six " "xseven-xeightxone_two xthree-xfour xfive_six " "xseven-xeightxone_two xthree-xfour xfive_six " "xseven-xeight\r\n" "xone_two xthree-xfour xfive_six xseven-xeight\r\n", "one_two three-four five_six seven-eight\n", command = ReplxxTests._cSample_ + " q1 'w \t-'" ) self_.check_scenario( "xxxxxx", "one_two three-four five_six " "seven-eightone_two three-four five_six " "seven-eightone_two three-four five_six " "xseven-eightone_two three-four five_six " "xseven-eightone_two three-four five_six " "xseven-eightone_two three-four five_xsix " "xseven-eightone_two three-four five_xsix " "xseven-eightone_two three-four five_xsix " "xseven-eightone_two three-four xfive_xsix " "xseven-eightone_two three-four xfive_xsix " "xseven-eightone_two three-four xfive_xsix " "xseven-eightone_two xthree-four xfive_xsix " "xseven-eightone_two xthree-four xfive_xsix " "xseven-eightone_two xthree-four xfive_xsix " "xseven-eightone_xtwo xthree-four xfive_xsix " "xseven-eightone_xtwo xthree-four xfive_xsix " "xseven-eightone_xtwo xthree-four xfive_xsix " "xseven-eightxone_xtwo xthree-four xfive_xsix " "xseven-eightxone_xtwo xthree-four xfive_xsix " "xseven-eight\r\n" "xone_xtwo xthree-four xfive_xsix xseven-eight\r\n", "one_two three-four five_six seven-eight\n", command = ReplxxTests._cSample_ + " q1 'w \t_'" ) def test_no_color( self_ ): self_.check_scenario( " X", "color_black color_red color_green color_brown color_blue " "color_magenta color_cyan color_lightgray color_gray color_brightred " "color_brightgreen color_yellow color_brightblue color_brightmagenta " "color_brightcyan color_whitecolor_black color_red " "color_green color_brown color_blue color_magenta color_cyan color_lightgray " "color_gray color_brightred color_brightgreen color_yellow color_brightblue " "color_brightmagenta color_brightcyan color_white " "color_black color_red color_green color_brown color_blue " "color_magenta color_cyan color_lightgray color_gray color_brightred " "color_brightgreen color_yellow color_brightblue color_brightmagenta " "color_brightcyan color_white Xcolor_black color_red " "color_green color_brown color_blue color_magenta color_cyan color_lightgray " "color_gray color_brightred color_brightgreen color_yellow color_brightblue " "color_brightmagenta color_brightcyan color_white X\r\n" "color_black color_red color_green color_brown color_blue color_magenta " "color_cyan color_lightgray color_gray color_brightred color_brightgreen " "color_yellow color_brightblue color_brightmagenta color_brightcyan " "color_white X\r\n", "color_black color_red color_green color_brown color_blue color_magenta color_cyan color_lightgray" " color_gray color_brightred color_brightgreen color_yellow color_brightblue color_brightmagenta color_brightcyan color_white\n", command = ReplxxTests._cSample_ + " q1 m1" ) def test_backspace_long_line_on_small_term( self_ ): self_.check_scenario( "", "\r\n" "replxx> \r\n" "replxx> \r\n" "replxx> " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", dimensions = ( 10, 40 ) ) self_.check_scenario( "", "\r\n" "replxx> \r\n" "replxx> \r\n" "replxx> a qu ite lo ng li ne of sh ort wo rds wi " "ll te st cu rs or mo ve me nta qu ite lo " "ng li ne of sh ort wo rds wi ll te st cu rs or mo ve me " "na qu ite lo ng li ne of sh ort wo rds wi " "ll te st cu rs or mo ve me a qu ite lo ng " "li ne of sh ort wo rds wi ll te st cu rs or mo ve " "mea qu ite lo ng li ne of sh ort wo rds " "wi ll te st cu rs or mo ve ma qu ite lo " "ng li ne of sh ort wo rds wi ll te st cu rs or mo ve " "a qu ite lo ng li ne of sh ort wo rds wi " "ll te st cu rs or mo vea qu ite lo ng li " "ne of sh ort wo rds wi ll te st cu rs or mo ve\r\n" "a qu ite lo ng li ne of sh ort wo rds wi ll te st cu rs or mo ve\r\n", "a qu ite lo ng li ne of sh ort wo rds wi ll te st cu rs or mo ve me nt\n", dimensions = ( 10, 40 ) ) def test_reverse_history_search_on_max_match( self_ ): self_.check_scenario( "", "aaaaaaaaaaaaaaaaaaaaa(reverse-i-search)`': " "aaaaaaaaaaaaaaaaaaaaareplxx> " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" "aaaaaaaaaaaaaaaaaaaaa\r\n", "aaaaaaaaaaaaaaaaaaaaa\n" ) def test_no_terminal( self_ ): res = subprocess.run( [ ReplxxTests._cSample_, "q1" ], input = b"replxx FTW!\n", stdout = subprocess.PIPE, stderr = subprocess.PIPE ) self_.assertSequenceEqual( res.stdout, b"starting...\nreplxx FTW!\n\nExiting Replxx\n" ) def test_async_print( self_ ): self_.check_scenario( [ "a", "b", "c", "d", "e", "f" ], [ "0\r\n" "replxx> " "aab1\r\n" "replxx> " "ababcabcd2\r\n" "replxx> " "abcdabcdeabcdefabcdef\r\n" "abcdef\r\n", "0\r\n" "replxx> " "aab1\r\n" "replxx> " "ababcabcd2\r\n" "replxx> " "abcdabcdeabcdefabcdef\r\n" "abcdef\r\n", ], command = [ ReplxxTests._cxxSample_, "" ], pause = 0.5 ) self_.check_scenario( [ "", "a", "b", "c", "d", "e", "f" ], [ "0\r\n" "replxx> a very long line of " "user input, wider then current terminal, the line is wrapped: " "a very long line of user input, wider then current " "terminal, the line is wrapped: a1\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, " "the line is wrapped: aa very long line of user " "input, wider then current terminal, the line is wrapped: " "aba very long line of user input, wider then current " "terminal, the line is wrapped: abc2\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, " "the line is wrapped: abca very long line of user " "input, wider then current terminal, the line is wrapped: " "abcda very long line of user input, wider then " "current terminal, the line is wrapped: abcde3\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, " "the line is wrapped: abcdea very long line of user " "input, wider then current terminal, the line is wrapped: " "abcdefa very long line of user input, wider then " "current terminal, the line is wrapped: abcdef\r\n" "a very long line of user input, wider then current terminal, the line is " "wrapped: abcdef\r\n", "0\r\n" "replxx> a very long line of user input, " "wider then current terminal, the line is wrapped: a " "very long line of user input, wider then current terminal, the line is " "wrapped: a1\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: aa very long line of user input, " "wider then current terminal, the line is wrapped: " "aba very long line of user input, wider then current " "terminal, the line is wrapped: abc2\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: abca very long line of user input, " "wider then current terminal, the line is wrapped: " "abcd3\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: abcda very long line of user input, " "wider then current terminal, the line is wrapped: " "abcdea very long line of user input, wider then " "current terminal, the line is wrapped: abcdefa very " "long line of user input, wider then current terminal, the line is wrapped: " "abcdef\r\n" "a very long line of user input, wider then current terminal, the line is " "wrapped: abcdef\r\n", "0\r\n" "replxx> a very long line of user input, wider then " "current terminal, the line is wrapped: a very long " "line of user input, wider then current terminal, the line is wrapped: " "a1\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: aa very long line of user input, " "wider then current terminal, the line is wrapped: " "aba very long line of user input, wider then current " "terminal, the line is wrapped: abc2\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: abca very long line of user input, " "wider then current terminal, the line is wrapped: " "abcd3\r\n" "replxx> \r\n" "\r\n" "a very long line of user input, wider then current terminal, the " "line is wrapped: abcda very long line of user input, " "wider then current terminal, the line is wrapped: " "abcdea very long line of user input, wider then " "current terminal, the line is wrapped: abcdefa very " "long line of user input, wider then current terminal, the line is wrapped: " "abcdef\r\n" "a very long line of user input, wider then current terminal, the line is " "wrapped: abcdef\r\n" ], "a very long line of user input, wider then current terminal, the line is wrapped: \n", command = [ ReplxxTests._cxxSample_, "" ], dimensions = ( 10, 40 ), pause = 0.5 ) def test_async_emulate_key_press( self_ ): self_.check_scenario( [ "a", "b", "c", "d", "e", "f" ], [ "11a" "1ab1ab" "21ab2" "c1ab2" "cd1ab2cd3" "1ab2cd3e" "1ab2cd3ef" "1ab2cd3ef\r\n" "1ab2cd3ef\r\n", "1a1ab" "1ab21ab" "2c1ab2cd" "1ab2cd31ab" "2cd3e1ab2cd" "3ef1ab2cd3ef\r\n" "1ab2cd3ef\r\n" ], command = [ ReplxxTests._cxxSample_, "123456" ], pause = 0.5 ) def test_special_keys( self_ ): self_.check_scenario( "" "" "" "" "" "", "\r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" "replxx> \r\n" ) def test_overwrite_mode( self_ ): self_.check_scenario( "XYZ012345", "abcdefghabcdefgh" "abcdefghabcdefgh" "abXcdefghabXYcdefgh" "abXYZcdefghabXYZ0defgh" "abXYZ01efghabXYZ012fgh" "abXYZ0123fghabXYZ01234fgh" "abXYZ012345fghabXYZ012345fgh\r\n" "abXYZ012345fgh\r\n", "abcdefgh\n" ) def test_verbatim_insert( self_ ): self_.check_scenario( ["", rapid( "" ), ""], "^[[2~^[[2~\r\n" "\r\n" ) def test_hint_delay( self_ ): self_.check_scenario( ["han", ""], "hhahanhan\r\n" " hans\r\n" " hansekoggehan\r\n" "han\r\n", command = [ ReplxxTests._cSample_, "q1", "H200" ] ) def test_complete_next( self_ ): self_.check_scenario( "", "color_\r\n" " color_black\r\n" " color_red\r\n" " " "color_greencolor_black" "color_redcolor_blackcolor_\r\n" " color_black\r\n" " color_red\r\n" " " "color_greencolor_normalcolor_normal\r\n" "color_normal\r\n", "color_\n" ) self_.check_scenario( "l", "l\r\n" " lc_ctype\r\n" " lc_time\r\n" " lc_messageslc_\r\n" " lc_ctype\r\n" " lc_time\r\n" " " "lc_messageslc_ctypelc_timelc_ctypelc_\r\n" " lc_ctype\r\n" " lc_time\r\n" " lc_messageslc_\r\n" "lc_\r\n", command = [ ReplxxTests._cSample_, "xlc_ctype,lc_time,lc_messages,zoom", "I1", "q1" ] ) self_.check_scenario( "l", "l\r\n" " lc_ctype\r\n" " lc_time\r\n" " lc_messageslc_\r\n" " lc_ctype\r\n" " lc_time\r\n" " " "lc_messageslc_ctypelc_\r\n" " lc_ctype\r\n" " lc_time\r\n" " " "lc_messageslc_messageslc_messages\r\n" "lc_messages\r\n", command = [ ReplxxTests._cSample_, "xlc_ctype,lc_time,lc_messages,zoom", "I0", "q1" ] ) def test_disabled_handlers( self_ ): self_.check_scenario( "4", "(+ 1 2)(+ 1 " "2)(+ 1 " ")(+ 1 " "4)(+ 1 4)\r\n" "thanks for the input: (+ 1 4)\r\n", "(+ 1 2)\r\n", command = [ ReplxxTests._cSample_, "N", "S" ] ) def test_state_manipulation( self_ ): self_.check_scenario( "~", "replxxREPLXXREP~LXXREP~LXX\r\n" "REP~LXX\r\n", "replxx\n", command = [ ReplxxTests._cSample_, "q1" ] ) def test_modify_callback( self_ ): self_.check_scenario( "*", "abcd12abcd12" "abcd12abcd12" "ababcd12cd12" "ababcd12cd12\r\n" "ababcd12cd12\r\n", "abcd12\n", command = [ ReplxxTests._cSample_, "q1", "M1" ] ) def test_paste( self_ ): self_.check_scenario( rapid( "abcdef" ), "aabcdef\r\nabcdef\r\n" ) def test_history_merge( self_ ): with open( "replxx_history_alt.txt", "w" ) as f: f.write( "### 0000-00-00 00:00:00.001\n" "one\n" "### 0000-00-00 00:00:00.003\n" "three\n" "### 0000-00-00 00:00:00.005\n" "other\n" "### 0000-00-00 00:00:00.009\n" "same\n" "### 0000-00-00 00:00:00.017\n" "seven\n" ) f.close() self_.check_scenario( "", ".merge.merge\r\n", "### 0000-00-00 00:00:00.002\n" "two\n" "### 0000-00-00 00:00:00.004\n" "four\n" "### 0000-00-00 00:00:00.006\n" "same\n" "### 0000-00-00 00:00:00.008\n" "other\n" "### 0000-00-00 00:00:00.018\n" ".merge\n" ) with open( "replxx_history_alt.txt", "r" ) as f: data = f.read() expected = ( "### 0000-00-00 00:00:00.001\n" "one\n" "### 0000-00-00 00:00:00.002\n" "two\n" "### 0000-00-00 00:00:00.003\n" "three\n" "### 0000-00-00 00:00:00.004\n" "four\n" "### 0000-00-00 00:00:00.008\n" "other\n" "### 0000-00-00 00:00:00.009\n" "same\n" "### 0000-00-00 00:00:00.017\n" "seven\n" "### " ) self_.assertSequenceEqual( data[:-31], expected ) self_.assertSequenceEqual( data[-7:], ".merge\n" ) def test_history_save( self_ ): with open( "replxx_history_alt.txt", "w" ) as f: f.write( "### 0000-00-00 00:00:00.001\n" "one\n" "### 0000-00-00 00:00:00.003\n" "three\n" "### 3000-00-00 00:00:00.005\n" "other\n" "### 3000-00-00 00:00:00.009\n" "same\n" "### 3000-00-00 00:00:00.017\n" "seven\n" ) f.close() self_.check_scenario( "zoom.save", "zzozoozoomzoom\r\n" "zoom\r\n" "replxx> " "..s.sa.sav.save.save\r\n" "replxx> " "zoomzoom\r\n" "zoom\r\n" ) def test_bracketed_paste( self_ ): self_.check_scenario( "a0b1c2d3e4f", "a" "a0" "a0b1c2d3e" "a0b1c2d3e4" "a0b1c2d3e4f" "a0b1c2d3e4f\r\n" "a0b1c2d3e4f\r\n", command = [ ReplxxTests._cSample_, "q1" ] ) self_.check_scenario( "a0b1c2d3e4f", "a" "a0" "a0b1c2d3e" "a0b1c2d3e4" "a0b1c2d3e4f" "a0b1c2d3e4f\r\n" "a0b1c2d3e4f\r\n", command = [ ReplxxTests._cSample_, "q1", "B" ] ) self_.check_scenario( "a0/eb/dbx", "aa0a0" "a/eb0a/eb0\r\n" "a/eb0\r\n" "replxx> /db/db\r\n" "/db\r\n" "replxx> xx\r\n" "x\r\n", command = [ ReplxxTests._cSample_, "q1" ] ) def parseArgs( self, func, argv ): global verbosity res = func( self, argv ) verbosity = self.verbosity return res if __name__ == "__main__": pa = unittest.TestProgram.parseArgs unittest.TestProgram.parseArgs = lambda self, argv: parseArgs( self, pa, argv ) unittest.main()