Skip to content

Commit

Permalink
add a get_string() VTABLE to pmcmatrix2d
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Nov 18, 2009
1 parent b58e1a6 commit 550b56d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/pmc/pmcmatrix2d.pmc
Expand Up @@ -102,4 +102,28 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
VTABLE_set_string_native(INTERP, item, value);
VTABLE_set_pmc_keyed(INTERP, SELF, key, item);
}

VTABLE STRING *get_string() {
INTVAL rows, cols;
STRING *pstr = Parrot_str_new(INTERP, "{", 1);
STRING * const strend = Parrot_str_new(INTERP, "}", 1);
STRING * const newline = Parrot_str_new(INTERP, "\n", 1);
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
PMC ** const s = attrs->storage;
const INTVAL rows_size = attrs->x;
const INTVAL cols_size = attrs->y;
for (cols = 0; cols < cols_size; ++cols) {
for (rows = 0; rows < rows_size; ++rows) {
PMC * const item = ITEM_XY_ROWMAJOR(s, rows_size, cols_size, rows, cols);
STRING * const str = VTABLE_get_string(INTERP, item);
STRING * const index = Parrot_sprintf_c(INTERP, "\t[%d,$d] = ", rows, cols);
pstr = Parrot_str_append(INTERP, pstr, index);
pstr = Parrot_str_append(INTERP, pstr, item);
pstr = Parrot_str_append(INTERP, pstr, newline);
}
pstr = Parrot_str_append(INTERP, pstr, strend);
pstr = Parrot_str_append(INTERP, pstr, newline);
}
return pstr;
}
}
10 changes: 5 additions & 5 deletions t/harness
Expand Up @@ -59,11 +59,11 @@ sub MAIN () {
}
}
}
if ($failed) {
if $failed {
say('failed ' ~ $failed ~ '/' ~ $num_tests ~ ' tests');
}
else {
if( @plan_parts[0] != 1 || $num_tests < 0) {
if @plan_parts[0] != 1 || $num_tests < 0 {
say('INVALID PLAN: ' ~ join('',@plan_parts));
$failed_files++;
}
Expand All @@ -73,14 +73,14 @@ sub MAIN () {
}
$total_passed := $total_passed + $passed;
$total_failed := $total_failed + $failed;
if( $num_tests != $curr_test ) {
if $num_tests != $curr_test {
say("Planned to run " ~ $num_tests ~ " tests but ran " ~ $curr_test ~ " tests");
say("FAILED");
}
}
if ($total_failed) {
if $total_failed {
say("FAILED " ~ $total_failed ~ '/' ~ ($total_passed+$total_failed));
} elsif ($failed_files) {
} elsif $failed_files {
say("FAILED " ~ $failed_files ~ " files, PASSED " ~ $total_passed ~ ' tests');
} else {
say("PASSED " ~ $total_passed ~ ' tests in ' ~ $total_files ~ ' files');
Expand Down

0 comments on commit 550b56d

Please sign in to comment.