[svn:parrot] r41381 - trunk/t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun Sep 20 21:47:45 UTC 2009
Author: bacek
Date: Sun Sep 20 21:47:42 2009
New Revision: 41381
URL: https://trac.parrot.org/parrot/changeset/41381
Log:
[t] Rewrite FixedStringArray test into PIR.
Modified:
trunk/t/pmc/fixedstringarray.t
Modified: trunk/t/pmc/fixedstringarray.t
==============================================================================
--- trunk/t/pmc/fixedstringarray.t Sun Sep 20 15:00:49 2009 (r41380)
+++ trunk/t/pmc/fixedstringarray.t Sun Sep 20 21:47:42 2009 (r41381)
@@ -1,13 +1,7 @@
-#! perl
+#! parrot
# Copyright (C) 2001-2007, Parrot Foundation.
# $Id$
-use strict;
-use warnings;
-use lib qw( . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test tests => 15;
-
=head1 NAME
t/pmc/fixedstringarray.t - FixedStringArray PMC
@@ -23,335 +17,279 @@
=cut
-pasm_output_is( <<'CODE', <<'OUTPUT', "Setting array size" );
- new P0, ['FixedStringArray']
+.sub 'main' :main
+ .include 'test_more.pir'
+ plan(36)
+
+ 'test_set_size'() # 2 tests
+ 'test_reset_size'() # 1 test
+ 'test_set_first'() # 3 tests
+ 'test_set_second'() # 3 tests
+ 'test_out_of_bounds'() # 4 tests
+ 'test_set_via_pmc'() # 3 tests
+ 'test_get_via_pmc'() # 4 tests
+ 'test_interface_done'() # 4 tests
+ 'test_clone'() # 3 tests
+ 'test_clone_unitialized'() # 2 tests
+ 'test_truth'() # 2 tests
+ 'test_gc'() # 4 tests
+ 'test_get_iter'() # 1 test
+ 'test_freez_thaw'() # 1 test
+.end
+
+.sub 'test_set_size'
+ $P0 = new ['FixedStringArray']
+
+ $I0 = $P0
+ is($I0, 0, "Fresh array has 0 elements")
+
+ $P0 = 42
+ $I0 = $P0
+ is($I0, 42, "Size was set correctly")
+.end
+
+.sub 'test_reset_size'
+ $P0 = new ['FixedStringArray']
+
+ $I0 = 1
+ $P0 = 1
+ push_eh handled
+ $P0 = 2
+ $I0 = 0
+ handled:
+ pop_eh
+
+ ok($I0, "Can't resize")
+.end
+
+
+.sub 'test_set_first'
+ $P0 = new ['FixedStringArray']
+ $P0 = 1
+
+ $P0[0] = -7
+ $I0 = $P0[0]
+ is($I0, -7, "First element set to integer properly")
+
+ $P0[0] = 3.7
+ $N0 = $P0[0]
+ is($N0, 3.7, "First element set to number properly")
+
+ $P0[0] = "muwhahaha"
+ $S0 = $P0[0]
+ is($S0, "muwhahaha", "First element set to string properly")
+.end
+
+
+.sub 'test_set_second'
+ $P0 = new ['FixedStringArray']
+ $P0 = 2
+
+ $P0[1] = -7
+ $I0 = $P0[1]
+ is($I0, -7, "Second element set to integer properly")
+
+ $P0[1] = 3.7
+ $I0 = $P0[1]
+ is($I0, 3, "Second element set to number properly")
+
+ $P0[1] = "purple"
+ $S0 = $P0[1]
+ is($S0, "purple", "Second element set to string properly")
+.end
+
+.sub 'test_out_of_bounds'
+ $P0 = new ['FixedStringArray']
+ $P0 = 1
+
+ $I0 = 1
+ push_eh handle_set
+ $P0[2] = 7
+ $I0 = 0
+ handle_set:
+ ok($I0, "Can't set out-of-bounds element")
+
+ $I0 = 1
+ push_eh handle_set_negative
+ $P0[-42] = 7
+ $I0 = 0
+ handle_set_negative:
+ ok($I0, "Can't set element on negative index")
+
+ $I0 = 1
+ push_eh handle_get
+ $I1 = $P0[2]
+ $I0 = 0
+ handle_get:
+ ok($I0, "Can't get out-of-bounds element")
+
+ $I0 = 1
+ push_eh handle_get_negative
+ $I1 = $P0[-1]
+ $I0 = 0
+ handle_get_negative:
+ ok($I0, "Can't get element with negative index")
+
+.end
+
+
+# Set via PMC keys, access via INTs
+.sub 'test_set_via_pmc'
+ $P0 = new ['FixedStringArray']
+ $P0 = 3
+
+ $P1 = new ['Key']
+
+ $P1 = 0
+ $P0[$P1] = 25
+ $S0 = $P0[0]
+ is($S0, "25", "Set INTVAL via PMC Key works")
+
+ $P1 = 1
+ $P0[$P1] = 2.5
+ $S0 = $P0[1]
+ is($S0, "2.5", "Set FLOATVAL via PMC Key works")
+
+ $P1 = 2
+ $P0[$P1] = "bleep"
+ $S0 = $P0[2]
+ is($S0, "bleep", "Set STRING via PMC Key works")
+.end
+
+# Set via INTs, access via PMC Keys
+.sub 'test_get_via_pmc'
+ $P0 = new ['FixedStringArray']
+ $P0 = 1024
+
+ $P0[25] = 125
+ $P0[128] = 10.2
+ $P0[513] = "blah"
+
+ $P1 = new ['Integer']
+ $P1 = 123456
+ $P0[1023] = $P1
+
+ $P2 = new ['Key']
+
+ $P2 = 25
+ $I0 = $P0[$P2]
+ is($I0, 125, "Get INTVAL via Key works")
+
+ $P2 = 128
+ $N0 = $P0[$P2]
+ is($N0, 10.2, "Get FLOATVAL via Key works")
+
+ $P2 = 513
+ $S0 = $P0[$P2]
+ is($S0, "blah", "Get STRING via Key works")
+
+ $P2 = 1023
+ $I0 = $P0[$P2]
+ is($I0, 123456, "Get INTVAL for stored PMC via Key works")
- set I0,P0
- eq I0,0,OK_1
- print "not "
-OK_1: print "ok 1\n"
-
- set P0,1
- set I0,P0
- eq I0,1,OK_2
- print "not "
-OK_2: print "ok 2\n"
-
- end
-CODE
-ok 1
-ok 2
-OUTPUT
-
-pasm_error_output_like( <<'CODE', <<'OUTPUT', "Resetting array size (and getting an exception)" );
- new P0, ['FixedStringArray']
-
- set I0,P0
- set P0,1
- set P0,2
- print "Should have gotten an exception\n "
-
-
- end
-CODE
-/FixedStringArray: Can't resize!
-current instr\.:/
-OUTPUT
-
-#VIM's syntax highlighter needs this line
-
-pasm_output_is( <<'CODE', <<'OUTPUT', "Setting first element" );
- new P0, ['FixedStringArray']
- set P0, 1
-
- set P0[0],-7
- set I0,P0[0]
- eq I0,-7,OK_1
- print "not "
-OK_1: print "ok 1\n"
-
- set P0[0],3.7
- set N0,P0[0]
- eq N0,3.7,OK_2
- print "not "
-OK_2: print "ok 2\n"
-
- set P0[0],"muwhahaha"
- set S0,P0[0]
- eq S0,"muwhahaha",OK_3
- print "not "
-OK_3: print "ok 3\n"
-
- end
-CODE
-ok 1
-ok 2
-ok 3
-OUTPUT
-
-pasm_output_is( <<'CODE', <<'OUTPUT', "Setting second element" );
- new P0, ['FixedStringArray']
- set P0, 2
-
- set P0[1], -7
- set I0, P0[1]
- eq I0,-7,OK_1
- print "not "
-OK_1: print "ok 1\n"
-
- set P0[1], 3.7
- set N0, P0[1]
- eq N0,3.7,OK_2
- print "not "
-OK_2: print "ok 2\n"
-
- set P0[1],"purple"
- set S0, P0[1]
- eq S0,"purple",OK_3
- print "not "
-OK_3: print "ok 3\n"
-
- end
-CODE
-ok 1
-ok 2
-ok 3
-OUTPUT
-
-pasm_error_output_like( <<'CODE', <<'OUTPUT', "Setting out-of-bounds elements" );
- new P0, ['FixedStringArray']
- set P0, 1
-
- set P0[1], -7
-
- end
-CODE
-/FixedStringArray: index out of bounds!
-current instr\.:/
-OUTPUT
-
-pasm_error_output_like( <<'CODE', <<'OUTPUT', "Getting out-of-bounds elements" );
- new P0, ['FixedStringArray']
- set P0, 1
-
- set I0, P0[1]
- end
-CODE
-/FixedStringArray: index out of bounds!
-current instr\.:/
-OUTPUT
-
-pasm_output_is( <<"CODE", <<'OUTPUT', "Set via PMC keys, access via INTs" );
- .include 'fp_equality.pasm'
- new P0, ['FixedStringArray']
- set P0, 3
- new P1, ['Key']
-
- set P1, 0
- set P0[P1], 25
-
- set P1, 1
- set P0[P1], 2.5
-
- set P1, 2
- set P0[P1], "bleep"
-
- set I0, P0[0]
- eq I0, 25, OK1
- print "not "
-OK1: print "ok 1\\n"
-
- set N0, P0[1]
- .fp_eq_pasm(N0, 2.5, OK2)
- print "not "
-OK2: print "ok 2\\n"
-
- set S0, P0[2]
- eq S0, "bleep", OK3
- print "not "
-OK3: print "ok 3\\n"
-
- end
-CODE
-ok 1
-ok 2
-ok 3
-OUTPUT
-
-pasm_output_is( <<"CODE", <<'OUTPUT', "Set via INTs, access via PMC Keys" );
- .include 'fp_equality.pasm'
- new P0, ['FixedStringArray']
- set P0, 1024
-
- set P0[25], 125
- set P0[128], 10.2
- set P0[513], "cow"
- new P1, ['Integer']
- set P1, 123456
- set P0[1023], P1
-
- new P2, ['Key']
- set P2, 25
- set I0, P0[P2]
- eq I0, 125, OK1
- print "not "
-OK1: print "ok 1\\n"
-
- set P2, 128
- set N0, P0[P2]
- .fp_eq_pasm(N0, 10.2, OK2)
- print "not "
-OK2: print "ok 2\\n"
-
- set P2, 513
- set S0, P0[P2]
- eq S0, "cow", OK3
- print "not "
-OK3: print "ok 3\\n"
-
- set P2, 1023
- set P3, P0[P2]
- set I1, P3
- eq I1, 123456, OK4
- print "not "
-OK4: print "ok 4\\n"
-
- end
-CODE
-ok 1
-ok 2
-ok 3
-ok 4
-OUTPUT
+.end
-pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
-.sub _main
+.sub 'test_interface_done'
.local pmc pmc1
pmc1 = new ['FixedStringArray']
.local int bool1
does bool1, pmc1, "scalar"
- print bool1
- print "\n"
+ nok(bool1, "Does not scalar")
does bool1, pmc1, "array"
- print bool1
- print "\n"
+ ok(bool1, "Does array")
does bool1, pmc1, "no_interface"
- print bool1
- print "\n"
- end
-.end
-CODE
-0
-1
-0
-OUTPUT
-
-pasm_output_is( <<'CODE', <<'OUTPUT', "Clone" );
- new P0, ['FixedStringArray']
- set P0, 3
- set P0[0], "abcde"
- set P0[1], "fghi"
- set P0[2], "jkl"
- clone P1, P0
- set P0[0], ""
- set P0[1], ""
- set P0[2], ""
- set S0, P1[0]
- print S0
- set S0, P1[1]
- print S0
- set S0, P1[2]
- print S0
- print "\n"
- end
-CODE
-abcdefghijkl
-OUTPUT
-
-pasm_error_output_like( <<'CODE', <<'OUTPUT', "Cloning before size is set" );
- new P0, ['FixedStringArray']
- clone P1, P0
- set P0, 10
- set P1, 20
- print "ok\n"
- clone P2, P0
- set P2, 30
- end
-CODE
-/ok
-FixedStringArray: Can't resize!
-current instr\.:/
-OUTPUT
-
-#VIM's syntax highlighter needs this line
-
-pasm_output_is( <<'CODE', <<'OUTPUT', "Truth" );
- new P0, ['FixedStringArray']
- unless P0, OK1
- print "not "
-OK1: print "ok 1\n"
- set P0, 10
- if P0, OK2
- print "not "
-OK2: print "ok 2\n"
- end
-CODE
-ok 1
-ok 2
-OUTPUT
-
-pasm_output_is( <<'CODE', <<'OUTPUT', "Garbage collection" );
- new P0, ['FixedStringArray']
- set P0, 8192
- set I0, 0
-L1: set P0[I0], I0
- inc I0
- lt I0, 8192, L1
- sweep 1
- set S0, P0[1000]
- print S0
- print "\n"
- set S0, P0[2000]
- print S0
- print "\n"
- set S0, P0[4000]
- print S0
- print "\n"
- set S0, P0[8000]
- print S0
- print "\n"
- end
-CODE
-1000
-2000
-4000
-8000
-OUTPUT
+ nok(bool1, "Does not no_interface")
+.end
-pir_output_is( <<'CODE', <<'OUTPUT', "get_iter" );
-.sub 'main' :main
- new $P0, ['FixedStringArray']
- set $P0, 3
- $P0[0] = 42
- $P0[1] = 43
- $P0[2] = 44
+
+.sub 'test_clone'
+ new $P0, ['FixedStringArray']
+ set $P0, 3
+ set $P0[0], "abcde"
+ set $P0[1], "fghi"
+ set $P0[2], "jkl"
+ clone $P1, $P0
+ set $P0[0], ""
+ set $P0[1], ""
+ set $P0[2], ""
+ set $S0, $P1[0]
+ is($S0, "abcde", "First element cloned")
+ set $S0, $P1[1]
+ is($S0, "fghi", "Second element cloned")
+ set $S0, $P1[2]
+ is($S0, "jkl", "Third element cloned")
+.end
+
+.sub 'test_clone_unitialized'
+ $P0 = new ['FixedStringArray']
+ $P1 = clone $P0
+
+ $I0 = 0
+ push_eh clone_1
+ $P0 = 10
+ $P1 = 20
+ $I0 = 1
+ clone_1:
+ pop_eh
+ ok($I0, "Resize of uninitialized clone successful")
+
+ $I1 = 1
+ push_eh clone_2
+ $P2 = clone $P0
+ $P2 = 30
+ $I0 = 0
+ clone_2:
+ ok($I0, "Resize of initialization not successful")
+
+.end
+
+.sub 'test_truth'
+ $P0 = new ['FixedStringArray']
+ nok($P0, "Empty array is false")
+ $P0 = 10
+ ok($P0, "Non-empty array is true")
+.end
+
+.sub 'test_gc'
+ $P0 = new ['FixedStringArray']
+ $P0 = 8192
+
+ $I0 = 0
+ loop:
+ $P0[$I0] = $I0
+ inc $I0
+ sweep 1
+ if $I0 < 8192 goto loop
+
+ $S0 = $P0[1000]
+ is($S0, "1000", "1000th element survived")
+ $S0 = $P0[2000]
+ is($S0, "2000", "2000th element survived")
+ $S0 = $P0[4000]
+ is($S0, "4000", "4000th element survived")
+ $S0 = $P0[8000]
+ is($S0, "8000", "8000th element survived")
+.end
+
+.sub 'test_get_iter'
+ $P0 = new ['FixedStringArray']
+ $P0 = 3
+ $P0[0] = "foo"
+ $P0[1] = "bar"
+ $P0[2] = "baz"
+ $S0 = ""
$P1 = iter $P0
loop:
unless $P1 goto loop_end
$S2 = shift $P1
- say $S2
+ concat $S0, $S2
goto loop
loop_end:
+ is($S0, "foobarbaz", "Iteration works")
.end
-CODE
-42
-43
-44
-OUTPUT
-pir_output_is( <<'CODE', <<'OUTPUT', "freeze/thaw" );
-.sub 'main' :main
+.sub 'test_freez_thaw'
.local pmc fsa, it
.local string s
@@ -367,22 +305,15 @@
fsa = thaw s
it = iter fsa
+ $S0 = ""
loop:
unless it goto loop_end
s = shift it
- say s
+ concat $S0, s
goto loop
loop_end:
+ is($S0, "42434499101", "get_iter works")
.end
-CODE
-42
-43
-44
-99
-101
-OUTPUT
-
-1;
# Local Variables:
# mode: cperl
More information about the parrot-commits
mailing list