[svn:parrot] r44305 - trunk/t/dynpmc
darbelo at svn.parrot.org
darbelo at svn.parrot.org
Mon Feb 22 20:50:27 UTC 2010
Author: darbelo
Date: Mon Feb 22 20:50:25 2010
New Revision: 44305
URL: https://trac.parrot.org/parrot/changeset/44305
Log:
Convert gdbmhash tests to PIR.
Patch by bubaflub++ with some very minor edits.
Modified:
trunk/t/dynpmc/gdbmhash.t
Modified: trunk/t/dynpmc/gdbmhash.t
==============================================================================
--- trunk/t/dynpmc/gdbmhash.t Mon Feb 22 20:11:28 2010 (r44304)
+++ trunk/t/dynpmc/gdbmhash.t Mon Feb 22 20:50:25 2010 (r44305)
@@ -1,21 +1,14 @@
-#! perl
-# Copyright (C) 2005-2008, Parrot Foundation.
+#! parrot
+# Copyright (C) 2005-2010, Parrot Foundation.
# $Id$
-use strict;
-use warnings;
-use lib qw( . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test;
-use Parrot::Config;
-
=head1 NAME
t/dynpmc/gdbmhash.t - test the GDBMHash PMC
=head1 SYNOPSIS
- % prove t/dynpmc/gdbmhash.t
+ % parrot t/dynpmc/gdbmhash.t
=head1 DESCRIPTION
@@ -23,77 +16,85 @@
=cut
-if ( $PConfig{has_gdbm} ) {
- plan tests => 13;
-}
-else {
- plan skip_all => "No gdbm library available";
-}
+.sub main
+ .include 'test_more.pir'
+ .include 'iglobals.pasm'
+ .local pmc config_hash, interp
+
+ plan(48)
+ interp = getinterp
+ config_hash = interp[.IGLOBALS_CONFIG_HASH]
+ $S0 = config_hash['has_gdbm']
+ unless $S0 goto no_gdbm
+
+ test_typeof()
+ test_interface()
+ test_get_integer()
+ test_get_bool()
+ test_modify_an_entry()
+ test_exists_keyed()
+ test_set_string_with_string_key()
+ test_set_string_with_pmc_key()
+ test_set_pmc_with_string_key()
+ test_set_pmc_with_pmc_key()
+ test_set_intval_with_string_key()
+ test_set_floatval_with_pmc_key()
+ test_delete_keyed()
+ .return()
+ no_gdbm:
+ skip(48, 'No gdbm library available')
+.end
+
+.sub unlink
+ .param string filename
+ new $P0, 'OS'
+ $P0.'rm'(filename)
+.end
-# PIR fragment for setting up a GDBM Hash
-my $new_hash_1 = << 'CODE';
-.sub test :main
+.sub test_typeof
.local pmc gdbmhash_lib
gdbmhash_lib = loadlib "gdbmhash"
.local pmc hash_1
hash_1 = new "GDBMHash"
-CODE
-
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "typeof" );
-
.local string type
type = typeof hash_1
- print type
- print "\n"
+ is(type, 'GDBMHash', 'typeof')
.end
-CODE
-GDBMHash
-OUTPUT
-unlink('gdbm_hash_1');
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "check whether interface is done" );
+.sub test_interface
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
.local int bool1
does bool1, hash_1, "scalar"
- print bool1
- print "\n"
+ is(bool1, 0, 'check whether interface is done')
does bool1, hash_1, "hash"
- print bool1
- print "\n"
+ is(bool1, 1, 'check whether interface is done')
does bool1, hash_1, "no_interface"
- print bool1
- print "\n"
+ is(bool1, 0, 'check whether interface is done')
.end
-CODE
-0
-1
-0
-OUTPUT
-unlink('gdbm_hash_1');
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "get_integer" );
+.sub test_get_integer
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
.local int hash_size
hash_size = hash_1
- print "An unitialized GDBMHash has size "
- print hash_size
- print ".\n"
+ is(hash_size, 0, 'An unitialized GDBMHash has size 0')
hash_1 = "gdbm_hash_1"
hash_size = hash_1
- print "An GDBMHash for a new file has size "
- print hash_size
- print ".\n"
+ is(hash_size, 0, 'An GDBMHash for a new file has size 0')
hash_1["key1"] = "val1"
hash_size = hash_1
- print "After one assignment GDBMHash has size "
- print hash_size
- print ".\n"
+ is(hash_size, 1, 'After one assignment GDBMHash has size 1')
hash_1["key2"] = "val2"
hash_size = hash_1
- print "After two assignments GDBMHash has size "
- print hash_size
- print ".\n"
+ is(hash_size, 2, 'After two assignments GDBMHash has size 2')
hash_1["key3"] = "val3"
hash_1["key4"] = "val4"
@@ -109,225 +110,201 @@
hash_1["key14"] = "val14"
hash_1["key15"] = "val15"
hash_size = hash_1
- print "After 15 assignments GDBMHash has size "
- print hash_size
- print ".\n"
+ is(hash_size, 15, 'After 15 assignments GDBMHash has size 15')
delete hash_1["key7"]
delete hash_1["key9"]
hash_size = hash_1
- print "After 15 assignments and 2 deletes GDBMHash has size "
- print hash_size
- print ".\n"
-
+ is(hash_size, 13, 'After 15 assignments and 2 deletes GDBMHash has size 13')
+ unlink('gdbm_hash_1')
.end
-CODE
-An unitialized GDBMHash has size 0.
-An GDBMHash for a new file has size 0.
-After one assignment GDBMHash has size 1.
-After two assignments GDBMHash has size 2.
-After 15 assignments GDBMHash has size 15.
-After 15 assignments and 2 deletes GDBMHash has size 13.
-OUTPUT
-unlink('gdbm_hash_1');
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "get_bool" );
- print "An uninitialized GDBMHash is"
+.sub test_get_bool
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
if hash_1 goto HASH1_IS_1
- print " not"
+ ok(1, 'An uninitialized GDBMHash is not')
HASH1_IS_1:
- print ".\n"
hash_1 = "gdbm_hash_1"
- print "An GDBMHash for a new file is"
if hash_1 goto HASH1_IS_2
- print " not"
+ ok(1, 'A GDBMHash for a new file is not')
HASH1_IS_2:
- print ".\n"
hash_1["key1"] = "val1"
- print "After one insert the GDBMHash is"
if hash_1 goto HASH1_IS_3
- print " not"
+ ok(0, 'After one insert the GDBMHash is not')
HASH1_IS_3:
- print ".\n"
+ ok(1, 'After one insert the GDBMHash is')
+ unlink('gdbm_hash_1')
.end
-CODE
-An uninitialized GDBMHash is not.
-An GDBMHash for a new file is not.
-After one insert the GDBMHash is.
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a STRING, with umlaut
# The key used for insertion is a STRING.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "modify an entry" );
+.sub test_modify_an_entry
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local pmc val_pmc
- hash_1["Schluessel"] = "Wert urspruenglich\n"
+ hash_1["Schluessel"] = "Wert urspruenglich"
val_pmc = hash_1["Schluessel"]
- print val_pmc
- hash_1["Schluessel"] = "Wert geaendert\n"
+ is(val_pmc, 'Wert urspruenglich', 'modify an entry')
+ hash_1["Schluessel"] = "Wert geaendert"
val_pmc = hash_1["Schluessel"]
- print val_pmc
- hash_1["Schluessel"] = "Wert nocheinmal geaendert\n"
+ is(val_pmc, 'Wert geaendert', 'modify an entry')
+ hash_1["Schluessel"] = "Wert nocheinmal geaendert"
val_pmc = hash_1["Schluessel"]
- print val_pmc
- hash_1["Schluessel"] = "Wert urspruenglich\n"
+ is(val_pmc, 'Wert nocheinmal geaendert', 'modify an entry')
+ hash_1["Schluessel"] = "Wert urspruenglich"
val_pmc = hash_1["Schluessel"]
- print val_pmc
+ is(val_pmc, 'Wert urspruenglich', 'modify an entry')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-Wert urspruenglich
-Wert geaendert
-Wert nocheinmal geaendert
-Wert urspruenglich
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a STRING.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "exists_keyed" );
+.sub test_exists_keyed
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
- hash_1["Schluessel"] = "Wert\n"
+ hash_1["Schluessel"] = "Wert"
.local int exist_flag
exist_flag = exists hash_1["a"]
- print exist_flag
- print "\n"
+ is(exist_flag, 0, 'exists keyed')
exist_flag = exists hash_1["Schluessel"]
- print exist_flag
- print "\n"
+ is(exist_flag, 1, 'exists keyed')
.local pmc key_out
key_out = new 'String'
key_out = "b"
exist_flag = exists hash_1[key_out]
- print exist_flag
- print "\n"
+ is(exist_flag, 0, 'exists keyed')
key_out = "Schluessel"
exist_flag = exists hash_1[key_out]
- print exist_flag
- print "\n"
+ is(exist_flag, 1, 'exists keyed')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-0
-1
-0
-1
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a STRING.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set STRING with STRING key" );
+.sub test_set_string_with_string_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
- hash_1["Schluessel"] = "Wert\n"
+ hash_1["Schluessel"] = "Wert"
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
+ is(val_string, 'Wert', 'set string with string key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
+ is(val_pmc, 'Wert', 'set string with string key')
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
- print val_string
+ is(val_string, 'Wert', 'set string with string key')
val_pmc = hash_1[key_out]
- print val_pmc
+ is(val_pmc, 'Wert', 'set string with string key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-Wert
-Wert
-Wert
-Wert
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a PMC.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set STRING with a PMC key" );
+.sub test_set_string_with_pmc_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local pmc key_pmc
key_pmc = new 'String'
key_pmc = "Schluessel"
- hash_1[key_pmc] = "Wert\n"
+ hash_1[key_pmc] = "Wert"
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
+ is(val_string, 'Wert', 'set string with pmc key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
+ is(val_pmc, 'Wert', 'set string with pmc key')
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
- print val_string
+ is(val_string, 'Wert', 'set string with pmc key')
val_pmc = hash_1[key2]
- print val_pmc
+ is(val_pmc, 'Wert', 'set string with pmc key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-Wert
-Wert
-Wert
-Wert
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a PMC.
# The key used for insertion is a STRING.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set PMC with STRING key" );
+.sub test_set_pmc_with_string_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local pmc val
val = new 'String'
- val = "Wert\n"
+ val = "Wert"
hash_1["Schluessel"] = val
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
+ is(val_string, 'Wert', 'set pmc with string key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
+ is(val_pmc, 'Wert', 'set pmc with string key')
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
- print val_string
+ is(val_string, 'Wert', 'set pmc with string key')
val_pmc = hash_1[key_out]
- print val_pmc
+ is(val_pmc, 'Wert', 'set pmc with string key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-Wert
-Wert
-Wert
-Wert
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a PMC.
# The key used for insertion is a PMC.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set PMC with a PMC key" );
+.sub test_set_pmc_with_pmc_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local pmc val
val = new 'String'
- val = "Wert\n"
+ val = "Wert"
.local pmc key_pmc
key_pmc = new 'String'
key_pmc = "Schluessel"
@@ -337,28 +314,27 @@
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
+ is(val_string, 'Wert', 'set pmc with pmc key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
+ is(val_pmc, 'Wert', 'set pmc with pmc key')
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
- print val_string
+ is(val_string, 'Wert', 'set pmc with pmc key')
val_pmc = hash_1[key2]
- print val_pmc
+ is(val_pmc, 'Wert', 'set pmc with pmc key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
-Wert
-Wert
-Wert
-Wert
-OUTPUT
-unlink('gdbm_hash_1');
# The value is an INTVAL
# The key used for insertion is a STRING.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set INTVAL with STRING key" );
+.sub test_set_intval_with_string_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
hash_1["Schluessel"] = -11012005
@@ -367,32 +343,27 @@
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
- print "\n"
+ is(val_string, -11012005, 'set intval with a string key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
- print "\n"
+ is(val_pmc, -11012005, 'set intval with a string key')
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
- print val_string
- print "\n"
+ is(val_string, -11012005, 'set intval with a string key')
val_pmc = hash_1[key_out]
- print val_pmc
- print "\n"
+ is(val_pmc, -11012005, 'set intval with a string key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
--11012005
--11012005
--11012005
--11012005
-OUTPUT
-unlink('gdbm_hash_1');
# The value is a FLOATVAL.
# The key used for insertion is a PMC.
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set FLOATVAL with a PMC key" );
+.sub test_set_floatval_with_pmc_key
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local pmc key_pmc
@@ -404,62 +375,47 @@
.local string val_string
val_string = hash_1["Schluessel"]
- print val_string
- print "\n"
+ is(val_string, -1101.2005, 'set float with a pmc key')
val_pmc = hash_1["Schluessel"]
- print val_pmc
- print "\n"
+ is(val_pmc, -1101.2005, 'set float with a pmc key')
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
- print val_string
- print "\n"
+ is(val_string, -1101.2005, 'set float with a pmc key')
val_pmc = hash_1[key2]
- print val_pmc
- print "\n"
+ is(val_pmc, -1101.2005, 'set float with a pmc key')
+
+ unlink('gdbm_hash_1')
.end
-CODE
--1101.2005
--1101.2005
--1101.2005
--1101.2005
-OUTPUT
-unlink('gdbm_hash_1');
-pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "delete_keyed" );
+.sub test_delete_keyed
+ .local pmc gdbmhash_lib
+ gdbmhash_lib = loadlib "gdbmhash"
+ .local pmc hash_1
+ hash_1 = new "GDBMHash"
hash_1 = "gdbm_hash_1"
.local int exist_flag
.local int hash_size
exist_flag = exists hash_1["a"]
- print '"a" exists: '
- print exist_flag
- print "\n"
+ is(exist_flag, 0, 'delete keyed')
hash_1["a"] = "A"
exist_flag = exists hash_1["a"]
- print '"a" exists: '
- print exist_flag
- print "\n"
+ is(exist_flag, 1, 'delete keyed')
delete hash_1["a"]
exist_flag = exists hash_1["a"]
- print '"a" exists: '
- print exist_flag
- print "\n"
-.end
-CODE
-"a" exists: 0
-"a" exists: 1
-"a" exists: 0
-OUTPUT
-unlink('gdbm_hash_1');
+ is(exist_flag, 0, 'delete keyed')
+
+ unlink('gdbm_hash_1')
+.end
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 filetype=pir:
More information about the parrot-commits
mailing list