File: test.pl

package info (click to toggle)
libclass-dbi-loader-relationship-perl 1%3A1.2-5.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 92 kB
  • sloc: perl: 126; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,029 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
use Test::More 'no_plan';
use_ok("Class::DBI::Loader::Relationship");
use Class::DBI::Loader::Generic;

my $fake = bless {
    CLASSES => { reverse(
        BeerDB::Brewery => "brewery",
        BeerDB::Beer => "beer",
        BeerDB::Handpump => "handpump",
        BeerDB::Pub => "pub"
    )
    }
}, 'Class::DBI::Loader::Generic';

$Class::DBI::Loader::Relationship::DEBUG = 1;

my $crib1 = <<EOF;
BeerDB::Brewery->has_many(beers => BeerDB::Beer);
BeerDB::Beer->has_a(brewery => BeerDB::Brewery);
EOF
sub test { my($text, $crib) = @_; is($fake->relationship($text), $crib, $text)}

test("a brewery produces beers", $crib1);
test("breweries produce beer", $crib1);
test("a brewery has a beer", "BeerDB::Brewery->has_a(beer => BeerDB::Beer);\n");

my $crib2 = <<EOF;
BeerDB::Handpump->has_a(pub => BeerDB::Pub)
BeerDB::Handpump->has_a(beer => BeerDB::Beer)
BeerDB::Pub->has_many(beers => [ BeerDB::Handpump => beer ])
BeerDB::Beer->has_many(pubs => [ BeerDB::Handpump => pub ])
EOF

test("pubs have beer on handpumps", $crib2);