File: token.t

package info (click to toggle)
libmakefile-dom-perl 0.004-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 616 kB
  • ctags: 535
  • sloc: perl: 6,552; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;

# Execute the tests
use Test::More tests => 26;
BEGIN { use_ok('MDOM::Token'); }

my $token = MDOM::Token->new('hello!');
ok $token, 'obj ok';
isa_ok $token, 'MDOM::Token::Bare', 'bare ok';
isa_ok $token, 'MDOM::Token', 'token ok';
is "$token", 'hello!', 'stringify ok';
ok $token->significant, 'plain tokens are significant by default';

$token->set_content('wow');
is $token->content, 'wow', 'set/get_content ok';
$token->add_content('~~~');
is $token->content, 'wow~~~', 'add_content ok';

$token = MDOM::Token->new('Whitespace', "\n\t ");
isa_ok $token, 'MDOM::Token::Whitespace';
isa_ok $token, 'MDOM::Token';
is $token->content, "\n\t ", 'ws content ok';
ok !$token->significant, 'ws is not significant';

$token = MDOM::Token->new('Separator', ":=");
isa_ok $token, 'MDOM::Token::Separator';
isa_ok $token, 'MDOM::Token';
is $token->content, ':=', 'sp content ok';
ok $token->significant, 'separators are significant';

$token = MDOM::Token->new('Comment', "# blah blah blah");
isa_ok $token, 'MDOM::Token::Comment';
isa_ok $token, 'MDOM::Token';
is $token->content, "# blah blah blah", 'cmt content ok';
$token->add_content("\n hey!");
is "$token", "# blah blah blah\n hey!", 'cmt add_content ok';
ok !$token->significant, 'comments are not significant';

$token = MDOM::Token->new('Continuation', "\\\n");
isa_ok $token, 'MDOM::Token::Continuation';
isa_ok $token, 'MDOM::Token';
is $token->content, "\\\n";
ok !$token->significant, 'line continuations are not significant';

$token = MDOM::Token::Whitespace->new("\n");
is $token->content, "\n";