From db90ff8ccd89dedb6b81dd0acb86f3e07b1b1b8b Mon Sep 17 00:00:00 2001 From: Will Budic Date: Tue, 11 Mar 2025 03:04:52 +1100 Subject: [PATCH] Added test case for NodeLists. --- system/modules/CNFNode.pm | 6 +++--- system/modules/CNFParser.pm | 32 +++++++++++++++----------------- tests/testCNFNode.pl | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/system/modules/CNFNode.pm b/system/modules/CNFNode.pm index ffb1fc6..083e212 100644 --- a/system/modules/CNFNode.pm +++ b/system/modules/CNFNode.pm @@ -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) { diff --git a/system/modules/CNFParser.pm b/system/modules/CNFParser.pm index 60a5fdf..a4c9ca7 100644 --- a/system/modules/CNFParser.pm +++ b/system/modules/CNFParser.pm @@ -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"} } diff --git a/tests/testCNFNode.pl b/tests/testCNFNode.pl index 7179d96..34bdc32 100644 --- a/tests/testCNFNode.pl +++ b/tests/testCNFNode.pl @@ -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> + )); + 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(); # -- 2.34.1