• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package Test::ANTLR::Runtime::BitSet;
2
3use Test::More;
4
5use Moose;
6
7BEGIN { extends 'My::Test::Class' }
8
9sub constructor : Tests(3) {
10    my ($self) = @_;
11    my $class = $self->class;
12
13    can_ok $class, 'new';
14    ok my $bs = $class->new();
15    isa_ok $bs, $class;
16}
17
18sub constructor_bits : Tests(5) {
19    my ($self) = @_;
20    my $bs = $self->class->new({ bits => '001' });
21    ok !$bs->member(0);
22    ok !$bs->member(1);
23    ok $bs->member(2);
24    ok !$bs->member(3);
25    is "$bs", '{2}';
26}
27
28sub constructor_number : Tests(2) {
29    my ($self) = @_;
30    my $bs = $self->class->new({ number => 0x10 });
31    ok $bs->member(4);
32    is "$bs", '{4}';
33}
34
35sub constructor_words64 : Tests(2) {
36    my ($self) = @_;
37    my $bs = $self->class->new(
38        { words64 => [ '0x0000004000000001', '0x1000000000800000' ] });
39    is "$bs", '{0,38,87,124}';
40}
41
42sub of : Tests(2) {
43    my ($self) = @_;
44    my $bs = $self->class->of(0x10);
45    ok $bs->member(16) ;
46    is "$bs", '{16}' ;
47}
48
49sub operator_to_string : Tests(1) {
50    my ($self) = @_;
51    my $bs = $self->class->new();
52    is "$bs", '{}';
53}
54
55sub add : Tests(1) {
56    my ($self) = @_;
57    my $bs = $self->class->new();
58    $bs->add(2);
59    $bs->add(7);
60    is "$bs", '{2,7}';
61}
62
63sub remove : Tests(2) {
64    my ($self) = @_;
65    my $bs = $self->class->new();
66    $bs->add(3);
67    $bs->add(12);
68    is "$bs", '{3,12}';
69    $bs->remove(3);
70    is "$bs", '{12}';
71}
72
73sub operator_or : Tests(1) {
74    my ($self) = @_;
75    my $bs = $self->class->of(4);
76    $bs |= $self->class->of(5);
77    is "$bs", '{4,5}';
78}
79
80no Moose;
81__PACKAGE__->meta->make_immutable(inline_constructor => 0);
821;
83