File: regexp.t

package info (click to toggle)
perl-tk 1%3A804.036%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,284 kB
  • sloc: ansic: 349,560; perl: 52,292; sh: 12,678; makefile: 5,700; asm: 3,565; ada: 1,681; pascal: 1,082; cpp: 1,006; yacc: 883; cs: 879
file content (84 lines) | stat: -rw-r--r-- 2,279 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding:utf-8; -*-
use Test::More tests => 22;
use Tk;
use Tk::widgets qw(Text);
use utf8;

my $mw = MainWindow->new;
my $tw = $mw->Text;
my $all = <<'TEXT';

This is the text we are matching.
     $42
     £42

TEXT

$tw->insert(end => $all);
is($tw->get('1.0','end -1 char'),$all,"Contents as expected");

my $eposn;
my $ecoun;

$eposn = $tw->search(-count => \$ecount, -exact => 'matching','1.0');
is($eposn,'2.24',"Correct -exact postion");
is($ecount,8,"Correct -exact length");

my $rposn;
my $rcount;

$rposn = $tw->search(-count => \$rcount, -regexp => 'matching','1.0');
is($rposn,'2.24',"Correct -regexp postion");
is($rcount,8,"Correct -regexp length");

$rposn = $tw->search(-count => \$rcount, -regexp => 'tHiS','1.0');
is($rposn,undef,"Correct non-match");

$rposn = $tw->search(-count => \$rcount, -nocase => -regexp => 'tHiS','1.0');
is($rposn,'2.0',"Correct -regexp -nocase");

$eposn = $tw->search(-count => \$rcount, -nocase => -exact => 'tHiS','1.0');
is($eposn,'2.0',"Correct -exact -nocase");

$eposn = $tw->search(-count => \$ecount, -nocase => -exact => '£42','1.0');
is($eposn,'4.5',"Correct -exact high-bit posn");
is($ecount,3,"Correct -exact high-bit len");

TODO: {
  local $TODO = "perl regexp bug pre perl5.8.1" if $] < 5.008001;
$rcount = 0;
$rposn = $tw->search(-count => \$rcount, -nocase => -regexp => '£42','1.0');
is($rposn,'4.5',"Correct -regexp high-bit posn");
is($rcount,3,"Correct -regexp high-bit len");
};

my $qposn;
my $qcount;

$qposn = $tw->search(-count => \$qcount, -regexp => qr/matching/,'1.0');
is($qposn,'2.24',"Correct -regexp qr// postion");
is($qcount,8,"Correct -regexp qr// length");

SKIP:  {
  skip "Perl too old", 8 unless $] >= 5.008001;
my $tword = qr/\bt\w+|\D\d+/i;
my $start = '1.0';
my $i = 0;
my @word = $all =~ /$tword/g;
while ($qposn = $tw->search(-count => \$qcount, -regexp => $tword,$start,'end'))
 {
  $start = $tw->index("$qposn +$qcount chars");
  my $s = $tw->get($qposn,$start);
  print "# '$s'\n";
  is($s,$word[$i++],"Right word");
 }


$rposn = $tw->search(-count => \$rcount, -regexp => '£\d+','1.0');
$i     = $tw->get("$rposn+1 chars","$rposn + $rcount chars");
is($rposn,'4.5',"Correct -regexp postion");
is($rcount,3,"Correct -regexp length");
is($i,'42',"UTF-8 Skip correct");

}