Commits

Shlomi Fish  committed 40a9cff

The scripts/Test.pm-to-Test-More.pl is more-or-less working.

  • Participants
  • Parent commits 7c7d49a

Comments (0)

Files changed (1)

File scripts/Test.pm-to-Test-More.pl

     die "Could not find any statements.";
 }
 
+sub is_comma
+{
+    my $node = shift;
+    return  $node->isa('PPI::Token::Operator') && ($node->content() eq ",");
+}
+
 foreach my $stmt (@{$statements})
 {
-    if ($stmt->child(0)->isa('PPI::Token::Word')
-        && ($stmt->child(0)->literal() eq "ok")
+    my $call = $stmt->child(0);
+    if ($call->isa('PPI::Token::Word')
+        && ($call->literal() eq "ok")
     )
     {
-        print "$stmt\n";
+        # print "$stmt\n";
         my $comment = PPI::Token::Comment->new;
         $comment->line(1);
         $comment->set_content ("# TEST\n");
         {
             $stmt->insert_before( $comment );
         }
+
+        my $args = $stmt->find_first('PPI::Structure::List')->find_first('PPI::Statement::Expression');
+
+        my $num_childs = scalar (() = $args->children());
+
+        my $num_args = 1 + scalar (() = grep { is_comma($_) } $args->children());
+
+        my $last_child = $args->child($num_childs - 1);
+        if (is_comma($last_child) 
+                ||
+            (
+                $last_child->isa('PPI::Token::Whitespace')
+                    && 
+                is_comma($args->child($num_childs - 2))
+            )
+        )
+        {
+            $num_args--;
+        }
+
+        if ( $num_args == 2)
+        {
+            $call->set_content('is');
+        }
+
+        my $test_op = PPI::Token::Operator->new(q{,});
+        my $test_ws = PPI::Token::Whitespace->new;
+        $test_ws->set_content(' ');
+        my $test_name = PPI::Token::Quote::Single->new(q{' TODO : Add test name'});
+        # $test_name->string(' TODO : Add test name');
+        $args->add_element($test_op);
+        $args->add_element($test_ws);
+        $args->add_element($test_name);
     }
 }