1#!/usr/bin/expect -f
2proc begin_strcut_test {_from _length} {
3    global spawn_id from length
4    set from $_from
5    set length $_length
6
7    spawn tests/strcut Japanese "ISO-2022-JP" $_from $_length
8    set timeout 10
9
10    expect_after {
11        "\[^\r\n\]*\r\n" { fail $test }
12    }
13}
14
15begin_strcut_test -1 2
16
17set test "asciish characters ($from, $length)"
18send "testtest\r"
19expect {
20    -ex "***ERROR***\r\n" { pass $test }
21}
22
23set test "non-asciish characters ($from, $length)"
24send "\x1b\$B%F%9%H%F%9%H\x1b(B\r"
25sleep 1
26expect {
27    -ex "***ERROR***\r\n" { pass $test }
28}
29
30close
31begin_strcut_test 2 -1
32
33set test "asciish characters ($from, $length)"
34send "testtest\r"
35expect {
36    -ex "***ERROR***\r\n" { pass $test }
37}
38
39set test "non-asciish characters ($from, $length)"
40send "\x1b\$B%F%9%H%F%9%H\x1b(B\r"
41sleep 1
42expect {
43    -ex "***ERROR***\r\n" { pass $test }
44}
45
46close
47begin_strcut_test 3 2
48
49set test "asciish characters ($from, $length)"
50send "testtest\r"
51expect {
52    -ex "%74%74 (2)\r\n" { pass $test }
53}
54
55set test "non-asciish characters ($from, $length)"
56send "\x1b\$B%F%9%H%F%9%H\x1b(B\r"
57sleep 1
58expect {
59    -ex " (0)\r\n" { pass $test }
60}
61
62close
63begin_strcut_test 5 8
64
65set test "asciish characters ($from, $length)"
66send "testtest\r"
67expect {
68    -ex "%65%73%74 (3)\r\n" { pass $test }
69}
70
71set test "non-asciish characters ($from, $length)"
72sleep 1
73send "\x1b\$B%F%9%H%F%9%H\x1b(B\r"
74sleep 1
75expect {
76    -ex "%1b%24%42%25%39%1b%28%42 (8)\r\n" { pass $test }
77}
78
79close
80begin_strcut_test 1 15
81
82set test "asciish characters ($from, $length)"
83send "testestestestestes\r"
84expect {
85     "%65%73%74%65%73%74%65%73%74%65%73%74%65%73%74 (15)\r\n" { pass $test }
86}
87
88set test "non-asciish characters ($from, $length)"
89send "\x1b\$B%F%9%H%F%9%H\x1b(B\r"
90sleep 1
91expect {
92    -ex "%1b%24%42%25%46%25%39%25%48%25%46%1b%28%42 (14)\r\n" { pass $test }
93}
94close
95begin_strcut_test 8 20
96
97set test "non-asciish characters (2) ($from, $length)"
98send "\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x24\x46\x24\x39\x24\x48\x1b\x28\x49\x4a\x5e\x4a\x5e\x4a\x5e\x43\x3d\x44\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\r"
99sleep 1
100expect {
101    -ex "%74%1b%24%42%25%39%1b%28%42%74%1b%24%42%25%48%24%46%1b%28%42 (20)\r\n" {
102        pass $test
103    }
104}
105
106begin_strcut_test 8 21
107
108set test "non-asciish characters (2) ($from, $length)"
109send "\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x24\x46\x24\x39\x24\x48\x1b\x28\x49\x4a\x5e\x4a\x5e\x4a\x5e\x43\x3d\x44\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\r"
110sleep 1
111expect {
112    -ex "%74%1b%24%42%25%39%1b%28%42%74%1b%24%42%25%48%24%46%1b%28%42 (20)\r\n" {
113        pass $test
114    }
115}
116
117begin_strcut_test 11 17
118
119set test "non-asciish characters (2) ($from, $length)"
120send "\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x24\x46\x24\x39\x24\x48\x1b\x28\x49\x4a\x5e\x4a\x5e\x4a\x5e\x43\x3d\x44\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\x1b\x24\x42\x25\x46\x1b\x28\x42\x74\x1b\x24\x42\x25\x39\x1b\x28\x42\x74\x1b\x24\x42\x25\x48\x1b\x28\x42\x74\r"
121sleep 1
122expect {
123    -ex "%1b%24%42%25%39%1b%28%42%74%1b%24%42%25%48%1b%28%42 (17)\r\n" {
124        pass $test
125    }
126}
127
128
129# vim: sts=4 sw=4 ts=4 et
130