factor out FindIsh, implement ForEach
[scpubgit/DKit.git] / t / findall.t
index 5302bbe..df84bfe 100644 (file)
@@ -27,15 +27,19 @@ $solver->facts->{shell_installed} = DX::OrderedSet->new(
   ],
 );
 
+$solver->add_rule(has_shell => [ 'Srv', 'Shell' ],
+  [ exists => [ qw(Name SI) ] =>
+    [ member_of => 'SI', \'shell_installed' ],
+    [ prop => 'SI' => \'server' => 'Name' ],
+    [ prop => 'Srv' => \'name' => 'Name' ],
+    [ prop => 'SI' => \'shell' => 'Shell' ]
+  ],
+);
+
 my @r = $solver->query([ 'X' ],
   [ findall => X => S =>
     [ member_of => 'S', \'server' ],
-    [ exists => [ qw(Name SI) ] =>
-      [ member_of => 'SI', \'shell_installed' ],
-      [ prop => 'SI' => \'server' => 'Name' ],
-      [ prop => 'S' => \'name' => 'Name' ],
-      [ prop => 'SI' => \'shell' => \'bash' ]
-    ],
+    [ has_shell => 'S', \'bash' ],
   ]
 )->results;
 
@@ -44,4 +48,23 @@ is_deeply(
   [ qw(one three four) ]
 );
 
+@r = $solver->query([],
+  [ foreach => S => [ [ member_of => 'S', \'server' ] ],
+    [ [ has_shell => 'S' => \'bash' ] ] ]
+)->results;
+
+ok(!@r, 'No results for only bash');
+
+$solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'bash' ]);
+$solver->add_rule(has_any_shell => [ 'S' ] => [ has_shell => 'S' => \'csh' ]);
+
+@r = $solver->query([],
+  [ foreach => S => [ [ member_of => 'S', \'server' ] ],
+    [ [ has_any_shell => 'S' ] ] ]
+)->results;
+
+# only three matches both legs of has_any_shell
+
+is(scalar(@r), 2, 'Two solutions for any shell');
+
 done_testing;