Debian Codegraph @

t/text2.t

raw
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3
4 #
5 # Author: Slaven Rezic
6 #
7
8 # Here goes tests for non-core Tk methods
9
10 use strict;
11 use Tk;
12
13 BEGIN {
14 if (!eval q{
15 use Test::More;
16 1;
17 }) {
18 print "1..0 # skip no Test::More module\n";
19 exit;
20 }
21 }
22
23 plan tests => 11;
24
25 my $mw = MainWindow->new;
26 $mw->geometry("+10+10");
27
28 {
29 my $t = $mw->Text(qw(-width 20 -height 10))->pack;
30 $t->insert("end", "hello\nworld\nfoo\nbar\nworld\n");
31
32 ok(!$t->FindNext('-f', '-e', '-c', 'doesnotexist'), 'Pattern does not exist');
33
34 ok($t->FindNext('-f', '-e', '-c', 'world'), 'First search');
35 my @first_index = split /\./, $t->index('insert');
36
37 ok($t->FindNext('-forwards', '-e', '-c', 'world'), 'Second search');
38 my @second_index = split /\./, $t->index('insert');
39 cmp_ok($second_index[0], ">", $first_index[0], 'Really a forwards search');
40
41 ok($t->FindNext('-b', '-e', '-c', 'world'), 'Backwards search');
42 my @third_index = split /\./, $t->index('insert');
43 cmp_ok($third_index[0], "<", $second_index[0], 'Really a backwards search');
44
45 $t->destroy;
46 }
47
48 {
49 my $t = $mw->Text(qw(-width 20 -height 10))->pack;
50 tie *FH, ref $t, $t
51 or die $!;
52
53 print FH "Hello Text World!\n";
54 printf FH "formatted: %s\n", "string";
55 syswrite FH, "toto\n", 3, 2;
56
57 is($t->Contents, "Hello Text World!\nformatted: string\nto\n", "tied handle and Contents()");
58 # XXX untie attempted while 3 inner references still exist
59 untie *FH;
60 $t->destroy;
61 }
62
63 {
64 my $t = $mw->Scrolled(qw(Text -width 20 -height 10))->pack;
65 tie *FH, 'Tk::Text', $t
66 or die $!;
67 print FH "Scrolled\n";
68 is($t->Contents, "Scrolled\n", "tied handle on scrolled Text widget");
69 # XXX untie attempted while 3 inner references still exist
70 untie *FH;
71 $t->destroy;
72 }
73
74 {
75 my $t = $mw->Scrolled(qw(Text -width 20 -height 10))->pack;
76 is $t->Contents, '', 'fresh Tk::Text is empty';
77 $t->Contents('newline-less');
78 is $t->Contents, 'newline-less', 'content without newline';
79 $t->Contents('');
80 is $t->Contents, '', 'after emptying Tk::Text';
81 $t->destroy;
82 }
83
84 __END__