]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Added test case for NodeLists.
authorWill Budic <redacted>
Mon, 10 Mar 2025 16:04:52 +0000 (03:04 +1100)
committerWill Budic <redacted>
Mon, 10 Mar 2025 16:04:52 +0000 (03:04 +1100)
system/modules/CNFNode.pm
system/modules/CNFParser.pm
tests/testCNFNode.pl

index ffb1fc601e0673a1350a361ff3cb47613233add8..083e2122a60a0ecd433d432d327fbc124e2cfe0b 100644 (file)
@@ -355,7 +355,7 @@ sub node {
                     }
                 # }
             }
-            return $ret
+            return $ret if $ret
        }
       return EMPTY
     }
@@ -689,9 +689,9 @@ sub _parseShortife {
                     my $bck_n = length($nest);
                     if($name){
                         if($sub->{'#'}){
-                            $sub->{'#'} = $sub->{'#'}."\n$name";
+                           $sub->{'#'} = $sub->{'#'}."\n$name";
                         }else{
-                            $sub->{'#'} = $name;
+                           $sub->{'#'} = $name;
                         }
                     }
                     for(0..$bck_n-1) {
index 60a5fdf412d650cbae24a4915de94b1a8deb30ee..a4c9ca7ab036df7f58199796d34f27a896c52b56 100644 (file)
@@ -1450,23 +1450,23 @@ sub log {
         my $logfile  = $log{file};
         my $tail_cnt = $log{tail};
         if($logfile){
-                mkdir $dir if not ( -e $dir and -d $dir);
-                open (my $fh, ">>", $dir.$logfile) or die $!;
-                print $fh $time . " - " . $message ."\n";
-                close $fh;
-                if($tail_cnt>0 && !$LOG_TRIM_SUB){
-                    $fh = File::ReadBackwards->new($dir.$logfile) or die $!;
-                    if($fh->{lines}>$tail_cnt){
-                        $LOG_TRIM_SUB = sub {
-                            my $fh = File::ReadBackwards->new($dir.$logfile) or die $!;
-                            my @buffer; $buffer[@buffer] = $fh->readline() for (1..$tail_cnt);
-                            open (my $fhTemp, ">", "/tmp/$logfile") or die $!;
-                                    foreach my $line(reverse @buffer){print $fhTemp $line if $line}
-                            close $fhTemp;
-                            move("/tmp/$logfile",$dir.$logfile)
-                        }
+            mkdir $dir if not ( -e $dir and -d $dir);
+            open (my $fh, ">>", $dir.$logfile) or die $!;
+            print $fh $time . " - " . $message ."\n";
+            close $fh;
+            if($tail_cnt>0 && !$LOG_TRIM_SUB){
+                $fh = File::ReadBackwards->new($dir.$logfile) or die $!;
+                if($fh->{lines}>$tail_cnt){
+                    $LOG_TRIM_SUB = sub {
+                        my $fh = File::ReadBackwards->new($dir.$logfile) or die $!;
+                        my @buffer; $buffer[@buffer] = $fh->readline() for (1..$tail_cnt);
+                        open (my $fhTemp, ">", "/tmp/$logfile") or die $!;
+                                foreach my $line(reverse @buffer){print $fhTemp $line if $line}
+                        close $fhTemp;
+                        move("/tmp/$logfile",$dir.$logfile)
                     }
                 }
+            }
         }
     }
     return $time . " " .$message;
@@ -1494,8 +1494,6 @@ sub trace {
         cluck $message
     }
 }
-
-
 sub dumpENV{
     foreach (keys(%ENV)){print $_,"=", "\'".$ENV{$_}."\'", "\n"}
 }
index 7179d9673e84d2a193ba7c2d72cfb2288d19f4c0..34bdc32ce74b263482161b9945bfae652eff6d26 100644 (file)
@@ -255,6 +255,39 @@ Giving no advice.  __~
     $test -> nextCase();
     #
 
+    $test -> case("Find path test for selecting children by certain name.",'10');
+
+    $node -> process( CNFParser->new(),q(
+<ListNodes<  __IN_SHORTIFE__
+@@ _\
+1
+__/
+@@ __\
+2
+__/ 
+@@ __\
+3
+__/
+settings __\
+    attributes __\
+        A = 101
+        B =202 
+        __~        
+    __/
+__/
+>ListNodes>
+        ));
+    my $plist = $node -> node('ListNodes')->list();
+    $test->evaluate("ListNodes has three elemenet?", 3, scalar(@$plist));
+    $test->evaluate("ListNodes[0] is 1?", 1, @$plist[0]->val());
+    $test->evaluate("ListNodes[0] is 2?", 2, @$plist[1]->val());
+    $test->evaluate("ListNodes[0] is 3?", 3, @$plist[2]->val());
+
+    my $attrs = $node -> node('ListNodes/settings/attributes');
+    $test->isDefined("ListNodes/settings/attributes", $attrs);
+    $test->evaluate("attrs/A is 1?", 101, $attrs->{A});
+    $test->evaluate("attrs/B is 1?", 202, $attrs->{B});
+
     #
     $test->done();
     #