Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add a few more test for rosella build/construct. found and fixed a re…

…lated bug
  • Loading branch information...
commit 7dda3a3861fc4d13a10b6778312aebb6879d8ab6 1 parent 4315165
@Whiteknight authored
View
2  src/core/Rosella.winxed
@@ -45,7 +45,7 @@ namespace Rosella
{
var object = alloc(proto);
var class_obj = get_type_class(proto);
- var method = find_method(object, class_obj.name());
+ var method = find_named_method(object, class_obj.name());
if (method != null)
object.*method(pos:[flat], named:[flat,named]);
return object;
View
3  src/test/Assertions.winxed
@@ -107,7 +107,8 @@ namespace Assert
fail(message);
}
- function instance_of(var obj, var type, string message [optional], int has_msg [opt_flag]) {
+ function instance_of(var obj, var type, string message [optional], int has_msg [opt_flag])
+ {
message = default_message(message, has_msg, "object is not instance_of");
using Rosella.get_type_class;
var class_obj = get_type_class(type);
View
39 t/core/Rosella.t
@@ -6,9 +6,20 @@ INIT {
Rosella::Test::test(RosellaTest);
class My::Test::Class {
- method sum($a, $b) {
- return $a + $b;
- }
+ method sum($a, $b) { return $a + $b; }
+ method value() { return -3; }
+}
+
+class My::Test::With::BUILD {
+ has $!value;
+ method BUILD($num) { $!value := $num + 5; }
+ method value() { $!value // -1; }
+}
+
+class My::Test::With::Constructor {
+ has $!value;
+ method Constructor($num) { $!value := $num + 7; }
+ method value() { $!value // -2; }
}
class RosellaTest is Rosella::Test::Testcase {
@@ -19,6 +30,28 @@ class RosellaTest is Rosella::Test::Testcase {
}
method test_build() {
+ my $item := Rosella::build(My::Test::Class);
+ Assert::instance_of($item, My::Test::Class);
+ }
+
+ method test_build_BUILD_args() {
+ my $item := Rosella::build(My::Test::With::BUILD, 3);
+ Assert::equal($item.value, 8);
+ }
+
+ method test_build_without_BUILD() {
+ my $item := Rosella::build(My::Test::With::Constructor, 3);
+ Assert::equal($item.value, -2);
+ }
+
+ method test_construct_args() {
+ my $item := Rosella::construct(My::Test::With::Constructor, 4);
+ Assert::equal($item.value, 11);
+ }
+
+ method test_construct_without_constructor() {
+ my $item := Rosella::construct(My::Test::Class, 5);
+ Assert::equal($item.value, -3);
}
method test_get_type_name() {
Please sign in to comment.
Something went wrong with that request. Please try again.