Permalink
Browse files

Add t/query to the harness. Add some basic tests for new path functio…

…nality
  • Loading branch information...
1 parent 3aa2160 commit c822d187ea4e94f6a5b3fbfbd42d668a81b757f6 @Whiteknight committed Feb 22, 2011
Showing with 80 additions and 0 deletions.
  1. +1 −0 t/harness
  2. +79 −0 t/query/Path.t
View
@@ -9,6 +9,7 @@ $harness.add_test_dirs("NQP",
"t/container",
"t/event",
"t/prototype",
+ "t/query",
:recurse(1)
);
$harness.run();
View
@@ -0,0 +1,79 @@
+INIT {
+ pir::load_bytecode("rosella/xunit.pbc");
+ pir::load_bytecode("rosella/query.pbc");
+}
+
+Rosella::Testcase::test(PathTest);
+
+class PathTest is Rosella::Testcase {
+
+ sub new_hash(*%h) { return %h; }
+
+ method test_hash_search() {
+ my $q := Rosella::build(Rosella::Query::Path);
+ my %a := new_hash(
+ :b(new_hash(
+ :foo("bar")
+ )),
+ :c(new_hash(
+ :baz("fie")
+ )),
+ :d("h")
+ );
+ my $result := $q.get(%a, 'b.foo');
+ Assert::equal($result, "bar");
+ }
+
+ method test_attr_search() {
+ my $q := Rosella::build(Rosella::Query::Path);
+ my $result := $q.get($q, '$!seperator');
+ Assert::equal($result, ".");
+ }
+
+ method test_hash_attr_search() {
+ my $q := Rosella::build(Rosella::Query::Path);
+ my %a := new_hash(
+ :b(new_hash(
+ :foo($q)
+ )),
+ :c(new_hash(
+ :baz("fie")
+ )),
+ :d("h")
+ );
+ my $result := $q.get(%a, 'b.foo.$!seperator');
+ Assert::equal($result, ".");
+ }
+
+ method test_attr_hash_search() {
+ self.unimplemented("Implement this");
+ }
+
+ method test_longest_key_hash_search() {
+ my $q := Rosella::build(Rosella::Query::Path);
+ my %a := new_hash(
+ :d("h")
+ );
+ %a{"d.e"} := new_hash(:f("g"));
+
+ my $result := $q.get(%a, 'd.e.f');
+ Assert::equal($result, "g");
+ }
+
+ method test_longest_key_hash_search_2() {
+ my $q := Rosella::build(Rosella::Query::Path);
+ my %a := new_hash(
+ :d(new_hash(
+ :e(new_hash(
+ :h("i")
+ ))
+ ))
+ );
+ %a{"d.e"} := new_hash(:f("g"));
+
+ my $result := $q.get(%a, 'd.e.f');
+ Assert::equal($result, "g");
+ $result := $q.get(%a, 'd.e.h');
+ Assert::equal($result, 'i');
+ }
+}

0 comments on commit c822d18

Please sign in to comment.