From: Will Budic Date: Wed, 5 Feb 2025 22:52:39 +0000 (+1100) Subject: TestManager updated, and new v.3.3.3 dev. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=8aaefcc76e6531ea2533f29dcb368496da96bfd7;p=PerlCNF.git TestManager updated, and new v.3.3.3 dev. --- diff --git a/old/lotto_tool.pl b/old/lotto_tool.pl index d69a2f3..2522cd1 100644 --- a/old/lotto_tool.pl +++ b/old/lotto_tool.pl @@ -15,8 +15,8 @@ my $content = qq| |; my $dom = Mojo::DOM->new($content); -print $dom->find('tr[class="balls"] td')->map('text')->join(","),"\n"; -$dom->find('tr[class="balls"] td')->last->append('4'); +print $dom->search('tr[class="balls"] td')->map('text')->join(","),"\n"; +$dom->search('tr[class="balls"] td')->last->append('4'); print $dom; diff --git a/tests/TestManager.pm b/tests/TestManager.pm index 2e4ab23..498992d 100644 --- a/tests/TestManager.pm +++ b/tests/TestManager.pm @@ -59,8 +59,9 @@ sub passed { } sub case { - my ($self, $out) =@_; - my ($package, $filename, $line) = caller; $filename =~ s/^(\/(.+)\/)//gs; + my ($self, $out, $ref) =@_; + my ($package, $filename, $line) = caller; $filename =~ s/^(\/(.+)\/)//gs; + die "Case REF not in ordinal string format!\n For -> $CWD/$filename:$line\n" if $ref && $ref !~ m/\d*/g; $stab=""; nextCase($self) if $self->{open}; print BRIGHT_CYAN,"\tCase ".$self->{test_cnt}.": $out", BLUE, "\n\tat -> ", @@ -130,9 +131,10 @@ sub evaluate { if(@_== 3 && $cc eq 'test-is-undef'){ my $swp = $aa; $aa = $bb; $bb = $cc; $cc = $swp } + $aa="" if !$aa; $bb="" if !$bb; $cc="" if !$cc; my ($package, $filename, $line) = caller; $filename =~ s/^(\.\/.*\/)/\@/; print BLINK. BRIGHT_RED."\t$stab Test ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}. - ": Failed! (". $self->{sub_err} .")",RESET, YELLOW, " $filename line $line\n", + ": Failed! (". $self->{sub_err} .")",RESET, YELLOW, " $filename:$line\n", BRIGHT_RED,"[$cc].eval(-> \$a->$aa, \$b->$bb <-)\n",RESET; return 0; } @@ -145,8 +147,13 @@ sub evaluate { # @return 1 on evaluation passed, 0 on failed. ### sub isDefined{ - my ($self, $var, $val)=@_; - die "The expected parameters required failed TestManager->isDefined($var,$val)!" if @_ < 3; + my ($self, $var, $val)=@_; + my ($package, $filename, $line) = caller; + die qq( The expected parameters count required + failed on TestManager->isDefined(\$var:"$var",\$val:"$val")! + \@Test -> $filename:$line + ) + if @_ < 2; my $ref = ref($val); if (defined $val||$ref){ print GREEN."\t$stab YDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}.": Passed -> Scalar [$var] is defined.\n" @@ -159,12 +166,12 @@ sub isDefined{ } sub isZeroOrEqual{ - my ($self, $var, $aa, $bb)=@_; - if ($aa == 0 or $aa==$bb){ + my ($self, $var, $aa, $bb)=@_;$bb =0 if !$bb; $aa = 0 if !$aa ; + if ($aa or $aa==$bb){ print GREEN."\t$stab YDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}.": Passed -> Scalar [$var] is ZeroOrEqual.\n" }else{ ++$self->{sub_err}; - print BLINK. BRIGHT_RED."\t$stab YDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}. ": Failed!"." ($self->{sub_err}) ".RESET. RED."Scalar [$var] is not equal!\n"; + print BLINK. BRIGHT_RED."\t$stab YDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}. ": Failed!"." ($self->{sub_err}) ".RESET. RED."Scalar [$var] is not ZeroOrEqual!\n"; return 0; } return 1; @@ -172,7 +179,7 @@ sub isZeroOrEqual{ ### # Performs non critical evaluation if an scalar is undefined. -# Atributes are $var for variable name and, $val the actual variable. +# Attributes are $var for variable name and, $val the actual variable. # @return 1 on evaluation passed, 0 on failed. ### sub isNotDefined{ @@ -181,7 +188,7 @@ sub isNotDefined{ print GREEN."\t$stab NDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}.": Passed -> Scalar [$var] is not defined.\n" }else{ ++$self->{sub_err}; - print BLINK. BRIGHT_RED."\t$stab NDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}. ": Failed!"." ($self->{sub_err}) ".RESET. RED."Scalar [$var] is defined!\n"; + print BLINK. BRIGHT_RED."\t$stab NDef ".$self->{test_cnt} .'.'. ++$self->{sub_cnt}. ": Failed!"." ($self->{sub_err}) ".RESET. RED."Scalar [$var] expected NOT but is defined!\n"; return 0; } return 1; @@ -321,21 +328,11 @@ our $DEC = "%-2d %s"; #under 100 lines pad like -> printf "%2d %s", $. sub frmln { my($at)=@_; return sprintf($DEC,$at) } -1; -=begin copyright -Programed by : Will Budić -EContactHash : 990MWWLWM8C2MI8K (https://github.com/wBudić/EContactHash.md) -Source : https://github.com/wBudić/PerlCNF.git -Documentation : Specifications_For_CNF_ReadMe.md - This source file is copied and usually placed in a local directory, outside of its repository project. - So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project. - Please leave source of origin in this file for future references. -Open Source Code License -> https://github.com/wBudić/PerlCNF/blob/master/ISC_License.md -=cut copyright +1; ### -# To debug in vscode you need the extension LanguageServer and Debuger by Gerald Richter +# To debug in vscode you need the extension LanguageServer and Debugger by Gerald Richter # the optional Perl Navigator uses also the LanguagerServer but isn't one. # To debug in vs code the local use lib ... have to be commented out. # Do not forget to uncoment them when commiting or using outside of vscode. @@ -345,8 +342,19 @@ Open Source Code License -> https://github.com/wBudić/PerlCNF/blob/master/ISC_L # requires full paths for Gerald's extension because it is dumb to reslove this. # # "perl.perlInc": [ -# "/home/will/dev_new/PerlCNF/tests", -# "/home/will/dev_new/PerlCNF/system/modules" +# "tests", +# "system/modules" # ] # -### \ No newline at end of file +### + +=begin copyright +Programed by : Will Budić +EContactHash : 990MWWLWM8C2MI8K (https://github.com/wBudić/EContactHash.md) +Source : https://github.com/wBudić/PerlCNF.git +Documentation : Specifications_For_CNF_ReadMe.md + This source file is copied and usually placed in a local directory, outside of its repository project. + So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project. + Please leave source of origin in this file for future references. +Open Source Code License -> https://github.com/wBudić/PerlCNF/blob/master/ISC_License.md +=cut copyright \ No newline at end of file diff --git a/tests/template_for_new_test.pl b/tests/template_for_new_test.pl index 3e5e440..f4ed042 100644 --- a/tests/template_for_new_test.pl +++ b/tests/template_for_new_test.pl @@ -14,8 +14,8 @@ use Syntax::Keyword::Try; # requires full paths for Gerald's extension because it is dumb to reslove this. # # "perl.perlInc": [ -# "/home/will/dev_new/PerlCNF/tests", -# "/home/will/dev_new/PerlCNF/system/modules" +# "tests", +# "system/modules" # ] # After that disable all the followin use lib ... statements: ### diff --git a/tests/testCNFAnons.pl b/tests/testCNFAnons.pl index 8ba7e1e..45f450a 100644 --- a/tests/testCNFAnons.pl +++ b/tests/testCNFAnons.pl @@ -15,11 +15,11 @@ try{ # Test instance creation. ### die $test->failed() if not $cnf = CNFParser->new(); - $test->case("Passed new instance CNFParser."); + $test->case("Passed new instance CNFParser.",'1'); $test->subcase('CNFParser->VERSION is '.CNFParser->VERSION); ${$cnf->anon()}{Public} = 'yes'; $test->evaluate('$cnf->anon(Public) == "yes"',$cnf->anon('Public'),'yes'); - $test->evaluate('$new->anon(Exclusive) == "yes"', CNFParser->new()->anon('Public'),'yes'); + $test->evaluate('$new->anon(Public) == "yes"', CNFParser->new()->anon('Public'),'yes'); # $test-> nextCase(); # @@ -28,13 +28,13 @@ try{ # Test private instance config. ### my $private = CNFParser->new(undef,{Exclusive=>'yes', ANONS_ARE_PUBLIC=>0}); - $test->case("Test new private CNFParser."); + $test->case("Test new private CNFParser.",'2'); $test->evaluate('$private->{Exclusive} is string "yes"?', $private->{Exclusive},'yes'); $test->evaluate('$private->anon(Exclusive)?', $private->anon('Exclusive'),undef); - $test->evaluate('$cnf->{Public} is still string "no"?', $cnf->anon('Public'),'yes'); - $test->evaluate('$private->{Public}', $private->anon('Public'),undef); + $test->evaluate('$cnf->{Public} is still string "yes"?', 'yes',$cnf->anon('Public')); + $test->isZeroOrEqual('$private->anon(Public)', $private->anon('Public')); # Not defined as it isn't coming from an config file. - $test->evaluate('Check $private->anon("Exlusive") is undef?', $private->anon("Exclusive"),undef); + $test->evaluate('Check $private->anon("Exclusive") is undef?', $private->anon("Exclusive"),undef); $private->parse(undef,qq/<>>/); $test->evaluate('Check $private->anon("test") is "best"?', $private->anon("test"),'best'); $test->evaluate('Check $cnf->anon("test") is undef?', $cnf->anon("test"),undef); @@ -42,10 +42,10 @@ try{ my $newInstance =CNFParser->new(); $test->evaluate('Check $newInstance->anon("Exclusive") == $cnf->anon("Exclusive")?', $newInstance->anon("Exclusive"), $private->anon("Exclusive")); ${$private->anon()}{Exclusive2} = 'yes'; - $test->case("Passed new private instance CNFParser."); + $test->passed("Passed new private instance of CNFParser."); # - $test-> nextCase(); + $test-> nextCase(); # #CNFParser->new()->parse(undef,q(<>>)); @@ -62,7 +62,7 @@ try{ die $test->failed() if keys %$anons == 0; my %h = %$anons; my $out; $out.="$_ => $$anons{$_}" for (keys %$anons); - $test->case("Obtained \%anons{$out}"); + $test->case("Obtained \%anons{$out}",'3'); # $test-> nextCase(); # @@ -70,8 +70,14 @@ try{ ### # List entry with non word instructions. ### - CNFParser->new()->parse(undef,q(<Spend in supermarket.>>)); - # + $test->case("List entry with non word instructions.",'4'); + my $list_parser = CNFParser->new()->parse(undef,q(<Spend in supermarket.>>)); + my @list = $list_parser -> list('list'); + my $instruction = $list[0]; + $test -> isDefined("\$instruction", $instruction); + $test -> evaluate('$instruction.ins == "20.05$"','20.05$',$instruction->{ins}); + $test -> evaluate('$instruction.val == "Spend in supermarket."','Spend in supermarket.',$instruction->{val}); + # $test-> nextCase(); # @@ -97,6 +103,7 @@ try{ die $test->failed() if $cnf->anon('The Added Two') ne $cnf2->anon('The Added Two'); $test->case("Contains shared 'The Added Two' ->$added"); $test->subcase(CNFParser::anon('The Added One')); + $test -> evaluate('CNFParser::anon(The Added One) == "Dynamically!"',CNFParser::anon('The Added One'),'Dynamically!'); # $test-> nextCase(); diff --git a/tests/testCNFNode.pl b/tests/testCNFNode.pl index 2963947..7179d96 100644 --- a/tests/testCNFNode.pl +++ b/tests/testCNFNode.pl @@ -15,16 +15,75 @@ use Syntax::Keyword::Try; try { ### # Test instance creation. ### + $test->case("Test CNFNode instance creation.",'1'); die $test->failed() if not my $node = CNFNode->new({'_'=>'node','#'=>1, DEBUG=>1}); - $test->evaluate("name==node",$node->name(),'node'); - $test->evaluate("val==1",$node->val(),1); - $test->case("Passed new instance for CNFParser."); + $test->passed("Passed new instance for CNFNode."); + $test->evaluate("name==node",$node->name(),'node'); + $test->evaluate("val==1",$node->val(),1); + + # + # + $test-> nextCase(); # + $test->case("TestComplex Shortife Format.",'2'); + + $node -> process( CNFParser->new(),q( + ___IN_SHORTIFE__ meta __\ + @@ __\ + A __\ + sub1 __\ + attr1 = Hello + a2 : World + __// + B __\ + sub2 __\ +Contains this paragraph, +which is nice. + ___/// + @@ __\ + tag: css_style + property: <**> + __// +)); + + my $list = $node->search('meta/@@'); + $test -> evaluate("\@list =\ $node->find('meta/@@')", 2,scalar(@$list)); + #my $sub = # $test-> nextCase(); # + $test->case("TestComplex Shortife Format Two, proper closing.",'3'); - $test->case("Test deep nested."); + $node -> process( CNFParser->new(),q( + ___IN_SHORTIFE__ meta2 __\ + @@ __\ + A __\ + sub1 __\ + attr1 = Hello2 + a2 : World2 __~ + __/ #sub1 + __/ + B __\ + sub2 __\ +Contains this paragraph, +which is nice. +Giving no advice. __~ + __/ #sub2 + __/ #B + __/ # @@ + @@ __\ + tag: css_style + property: <**> + __/ +)); + my $list2 = $node->search('meta2/@@'); + $test -> evaluate("\@list2 =\$node->find('meta2/@@')", 2,scalar(@$list2)); + # + $test-> nextCase(); + # + $test->case("TestComplex Shortife Format.",'4'); + + $test->case("Test deep nested.",'5'); my $errors = $node -> validate(qq( [a[ [b[ @@ -62,9 +121,9 @@ use Syntax::Keyword::Try; try { ### # Test validation. ### - $test->case("Testing validation."); + $test->case("Testing validation.",'6'); - $test->subcase('Misclosed property.'); + $test->subcase('Missclosed property.'); $errors = $node -> validate(qq( [a[ @@ -94,7 +153,7 @@ use Syntax::Keyword::Try; try { $test -> nextCase(); # - $test -> case("Test when tree script is collapsed."); + $test -> case("Test when tree script is collapsed.",'7'); $node -> process( CNFParser->new(),q( isDefined("$node->node('Example')",$node->node('Example')); $test -> evaluate("Do we have the Example node?", 'Example', $node->node('Example')->name()); $test -> subcase("Check for a node path."); - my $search = $node->find('Example/Paths/Attr1'); + my $search = $node->search('Example/Paths/Attr1'); $test -> isDefined("\$search",$search); $test -> evaluate("\$search", 'Hey! Let\'s Test. Is it corrupt, in da west?', $search); @@ -121,16 +180,16 @@ use Syntax::Keyword::Try; try { $test -> nextCase(); # - $test -> case("CNFNode to script."); + $test -> case("CNFNode to script.",'8'); print $node -> toScript(),"\n"; # $test -> nextCase(); # - $test -> case("Find path test for selecting children by certain name."); + $test -> case("Find path test for selecting children by certain name.",'9'); - $node -> process( CNFParser->new(),q( + $node -> process( CNFParser->new(),q( parent> )); - my $find = $node->find('/parent/has_div_children/@$'); - $test -> isDefined("\@find[/parent/has_div_children/@@]",$find); - $test -> evaluate("\$find[0]"," One ",$find->[0]->val()); - $test -> evaluate("\$find[0]"," Two ",$find->[1]->val()); - $test -> evaluate("\$find[0]","Three",$find->[2]->val()); - $test -> evaluate("\$find[0]"," Four ",$find->[3]->val()); + $test->subcase("Test contents of nodes via search."); + + my $found = $node->search('/node/parent/has_div_children/@$'); + $test -> isDefined ('@find[/parent/has_div_children/@$]',$found); + $test -> evaluate("\$found[0]"," One ",$found->[0]->val()); + $test -> evaluate("\$found[0]"," Two ",$found->[1]->val()); + $test -> evaluate("\$found[0]","Three",$found->[2]->val()); + $test -> evaluate("\$found[0]"," Four ",$found->[3]->val()); - $find = $node->find('/parent/div/*/text'); - $test -> isZeroOrEqual("\$find",CNFNode::_isNode($find)); - foreach(@$find){ + $found = $node->search('/node//parent/div/*/text'); + $test -> isZeroOrEqual("$found",CNFNode::_isNode($found)); + foreach(@$found){ my $path = $_->toPath(); say "<<$path<", $_->val(),">>>"; - $test -> failed("Path:$path not recognise!") + $test -> failed("Path:$path not recognize!") if $path ne 'node/parent/div/div/div/text' & $path ne 'node/parent/div/div/div/div/div/text' } - $test -> evaluate("\$find[/parent/div/*/text]","Deeply Nested!",$find->[0]->val()); - $test -> evaluate("\$find[/parent/div/*/text]","This Too!",$find->[1]->val()); + $test -> evaluate("\$found[/parent/div/*/text]","Deeply Nested!",$found->[0]->val()); + $test -> evaluate("\$found[/parent/div/*/text]","This Too!",$found->[1]->val()); - my $find2 = $node->find('/parent/*/text'); + my $found2 = $node->search('/parent/*/text'); $test -> subcase("Select all text nodes in parent.")-> - evaluate("\$find2[/parent/*/text]",3,scalar @$find2); - $test -> evaluate("\$find2[/parent/*/text]",'Shallow', $find2->[2]->val()); + evaluate("\$found2[/parent/*/text]",3,scalar @$found2); + $test -> evaluate("\$found2[/parent/*/text]",'Shallow', $found2->[2]->val()); $test -> subcase("Find and return value of attribute."); - my $find3 = $node->find('/parent/attribute'); - $test -> evaluate("[/parent/attribute]",'attribute value', $find3); + my $found3 = $node->search('/parent/attribute'); + $test -> evaluate("[/parent/attribute]",'attribute value', $found3); # $test -> nextCase(); diff --git a/tests/testCNFNodeShortiefs.pl b/tests/testCNFNodeShortiefs.pl index 13643c7..a07b65f 100644 --- a/tests/testCNFNodeShortiefs.pl +++ b/tests/testCNFNodeShortiefs.pl @@ -10,14 +10,106 @@ require CNFNode; my $test = TestManager->new($0); package Constants; -#<- Global Typeglob declared creates -# read only references but these are NOT constants. +# Global Typeglob declared creates +# read only references but these are NOT constants. *GlobelTroter = \"TEST"; package main; use Syntax::Keyword::Try; try { + + $test -> case("Test process list parsing shortif directly.", '1' ); + + $test -> subcase("Multiline value."); + my $nd1 = CNFNode::_createNode('root'); + CNFNode::_parseShortife( \$nd1, q( + A __\ + sub __\ +Contains this paragraph, +which is nice. +Giving no advice. +__~ + __/ + __/ + )); + my $a_sub = $nd1->node('A/sub/'); + $test->isDefined("has A/sub?",$a_sub); + $test ->evaluate("value of A/sub?.", +q(Contains this paragraph, +which is nice. +Giving no advice. +),$a_sub->val()); + + + my $parse_listed = CNFParser-> new() -> parse(undef,q(<<>>)); + $test->isDefined("CNF sequential anon format 'listed' is defined?",$parse_listed->anon('listed')); + $parse_listed = $parse_listed->anon('listed'); + $test->evaluate("CNF sequential anon format 'listed' has two itens?",2,scalar(@{$parse_listed->list()})); + + + $test -> case("Test process shortif directly with CNF sequential anon format.", '2'); + my $parsing = CNFParser-> new() -> parse(undef,q(<<>>)); + $test->isDefined("CNF sequential anon format node is defined?",$parsing->anon('node')); + + + $test -> case("Test Shortif regexp directly.",'3'); + my $nd_root = CNFNode::_createNode('root'); + CNFNode::_parseShortife( \$nd_root, q( + div__\ + test __\ + _______// + + )); + + CNFNode::_parseShortife( \$nd_root, q( + div__\ + a:1 + b:2 + child1__\ + has a value + __/ + child2__\ + __/ + c:3 + chd2 __\ + a __\ + b ___\ + c ____\ + d _____\ + ___///// + chd3 __\ + __/ + __/ + )); + + + + #say $nd_root->toScript(); + + $test -> isDefined("Root node has div?",$nd_root->node('div')); + $test -> evaluate ("Root node has div/a == 1?",1, $nd_root->node('div/a')); + $test -> evaluate ("Root node has div/b == 2?",2, $nd_root->node('div/b')); + $test -> evaluate ("Root node has div/c == 3?",3, $nd_root->node('div/c')); + $test -> evaluate ("Root node has div/child1?",'has a value', $nd_root->node('div/child1')->val()); + my $non_existent = $nd_root ->node('div/d'); + $test -> isZeroOrEqual ("Root node has div/d == 0?", $non_existent->val(), 0); + my $deep = $nd_root->node('div/chd2/a/b/c/d'); + $test -> isDefined ("Root node has div/chd2/a/b/c/d ?", $deep); + + + ### - $test -> case("Test typeglob as attribute type of constance."); + $test -> case("Test typeglob as attribute type of constance.",'4'); $test -> evaluate('Is *Globetroter main attribute eq to "TEST"', 'TEST', $Constants::GlobelTroter); # man:: package GlobelTroter; @@ -33,7 +125,7 @@ use Syntax::Keyword::Try; try { ### ### - $test -> case("Test shortife from file test.cnf."); + $test -> case("Test shortife from file test.cnf.",'5'); my $parser = CNFParser->new('test.cnf'); my @para_instructed = $parser->list("paragraphs"); my @paragraphs = $parser->listProcessed("paragraphs"); @@ -43,20 +135,84 @@ use Syntax::Keyword::Try; try { ### $test->nextCase(); ### - $test -> case("Test CNF frome test.cnf."); + $test -> case("Test CNF from test.cnf.",'6'); my $node = $parser->anon("paragraphs0"); $test-> isDefined("\$node",$node); #TODO Currently doesn't work with shortifes parsed nodes to return expected -> my $divs = $node->find("content/div/*"); - my $content = $node->find('content/div'); + my $content = $node->search('content/div'); my @divs = @{$content->{'@$'}}; $test -> evaluate("Does [".$content->name()."] have 2 child nodes?",2,scalar(@divs)); #TODO Following not working at the moment: #say $node->toScript(); - my $div1 = $node->find('content/div/div1'); + my $div1 = $node->search('content/div/div1'); $test->failed('content/div/div1 not found!') if not $test->isDefined("div1",$div1); $test->evaluate('content/div/div1[class] value matches?','paragraph',$div1->{class}); - say $node->toScript(); + #say $node->toScript(); + + + $test -> case("Test shortife from file test.cnf with nested nodes.",'7'); + my $meta = $parser -> anon('meta'); + $test->failed("meta shortif is not defined!") if not $test->isDefined("meta",$meta); + # A node can have a list of other nodes in an array style. + my $items = $meta->list(); + $test->failed("meta shortif has no list items!") if not $test->isDefined("\$meta->list()",$items); + my $count = @$items; + $test->evaluate("We expect 2 unnamed items in list.",2,$count); + + $test -> case("Test wild by tag name a root.",'8'); + $node -> process( $parser, q( + ___IN_SHORTIFE__ Users __\ + + User$$ __\ + Details__\ + Name : Albert + Surname : Cotton + DOB : 20-01-1998 + alias : cottona + Address __\ + _NOT_DISCLOSED_ __~ + __/// + + User$$ __\ + Details__\ + Name : Baldrick + Surname : Cotton + DOB : 08-07-2003 + alias : cottonb + Address __\ + _NOT_DISCLOSED_ __~ + __/// + + __/ +)); + my $users = $node -> search('Users/User*'); + $test->evaluate('search(Users/User*) == 2 of them?',2,scalar(@$users)); + $test->subcase("Test User Details."); + foreach my$user(@$users){ + if(my $details = $user->node('Details')){ + $test -> failed("Not matching expected: [" . $user->toPath(). "] ->".$user->toScript()) + if( + $details->{Name} ne 'Albert' and + $details->{Name} ne 'Baldrick' + or + $details->{Surname} ne 'Cotton' + ) + }else{ + $test -> failed("User has no [Details] node : ]" . $user->toPath() . "] ->".$user->toScript()) + } + if(my $alias = $user->node('Details/alias')){ + $test -> failed("Not matching expected: [" . $alias. "] for ->".$user->toScript()) + if( + $alias ne 'cottona' and $alias ne 'cottonb' + + ) + + }else{ + $test -> failed("User has no [Details/alias] attribute: ]" . $user->toPath() . "] ->".$user->toScript()) + } + } + ### $test->done(); # diff --git a/tests/testHTMLConversion.pl b/tests/testHTMLConversion.pl index 852a028..a97876b 100644 --- a/tests/testHTMLConversion.pl +++ b/tests/testHTMLConversion.pl @@ -58,7 +58,7 @@ use Syntax::Keyword::Try; try { my $html = $parser->data()->{'test1'}; my $tree = $parser->anon('test1'); die 'Not defined $tree' if !$tree; - my $images = $tree->find('list_images'); + my $images = $tree->search('list_images'); my $arr = $images->{'@@'}; die "Not expected size!" if @$arr != 2; @@ -85,7 +85,7 @@ use Syntax::Keyword::Try; try { #do not now bark at the wrong tree from before, we reassigning tree with: $tree = $parser->anon('test2'); die 'Not defined $tree2' if !$tree; - my $val = $tree->find('anon_value3'); + my $val = $tree->search('anon_value3'); $test -> isDefined("\$tree->find('anon_value3')",$val); $test -> evaluate($val,"REACHED 3!"); diff --git a/tests/testMarkDownPlugin_MD2HTMLConversion.pl b/tests/testMarkDownPlugin_MD2HTMLConversion.pl index f040bde..5d17a86 100644 --- a/tests/testMarkDownPlugin_MD2HTMLConversion.pl +++ b/tests/testMarkDownPlugin_MD2HTMLConversion.pl @@ -53,7 +53,7 @@ use Syntax::Keyword::Try; try { $test->subcase("Check embeded link to a perl constance <**>"); my $style = $parser->anon('HTML_STYLE'); $test->isDefined('$style',$style); - my @ret = $style->find('Content/MarkdownPlugin::CSS'); + my @ret = $style->search('Content/MarkdownPlugin::CSS'); my $script = $ret[0]; if($test->isDefined('$script',$script)){ if ($script->val() !~ m/\.B\s\{/gm){ diff --git a/tests/testSQL.pl b/tests/testSQL.pl index 407b80c..c1222d7 100644 --- a/tests/testSQL.pl +++ b/tests/testSQL.pl @@ -57,7 +57,7 @@ try{ $test->subcase('Test data to CNF nodes tree conversion for RSS feeds.'); my $perl_weekly = $cnf->getTree('Perl Weekly'); $test->isDefined("Has tree 'Perl Weekly'?",$perl_weekly); - my $url_node = $$perl_weekly->find("/Feed/URL"); + my $url_node = $$perl_weekly->search("/Feed/URL"); $test->isDefined("Has an URL defined node?",$url_node); $test->evaluate("CNF_FEED/Feed/URL is ok?","https://perlweekly.com/perlweekly.rss",$url_node); }else{ diff --git a/tests/testTree.pl b/tests/testTree.pl index a4fcaed..99aa5ec 100644 --- a/tests/testTree.pl +++ b/tests/testTree.pl @@ -1,9 +1,10 @@ #!/usr/bin/env perl -use warnings; use strict; +use warnings; use strict; use Syntax::Keyword::Try; use lib "tests"; use lib "system/modules"; +#use lib "system/modules"; require TestManager; @@ -16,7 +17,7 @@ my $cnf;my $err; try{ $test->case("Test nested multiline value."); - my $property = ${CNFNode->new({name=>'TEST'})->process(CNFParser->new(), qq( + my $property = ${CNFNode->new({name=>'TEST'})->process(CNFParser->new(), qq( [a[ [b[ [#[ @@ -25,32 +26,32 @@ try{ 3 ]#] - ]b] + ]b] ]a] [cell[ [#[ To Bottom - ]#] - ]cell] + ]#] + ]cell] ))}; - - my $prp = $property->find('cell'); + + my $prp = $property->search('cell'); $test ->isDefined('cell', $prp); print $prp->val(); - $prp = $property->find('a/b'); - $test ->isDefined('a/b', $prp); - $test ->evaluate('a/b=1\n2\n3\n', $prp->val(),"1\n2\n3\n"); + $prp = $property->search('a/b'); + $test ->isDefined('Payj:a/b', $prp); + $test ->evaluate('Path:a/b=1\n2\n3\n', $prp->val(),"1\n2\n3\n"); # ### # Test instance with cnf file creation. - ### + ### $test->case("Check Tree Algorithm."); -my $for_html = q( +my $for_html = q( div> div> >div> @@ -69,14 +70,16 @@ my $for_html = q( ); $prp = ${CNFNode->new({name=>'TEST'})->process(CNFParser->new(),$for_html)}; -my $nested = $prp->find('div/div/div/[0]/#'); -$test->evaluate("div/div/div/{0}/#",$nested,"This sample is more HTML look alike type of scheme."); +my $nested = $prp->search('/div/div/div/[0]/#'); +$test->evaluate("/div/div/div/[0]/#",$nested,"This sample is more HTML look alike type of scheme."); +$nested = $prp->search('/div/div/div/[1]/#'); +$test->evaluate("/div/div/div/[1]/#",$nested,"Other text."); -my $nada = $prp->find('nada'); +my $nada = $prp->search('nada'); $test->isNotDefined("\$nada",@$nada); -$nada = $prp->find('@$'); +$nada = $prp->search('@$'); $test->isDefined("TEST/@\$ properties subroperties",$nada); -$nada = $prp->find('test/#'); +$nada = $prp->search('test/#'); $test->evaluate("\$TEST/test",$nada,'me too'); @@ -86,21 +89,21 @@ $test->evaluate("\$TEST/test",$nada,'me too'); # my $tree = q{ # [node[ # [h1[ Hello World! ]h1] - # ]node] + # ]node] # }; # my $tree = q{ - # [node[ + # [node[ # div> # >div> - # ]node] + # ]node] # }; my $tree = q{ - [node[ + [node[ a:1 b=2 [1[ @@ -113,21 +116,21 @@ $test->evaluate("\$TEST/test",$nada,'me too'); [2[ [#[ World! ]#] ]2] - ]node] + ]node] }; $property = ${CNFNode->new({name=>'TEST'})->process(CNFParser->new(),$tree)}; # my %node = %${node($node, 'node/1/2/3')}; # print "[[".$node{'#'}."]]\n"; - + # print "[[".%$$node{'#'}."]]\n"; # $node = node($node, 'node/1/2/3/a'); - my $hello = $property->find('node/1/#'); - my $world = $property->find('node/2/#'); + my $hello = $property->search('node/1/#'); + my $world = $property->search('node/2/#'); $test -> evaluate("[[$hello]]",$hello, "Hello my\n"); #<- nl is simulated, not automaticaly assumed with multi values taged $test -> evaluate("[[$world]]",$world,' World! '); - + # - $test->nextCase(); + $test->nextCase(); # $cnf = CNFParser->new()->parse(undef,qq( @@ -150,23 +153,23 @@ $test->evaluate("\$TEST/test",$nada,'me too'); my $doc = $cnf->anon('DOC'); $test ->evaluate("\$doc->name() eg 'DOC'",$doc->name(),"DOC") ; - my $c = $doc->find('c'); - $test ->isDefined("doc/c", $c); + my $c = $doc->search('c'); + $test ->isDefined("doc/c", $c); $test ->evaluate("Node 'DOC/c' eq 'cccc'", $c->val(), 'cccc'); $test ->evaluate("App link is set", $doc->{APP},$app); # - $test->nextCase(); + $test->nextCase(); # $test->case("Test find by path."); #4 - my $val = $doc->find('c/2'); + my $val = $doc->search('c/2'); $test ->evaluate("Node 'DOC/c/2' eq 'barracuda'", $val, 'barracuda'); # - $test->nextCase(); + $test->nextCase(); # $test->case("Test Array parsing."); #5 @@ -176,18 +179,18 @@ $test->evaluate("\$TEST/test",$nada,'me too'); [@@[On single line]@@] <@@< One value. - ]@@] + ]@@] [@@[ Second value. ]@@] prop> [@@[ Third value. - ]@@] + ]@@] [@@[ - + [p1[ a:1 b:2 @@ -196,47 +199,30 @@ $test->evaluate("\$TEST/test",$nada,'me too'); ]@@] >node> }; - - # $tree = q{ - # node> - # }; - + + $property = ${CNFNode->new({name=>'TEST ARRAY'})->process($cnf,$tree)}; - my $node = $property->find('node/@@'); + my $node = $property->search('node/@@'); $test->isDefined('node/@@', $node); $test->evaluate('node/@@', scalar(@$node),5); - my $prop = $property->find('node/prop'); - $test ->isDefined('node/prop', $prop); - $test->evaluate('node/prop[{attribue}->val()', $prop->{'some attribute'}, 'Something inbetween!'); - - $node = $property->find('node/@@/p1'); + my $prop = $property->search('node/prop'); + $test ->isDefined('node/prop', $prop); + $test->evaluate('node/prop[{attribue}->val()', 'Something in between!', $prop->{'some attribute'}); + + $node = $property->search('node/@@/p1'); $test->isDefined('node/@@/p1', $node); - $val = $property->find('node/@@/p1/b'); + $val = $property->search('node/@@/p1/b'); $test->isDefined('node/@@/p1/b', $val); $test->evaluate('node/@@/p1/b', $val, '2' ); - # - $test->done(); + # + $test->done(); # } -catch { +catch { $test -> dumpTermination($@); $test -> doneFailed(); }