Debian Codegraph @

t/zzText.t

raw
1 # -*- perl -*-
2 BEGIN { $|=1; $^W=1; }
3 use strict;
4 use Test;
5 use Tk;
6
7 BEGIN { plan tests => 22 };
8
9 my $mw = Tk::MainWindow->new;
10 eval { $mw->geometry('+10+10'); }; # This works for mwm and interactivePlacement
11
12 my $text;
13 {
14 eval { require Tk::Text; };
15 ok($@, "", 'Problem loading Tk::Text');
16 eval { $text = $mw->Text(); };
17 ok($@, "", 'Problem creating Text widget');
18 ok( Tk::Exists($text) );
19 eval { $text->grid; };
20 ok($@, "", '$text->grid problem');
21 }
22 ##
23 ## A scrolled (e.g., entry) does not work work as embedded window
24 ##
25 {
26 my $normal = $text->Entry();
27 my $scroll = $text->Scrolled('Entry');
28 ok( Tk::Exists($normal) );
29 ok( Tk::Exists($scroll) );
30
31 eval { $text->window('create','end', -window=>$normal); };
32 ok($@ , "", "can't embedd \$normal=$normal. Error is: $@");
33 eval { $text->window('create','end', -window=>$scroll); };
34 ok($@ , "", "can't embedd \$scroll=$scroll. Error is: $@");
35
36 $text->update;
37
38 ok( ($normal->manager), 'text', "\$normal=$normal not managed by text widget");
39 ok( ($scroll->manager), 'text', "\$scroll=$scroll not managed by text widget");
40
41 ok( ($normal->geometry eq '1x1+0+0'), '', '$normal not visible. Geometry'.$normal->geometry);
42 ok( ($scroll->geometry eq '1x1+0+0'), '', '$scroll not visible. Geometry'.$scroll->geometry);
43 }
44 ##
45 ## Bugs 1) windowCreate(-create=>callback) method expects a pathname
46 ## and not a widget ref.
47 ## 2) eval {} does not catch error message below
48 ##
49 ##ptksh> $l=$t->Label(-text=>'fool');
50 ##ptksh> $t->window('create','end',-create=>sub{$l})
51 ##ptksh> Tk::Error: bad window path name "Tk::Label=HASH(0x1405b4198)"
52 ## at /home/ach/perl/5.004_64/site+standard/auto/Tk/Error.al line 13.
53 ##
54 {
55 my $l;
56 eval { $l = $text->Label(-text=>'an embedded label'); };
57 ok($@ , "", "error create widget for later windowCreate: $@");
58
59 eval { $text->window('create', 'end', -create=>sub{ $l }); };
60 ok($@ , "", "windowCreate definition had problems: $@");
61
62 eval { $text->update; }; # make sure Text is visible so -create will be called
63 ok($@ , "", "windowCreate('1.0',-create=>callback) does not work: $@");
64
65 ## The next test is disabled ...
66 #
67 # # test if error message of -create is catched by eval
68 # eval { $text->window('create', '1.0', -create=>sub{"generate an error"}); };
69 # ok($@ , "", "a foo windowCreate definition had problems: $@");
70 # eval { $text->update; };
71 # ok($@ ne "", 1, "windowCreate(-create=>callback) err msg not catched.");
72 #
73 ## ... because:
74 #
75 # From: Nick Ing-Simmons <[email protected]>
76 # Date: Sat, 18 Apr 1998 20:32:59 +0100
77 # Message-id: <[email protected]>
78 # ...
79 # This from zzText.t - is not going to be fixed any time soon.
80 #
81 # ... test code above ...
82 #
83 # It is doing its own error handling, and there is no way to propagate the
84 # error without a complete re-write of Text's display code.
85 }
86 ##
87 ## windowCreate(-window=>doesnotexist) does not give an error. Fixed in Tk800.004
88 ##
89 {
90 eval { $text->window('create', '1.0', -window => 'doesnotexist'); };
91 ok($@ ne "", 1, "windowCreate -window does not complain if argument is not a widget ref");
92 }
93 ##
94 ## Dump -window returned pathname instead of widget ref. E.g.
95 ## window,.text.label,1.0. Fixed in Tk800.005
96 ##
97 {
98 $text->delete('1.0', 'end');
99 my $l = $text->Label(-text => 'Frog');
100 $text->windowCreate('end', -window => $l);
101 my @list = $text->dump('-window', '1.0', '1.0 lineend');
102 ok(scalar(@list), 3, "Dumped list of a window has not 3 elements");
103 ok($list[0], 'window', "dump() does not return correct type");
104 ok($list[1], $l, "dump() does not return the widget reference");
105 ok($list[2], '1.0', "dump() returns wrong index");
106 }
107 ##
108 ## in Tk800.004 yview("$line.0") displays line 14 on top. yview("$line.0 linestart")
109 ## works as expected
110 ##
111 {
112 $text->delete('1.0', 'end');
113 for (1..70) { $text->insert('end',"$_\n"); }
114 my $idx1 = "13.0";
115 my $idx2 = "13.0 linestart";
116
117 ok($text->compare($idx1, '==', $idx2), 1,
118 "Opps, '$idx1' and '$idx2' are not the same ???"
119 );
120
121 $text->yview($idx1); $text->update(); my $before1 = ($text->yview)[0];
122 $text->yview($idx2); $text->update(); my $before2 = ($text->yview)[0];
123 ok($before1, $before2, "Opps, yview shows different portions for equal indices");
124
125 $text->delete('1.0', 'end');
126 }
127
128 1;
129 __END__