1
2use strict;
3
4BEGIN {
5	require Test::More;
6	use Term::ReadLine::Zoid::ViCommand;
7	Test::More->import( tests => 18 + scalar @Term::ReadLine::Zoid::ViCommand::vi_motions - 6 );
8}
9
10my $t;
11$t = Term::ReadLine::Zoid->new('test');
12$t->{config}{bell} = sub {}; # Else the "\cG" fucks up test harness
13
14# test routines
15sub test_reset {
16	$_[0]->reset();
17	$_[0]->switch_mode('command');
18	$_[0]->{lines} = [ 'duss ja', 'nou ja', 'test 123' ]; # 3 X 7,6,8
19	$_[0]->{pos} = [5, 1];
20}
21
22# escape
23test_reset $t;
24$t->{vi_command} = '!**^sgf@#$34342dfs#$fsg#$4g^$^)*!fgd';
25$t->press("\e");
26ok $t->{vi_command} eq '', 'escape reset';
27
28# h, l/space (left, right)
29test_reset $t;
30$t->press('4h');
31is_deeply $t->{pos}, [1,1], 'h 1';
32ok $t->self_insert('h'), 'h 2';
33$t->{pos} = [0,0];
34ok !$t->self_insert('h'), 'h 3';
35$t->press('7 ');
36is_deeply $t->{pos}, [7,0], 'space';
37ok $t->self_insert('l'), 'l 1';
38$t->{pos} = [8,2];
39ok !$t->self_insert('l'), 'l 2';
40
41# control-z
42
43# i
44# I
45# a
46# A
47# m
48# M
49# R
50# #
51# =
52# \
53# *
54
55# [I<count>] @ I<char>
56$t->reset;
57$t->{lines} = [ 'test123 123' ];
58$t->{pos} = [1,0];
59$t->{config}{aliases}{_A} = "\elldl";
60$t->press('@A');
61ok $t->{lines}[0] eq 'tet123 123', 'macro 1';
62$t->press('3@A');
63ok $t->{lines}[0] eq 'tet2 23', 'macro 2';
64
65# [I<count>] ~
66$t->reset;
67$t->{lines} = [ 'nou ja duss jaa' ];
68$t->{pos} = [0,0];
69$t->press('~3l~2l~4l~');
70ok $t->{lines}[0] eq 'Nou Ja Duss Jaa', '~ 1';
71$t->press('015~');
72ok $t->{lines}[0] eq 'nOU jA dUSS jAA', '~ 2';
73
74# [I<count>] .
75$t->reset;
76$t->{lines} = [ 'nou ja duss jaa' ];
77$t->{pos} = [11,0];
78$t->press('2dh');
79ok $t->{lines}[0] eq 'nou ja du jaa', '3dh';
80$t->press('..');
81ok $t->{lines}[0] eq 'nou j jaa', '..';
82$t->press('4.');
83ok $t->{lines}[0] eq 'n jaa', '4.';
84
85# v
86# [I<count>] w
87# [I<count>] W
88# [I<count>] e
89# [I<count>] E
90# [I<count>] b
91# [I<count>] B
92# ^
93# $
94# 0
95# [I<count>] |
96
97# [I<count>] f I<char>
98# [I<count>] F I<char>
99# [I<count>] t I<char>
100# [I<count>] T I<char>
101
102#TODO multiline the fFtT function
103#test_reset $t;
104#$t->press("\e");
105#for ( ['fs', []], ['Fs', []], ['ts', []], ['Ts', []] ) {
106#	test_reset $t;
107#	$t->press($$_[0]);
108#	print "# $$_[0]: $t->{pos}[0], $t->{pos}[1]\n";
109#	is_deeply $t->{pos}, $$_[1], $$_[0];
110#}
111
112# [I<count>] ;
113# [I<count>] ,
114# [I<count>] c I<motion>
115# C
116# S
117
118# [I<count>] r I<char>
119$t->reset;
120$t->{lines} = ['gdgfgfffghg'];
121$t->{pos} = [2,0];
122$t->press('rall3ra');
123ok $t->{lines}[0] eq 'gdafaaafghg', 'r';
124
125# [I<count>] _
126$t->reset;
127$t->{history} = ['word1 word2 word3'];
128$t->press("_\el2_\el1_");
129ok $t->{lines}[0] eq ' word3 word2 word1', '_';
130
131# [I<count>] x
132# [I<count>] X
133
134# [I<count>] d I<motion>
135# D
136
137# lines have to change, the exact change isn't tested here,
138# thats up to the motion test
139
140test_reset $t;
141$t->press("\e");
142my $lines = join '', @{$$t{lines}};
143#TODO multiline the fFtT function
144#$t->press('fs'); # for repeat movements
145for my $k (@Term::ReadLine::Zoid::ViCommand::vi_motions, 'd') {
146	test_reset $t;
147#	print STDERR "# pos: $$t{pos}[0],$$t{pos}[1] lines: ".join( "\n", @{$$t{lines}})."\n";
148	my $p = 'd'.$k;
149	next if grep {$_ eq $k} qw/f F t T ;/, ',';
150#	$p .= 's' if grep {$_ eq $k} qw/f F t T/;
151	$p = '1'.$p if $k eq '|';
152#	print STDERR "# pressing $p\n";
153	$t->press($p);
154#	print STDERR "# pos: $$t{pos}[0],$$t{pos}[1] lines: ".join( "\n", @{$$t{lines}})."\n";
155	ok length( join( '', @{$$t{lines}}) ) < length $lines, $p;
156}
157
158test_reset $t;
159$t->press('D');
160ok length( join( '', @{$$t{lines}}) ) < length $lines, 'D';
161
162# [I<count>] y I<motion>
163# Y
164# [I<count>] p
165# [I<count>] P
166# u
167# U
168# [I<count>] k
169# [I<count>] -
170# [I<count>] j
171# [I<count>] +
172# [I<number>] G
173# control-a
174# control-x
175# TODO
176# :
177# B<set> [I<+o>|I<-o>] [I<option>=I<value>]
178# B<ascii>
179# B<testchr>
180# B<bindchr> I<chr>=I<keyname>
181# B<!>, B<shell> I<shellcode>
182# B<eval> I<perlcode>
183# B<alias> I<char>=I<macro>
184# aliases
185# editor
186# shell
187