root/libswish3/trunk/bindings/perl/t/10tokenize.t

Revision 2176, 0.9 kB (checked in by karpet, 2 months ago)

all tests passing, all (known) leaks fixed

Line 
1 use Test::More tests => 6;
2
3 use SWISH::3 qw( :constants );
4
5 ok( my $s3 = SWISH::3->new, "new s3" );
6 ok( my $tokens = $s3->tokenize(
7         "now is the time, ain't it? or when else might it be!",
8         SWISH::3::MetaName->new('foo'), 'bar'
9     ),
10     "wordlist"
11 );
12
13 ok( $tokens->isa('SWISH::3::TokenIterator'), 'isa TokenIterator' );
14
15 #$s3->describe($tokens);
16
17 while ( my $token = $tokens->next ) {
18
19     #$s3->describe($token);
20
21     my $word = $token->value;
22     if ( $word eq 'now' ) {
23         is( $token->pos, 1, "now position" );
24     }
25     if ( $word eq 'time' ) {
26         is( $token->pos, 4, "time position" );
27     }
28     if ( $word eq 'be' ) {
29         is( $token->pos, 12, "be position" );
30     }
31
32     $s3->debug and diag( '=' x 60 );
33     for my $w (SWISH_TOKEN_FIELDS) {
34
35         my $val = $token->$w;
36         if ( $w eq 'meta' ) {
37             $val = $val->name;
38         }
39
40         $s3->debug and diag( sprintf( "%15s: %s\n", $w, $val ) );
41
42     }
43 }
44
Note: See TracBrowser for help on using the browser.