File: hash_boolean.t

package info (click to toggle)
libclass-makemethods-perl 1.01-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,944 kB
  • sloc: perl: 10,495; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

package X;

use Class::MakeMethods::Template::Hash (
  'bits' => [ qw / a b c d / ],
  'bits' => 'e'
);

sub new { bless {}, shift; }

package Y;

@ISA = 'X';

use Class::MakeMethods::Template::Hash (
  'bits' => [ qw / m n / ]
);

sub new { bless {}, shift; }

package main;

use Test;
BEGIN { plan tests => 19 }

my $o = new X;

ok( 1 ); #1

ok( ! $o->a ); #2
ok( ! $o->b ); #3
ok( ! $o->c ); #4
ok( ! $o->d ); #5
ok( ! $o->e ); #6

ok( $o->a(1) ); #7
ok( $o->a ); #8

ok( $o->set_a ); #9
ok( $o->a ); #10

ok( ! $o->a(0) ); #11
ok( ! $o->a ); #12

ok( ! $o->clear_a ); #13
ok( ! $o->a ); #14

my @f;
ok( @f = $o->bit_fields ); #15
ok do {
  $f[0] eq 'a' and
  $f[1] eq 'b' and
  $f[2] eq 'c' and
  $f[3] eq 'd' and
  $f[4] eq 'e'
};

ok do {
  $o->clear_a; $o->clear_b; $o->set_c;
  $o->set_d; $o->clear_e;
  my %f = $o->bit_hash;
  $f{'a'} == 0 and $f{'a'} == $o->a and
  $f{'b'} == 0 and $f{'b'} == $o->b and
  $f{'c'} == 1 and $f{'c'} == $o->c and
  $f{'d'} == 1 and $f{'d'} == $o->d and
  $f{'e'} == 0 and $f{'e'} == $o->e
};

my $y = new Y;
$y->set_a;
$y->clear_m;

ok do {
  $y->a;
};

ok do {
  ! $y->m;
};

exit 0;