[svn:parrot] r41382 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun Sep 20 21:58:03 UTC 2009
Author: bacek
Date: Sun Sep 20 21:58:02 2009
New Revision: 41382
URL: https://trac.parrot.org/parrot/changeset/41382
Log:
[core] Implement FSA.get_string and FSA.is_equal
Modified:
trunk/src/pmc/fixedstringarray.pmc
trunk/t/pmc/fixedstringarray.t
Modified: trunk/src/pmc/fixedstringarray.pmc
==============================================================================
--- trunk/src/pmc/fixedstringarray.pmc Sun Sep 20 21:47:42 2009 (r41381)
+++ trunk/src/pmc/fixedstringarray.pmc Sun Sep 20 21:58:02 2009 (r41382)
@@ -489,6 +489,8 @@
/*
+=item C<STRING *get_string()>
+
=item C<STRING *get_repr()>
Returns the Parrot string representation C<key>.
@@ -496,6 +498,9 @@
=cut
*/
+ VTABLE STRING *get_string() {
+ return STATICSELF.get_repr();
+ }
VTABLE STRING *get_repr() {
@@ -518,6 +523,43 @@
}
+/*
+
+=item C<INTVAL is_equal(PMC *value)>
+
+The C<==> operation. Compares two array to hold equal elements.
+
+=cut
+
+*/
+
+ VTABLE INTVAL is_equal(PMC *value) {
+ INTVAL j, n;
+
+ if (value->vtable->base_type != SELF->vtable->base_type)
+ return 0;
+
+ n = SELF.elements();
+
+ if (VTABLE_elements(INTERP, value) != n)
+ return 0;
+
+ for (j = 0; j < n; ++j) {
+ STRING * const item1 = SELF.get_string_keyed_int(j);
+ STRING * const item2 = VTABLE_get_string_keyed_int(INTERP, value, j);
+
+ if (item1 == item2)
+ continue;
+
+ if (item1 == NULL || item2 == NULL)
+ return 0;
+
+ if (!Parrot_str_equal(interp, item1, item2))
+ return 0;
+ }
+
+ return 1;
+ }
/*
Modified: trunk/t/pmc/fixedstringarray.t
==============================================================================
--- trunk/t/pmc/fixedstringarray.t Sun Sep 20 21:47:42 2009 (r41381)
+++ trunk/t/pmc/fixedstringarray.t Sun Sep 20 21:58:02 2009 (r41382)
@@ -19,7 +19,7 @@
.sub 'main' :main
.include 'test_more.pir'
- plan(36)
+ plan(42)
'test_set_size'() # 2 tests
'test_reset_size'() # 1 test
@@ -32,9 +32,11 @@
'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
+ 'test_get_string'() # 1 test
+ 'test_equality'() # 3 tests
+ 'test_gc'() # 4 tests
.end
.sub 'test_set_size'
@@ -315,6 +317,38 @@
is($S0, "42434499101", "get_iter works")
.end
+.sub 'test_get_string'
+ $P0 = new ['FixedStringArray']
+ $P0 = 2
+ $P0[0] = "foo"
+ is($P0, '[ "foo", "" ]', "Array stringified properly")
+.end
+
+.sub 'test_equality'
+ .local pmc a1, a2
+ a1 = new ['FixedStringArray']
+ a2 = new ['FixedStringArray']
+
+ is(a1, a2, "Empty arrays are equal")
+
+ a1 = 3
+ isnt(a1, a2, "Different size arrays aren't equal")
+
+ a2 = 3
+
+ a1[0] = "foo"
+ a2[0] = "foo"
+ is(a1, a2, "Equal with first element set")
+
+ a1[1] = "bar"
+ a2[1] = "BAR"
+ isnt(a1, a2, "Not equal when second element differ")
+
+ a2[1] = "bar"
+ is(a1, a2, "Equal when second element same")
+.end
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list