Index: src/pmc/boolean.pmc =================================================================== --- src/pmc/boolean.pmc (révision 41225) +++ src/pmc/boolean.pmc (copie de travail) @@ -25,23 +25,20 @@ /* -=item C +=item C -Object constructor. SELF is a Boolean Class object. Return a new -C object according to the passed PMC value. +Initialises SELF value according to the boolean value of the passed PMC. =cut */ - VTABLE PMC *instantiate(PMC *sig) { - /* XXX other types */ - const int argcP = REG_INT(interp, 3); - PMC * const res = pmc_new(interp, enum_class_Boolean); - - if (argcP) - SELF.set_bool(VTABLE_get_bool(interp, REG_PMC(interp, 5))); - - return PMCNULL; /* TODO */ + VTABLE void init_pmc(PMC *value) { + if (!PMC_IS_NULL(value)) { + SELF.set_bool(VTABLE_get_bool(INTERP, value)); + } + else { + SELF.set_bool(0); + } } /* Index: t/pmc/boolean.t =================================================================== --- t/pmc/boolean.t (révision 41225) +++ t/pmc/boolean.t (copie de travail) @@ -19,8 +19,9 @@ .sub main :main .include 'test_more.pir' - plan(28) + plan(30) init_int_tests() + instantiate_tests() num_tests() string_tests() pmc_to_pmc_tests() @@ -46,6 +47,21 @@ is($I0, 1, "Boolean converts negative int to true") .end +.sub instantiate_tests + $P0 = new ['Boolean'] + + $P0 = 1 + $P2 = get_class ['Boolean'] + $P1 = new $P2, $P0 + $I0 = $P1 + is($I0, 1, "Boolean instantiated to true") + + $P0 = 0 + $P1 = new ['Boolean'], $P0 + $I0 = $P1 + is($I0, 0, "Boolean instantiated to false") +.end + .sub num_tests $P0 = new ['Boolean']