[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Taunting Java



LOL...

Looks like I added that Java stab back in 2003...

Damn I'm a funny guy. :)

j






use Test::More tests => 70;

use Model::t::HashTest;

my $hash = new Model::t::HashTest;

# Test adding scalar keys...
ok(defined $hash,                       '$hash defined');
ok($hash->add('A', 'Apple'),            '$hash->A added');
is($hash->A, 'Apple',                   '$hash->A returns Apple');
ok($hash->add(B, 'Barnyard'),           '$hash->B added');
is($hash->B, 'Barnyard',                '$hash->B returns Barnyard');
is($hash->A, 'Apple',                   '$hash->A is still Apple');

# Test overwrite...
ok($hash->add('A', 'Adam'),             '$hash->A overwritten w/ Adam');
is($hash->B, 'Barnyard',                '$hash->B returns Barnyard');
is($hash->A, 'Adam',                    '$hash->A returns Adam');
ok($hash->add('A', 'Apple'),            '$hash->A overwritten w/
Apple');
is($hash->B, 'Barnyard',                '$hash->B returns Barnyard');
is($hash->A, 'Apple',                   '$hash->A returns Apple');

# --------------------------------------------
# Test adding a key that is an object...
# --------------------------------------------
package Ping;          # Try this, Java!
sub ping { return "pong"; }
sub new { return bless {} }
package main;

my $ping = new Ping;
ok(defined $ping,                       '$ping defined');
ok($ping->ping eq "pong",               '$ping->ping passed');
ok($hash->add('Ping', $ping),           '$hash->$ping added');
ok($hash->Ping->ping eq "pong",         '$hash->Ping->ping is pong');
ok($hash->A eq 'Apple',                 '$hash->A is still Apple');
ok($hash->B eq 'Barnyard',              '$hash->B is still Barnyard');
# --------------------------------------------


...etc...


$ perl Hash.t 
1..70
ok 1 - $hash defined
ok 2 - $hash->A added
ok 3 - $hash->A returns Apple
ok 4 - $hash->B added
ok 5 - $hash->B returns Barnyard
ok 6 - $hash->A is still Apple
ok 7 - $hash->A overwritten w/ Adam
ok 8 - $hash->B returns Barnyard
ok 9 - $hash->A returns Adam
ok 10 - $hash->A overwritten w/ Apple
ok 11 - $hash->B returns Barnyard
ok 12 - $hash->A returns Apple
ok 13 - $ping defined
ok 14 - $ping->ping passed
ok 15 - $hash->$ping added
ok 16 - $hash->Ping->ping is pong
ok 17 - $hash->A is still Apple
ok 18 - $hash->B is still Barnyard
...etc...