def display_edited_lines():
	diffmodel = FakeDiffModel()
	diffmodel.lines = [
		DiffLine( "left 01", "right 01", difflinetypes.DIFFERENT, False, True ),
		DiffLine( "left 02", "right 02", difflinetypes.DIFFERENT, True,  True ),
		DiffLine( "left 03", "right 03", difflinetypes.DIFFERENT, True, False ),
		DiffLine( "line 04", "line 04",  difflinetypes.IDENTICAL, False, True ),
		DiffLine( "line 05", "line 05",  difflinetypes.IDENTICAL, True,  True ),
		DiffLine( "line 06", "line 06",  difflinetypes.IDENTICAL, True, False ),
	]

	view = NCursesView( diffmodel )
	view.win_width  = 40
	view.win_height = 6

	actions = []

	assert_strings_equal( view.show( actions )[0],
"""[di]left 01           [ei] * [e]right 01           
left 02           [ei] * [e]right 02           
left 03           [ei] * [d]right 03           
[n]line 04           [ei]   [e]line 04            
line 05           [ei]   [e]line 05            
line 06           [ei]   [n]line 06            
""" )
def down_emptyfile():
    diffmodel = FakeDiffModel()
    diffmodel.lines = [
        DiffLine(None, "line 1 here", difflinetypes.ADD),
        DiffLine(None, "line 2 here", difflinetypes.ADD),
    ]

    view = NCursesView(diffmodel)
    view.win_width = 40
    view.win_height = 3

    actions = [
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
        curses.KEY_DOWN,
    ]

    assert_strings_equal(
        view.show(actions)[0],
        """[m]..................[ai] + [a]line 1 here        
[mi]..................[ai] + [a]line 2 here        
[n]                                        
""",
    )
示例#3
0
def differences():

	diffmodel = FakeDiffModel()
	diffmodel.lines = [
		DiffLine( "line 1 here", "line 1 here different",
			difflinetypes.DIFFERENT ),
		DiffLine( "line 2 here", "line 2 here different",
			difflinetypes.DIFFERENT ),
		]

	listview = ListView( diffmodel )

	listview.set_columns( 80 )

	assert_strings_equal( listview.get_string(),
"""line 1 here                            |  line 1 here different
line 2 here                            |  line 2 here different
""" )

	listview.set_columns( 60 )

	assert_strings_equal( listview.get_string(),
"""line 1 here                  |  line 1 here different
line 2 here                  |  line 2 here different
""" )
示例#4
0
def mixture():

	diffmodel = FakeDiffModel()
	diffmodel.lines = [
		DiffLine( "line 1 here", "line 1 here", difflinetypes.IDENTICAL ),
		DiffLine( None, "line 2 here",
			difflinetypes.ADD ),
		DiffLine( "line 3 here", "line 3 here", difflinetypes.IDENTICAL ),
		DiffLine( "line 4 here", "line 4 here different",
			difflinetypes.DIFFERENT ),
		DiffLine( "line 5 here", None,
			difflinetypes.REMOVE ),
		DiffLine( "line 6 here", "line 6 here", difflinetypes.IDENTICAL ),
		]

	view = NCursesView( diffmodel )
	view.win_width  = 40
	view.win_height = 5

	actions = []

	assert_strings_equal( view.show( actions )[0],
"""[ni]line 1 here       [n]   line 1 here        
[m]..................[ai] + [a]line 2 here        
[n]line 3 here          line 3 here        
[d]line 4 here       [di] * [d]line 4 here differe
[r]line 5 here       [ri] - [m]...................
""" )
def normal():
	view = _make_view()
	actions = [ "H" ]

	assert_strings_equal( view.show( actions )[0],
"""[n]                                                                                
                                 Diffident Help                                 
                                                                                
                                    Quit - q                                    
                         Move left/right - h/l or Arrow Keys                    
                            Move up/down - k/j or Arrow Keys                    
                     Select line up/down - K/J                                  
                Next/Previous difference - n/p or F8/F7                         
                            Page up/down - ,/. or PageUp/Down                   
                     Select page up/down - </>                                  
                       Scroll left/right - z/x                                  
                         Copy left/right - [/]                                  
                             Insert line - a                                    
                          Delete line(s) - d                                    
                            Save changes - s                                    
                                                                                
   Diffident is Copyright (C) 2009 Andy Balaam and the Diffident developers.    
                  Diffident comes with ABSOLUTELY NO WARRANTY.                  
  This is free software, and you are welcome to redistribute it under certain   
 conditions; see the file COPYING for details, or gnu.org/licenses/gpl-2.0.txt  
""" )
def _right(key):
    view = _make_view()
    actions = [key]
    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 1 here          [ni]line 1 here        
[n]line 2 here          line 2 here        
""",
    )
def right_twice():
    view = _make_view()
    actions = [curses.KEY_RIGHT, curses.KEY_RIGHT]
    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 1 here          [ni]line 1 here        
[n]line 2 here          line 2 here        
""",
    )
def down_scroll():
    view = _make_view()

    actions = [curses.KEY_DOWN, curses.KEY_DOWN]

    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 2 here          line 2 here        
[ni]line 3 here       [n]   line 3 here        
""",
    )
def _page_up(key):
    view = _make_view()

    actions = [curses.KEY_NPAGE, key]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 1 here       [n]   line 1 here        
line 2 here          line 2 here        
""",
    )
def _page_down(key):
    view = _make_view()

    actions = [key]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 3 here       [n]   line 3 here        
line 4 here          line 4 here        
""",
    )
def page_right_page_down():
    view = _make_wide_view()

    # Right, Down, PageRight, PageDown
    actions = [curses.KEY_RIGHT, curses.KEY_DOWN, "x", curses.KEY_NPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[m]..........[ai] + [a]56789abcde
[r]56789abcde[ri] - [mi]..........
""",
    )
def page_left_stop_at_beginning():
    view = _make_wide_view()

    # PageRight, PageLeft 3 times
    actions = ["x", "z", "z", "z"]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]0-23456789[n]   0-23456789
[d]1-23456789[di] * [d]1-23456789
""",
    )
def page_up_short_diff():
    view = _make_short_diff_view()
    actions = [curses.KEY_PPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 01 [n]   line 01  
line 02    line 02  
                    
                    
""",
    )
def page_right_thrice():
    view = _make_wide_view()

    # PageRight 3 times
    actions = ["x", "x", "x"]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]f         [n]   f         
[d]f         [di] * [d]f plus ext
""",
    )
def page_right():
    view = _make_wide_view()

    # PageRight
    actions = ["x"]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]56789abcde[n]   56789abcde
[d]56789abcde[di] * [d]56789abcde
""",
    )
def _left(key):
    view = _make_view()

    # Go right and then left - back to where we started
    actions = [curses.KEY_RIGHT, key]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 1 here       [n]   line 1 here        
line 2 here          line 2 here        
""",
    )
def _up(key):
    view = _make_view()

    # Go down and then up - back to where we started
    actions = [curses.KEY_DOWN, key]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 1 here       [n]   line 1 here        
line 2 here          line 2 here        
""",
    )
def page_right_stop_at_end():
    view = _make_wide_view()

    # PageRight many times - we should stop before
    # it's just an empty screen
    actions = ["x", "x", "x", "x", "x", "x", "x", "x"]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]          [n]             
[d]          [di] * [d]r         
""",
    )
def page_right_page_down_shorter_lines():
    view = _make_wide_view()

    # PageRight 5 times, PageDown twice - should jump back to
    # a scroll position with some visible characters
    actions = ["x", "x", "x", "x", "x", curses.KEY_NPAGE, curses.KEY_NPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]          [n]             
[d]          [di] * [d]s ext     
""",
    )
def enter_edit_mode():
	diffmodel = EditReportingFakeDiffModel()

	view = NCursesView( diffmodel )
	view.win_width = 50
	view.win_height = 5

	actions = [ "e" ]
	(window, header, status ) = view.show( actions )

	assert_strings_equal( status,
		"""[mi]       Editing line.  Press ESC to finish.        
""" )
def exit_edit_mode():
	diffmodel = EditReportingFakeDiffModel()

	view = NCursesView( diffmodel )
	view.win_width = 40
	view.win_height = 5

	actions = [ "e", keys.KEY_ESCAPE ]
	(window, header, status ) = view.show( actions )

	assert_strings_equal( status,
		"""[ni]         Press SHIFT-H for help         
""" )
def default_message_at_start():

	diffmodel = FakeDiffModel()
	diffmodel.lines = []

	view = NCursesView( diffmodel )
	view.win_width  = 40
	view.win_height = 5

	actions = []

	assert_strings_equal( view.show( actions )[2],
"""[ni]         Press SHIFT-H for help         
""" )
def page_down_cursor_to_bottom():
    view = _make_view()
    view.win_height = 3

    # Right, PageDown, PageDown
    actions = [curses.KEY_RIGHT, curses.KEY_NPAGE, curses.KEY_NPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 4 here          line 4 here        
line 5 here          line 5 here        
line 6 here          [ni]line 6 here        
""",
    )
def page_down_twice():
    view = _make_view()
    view.win_height = 3

    # PageDown, PageDown, PageDown
    actions = [curses.KEY_NPAGE, curses.KEY_NPAGE, curses.KEY_NPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 4 here          line 4 here        
line 5 here          line 5 here        
[ni]line 6 here       [n]   line 6 here        
""",
    )
def page_up_cursor_to_top():
    view = _make_view()
    view.win_height = 3

    # Right, Down, PageUp
    actions = [curses.KEY_RIGHT, curses.KEY_DOWN, curses.KEY_PPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[n]line 1 here          [ni]line 1 here        
[n]line 2 here          line 2 here        
line 3 here          line 3 here        
""",
    )
def page_up_twice():
    view = _make_view()
    view.win_height = 3

    # PageUp, PageUp
    actions = [curses.KEY_PPAGE, curses.KEY_PPAGE]

    assert_strings_equal(
        view.show(actions)[0],
        """[ni]line 1 here       [n]   line 1 here        
line 2 here          line 2 here        
line 3 here          line 3 here        
""",
    )
def help():

	diffmodel = FakeDiffModel()
	diffmodel.lines = []

	view = NCursesView( diffmodel )
	view.win_width  = 40
	view.win_height = 40

	actions = [ "H" ]

	assert_strings_equal( view.show( actions )[2],
"""[ni]       Press any key to continue        
""" )
def next_diff_several():

	view = _make_view()

	actions = [ curses.KEY_RIGHT, "n", "n" ]

	assert_strings_equal( view.show( actions )[0],
"""[n]line 09    line 09  
[d]line 10 [di] * [d]line 10 d
line 11 [di] * [d]line 11 d
[n]line 12    line 12  
line 13    line 13  
[m]........[ai] + line 14  
[m]........[ai] + [a]line 15  
""" )
def next_diff_different():

	view = _make_view()

	actions = [ "n" ]

	assert_strings_equal( view.show( actions )[0],
"""[n]line 07    line 07  
line 08    line 08  
line 09    line 09  
[di]line 10  * [d]line 10 d
line 11 [di] * [d]line 11 d
[n]line 12    line 12  
line 13    line 13  
""" )
def previous_diff():

	view = _make_view()

	actions = [ "n", "n", curses.KEY_DOWN, "p" ]

	assert_strings_equal( view.show( actions )[0],
"""[n]line 09    line 09  
[di]line 10  * [d]line 10 d
line 11 [di] * [d]line 11 d
[n]line 12    line 12  
line 13    line 13  
[m]........[ai] + [a]line 14  
[m]........[ai] + [a]line 15  
""" )