]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Unsuited yet bunch.
authorWill Budic <redacted>
Thu, 3 Jul 2025 07:27:39 +0000 (17:27 +1000)
committerWill Budic <redacted>
Thu, 3 Jul 2025 07:27:39 +0000 (17:27 +1000)
tests/testCLIArgumentOptions.pl [new file with mode: 0644]
tests/testSQL_TaskList.pl
tests/test_CursesProgressBar.pl [new file with mode: 0644]

diff --git a/tests/testCLIArgumentOptions.pl b/tests/testCLIArgumentOptions.pl
new file mode 100644 (file)
index 0000000..c915286
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+use warnings; use strict;
+use Syntax::Keyword::Try;
+#no critic "eval"
+
+use lib "tests";
+use lib "system/modules";
+# use lib::relative "../system/modules";
+
+require TestManager;
+require CNFParser;
+
+my $test = TestManager -> new($0) -> unsuited();
+
+my $cnf;
+
+try{
+    ###
+    # Test instance creation.
+    #
+    die $test->failed() if not $cnf = CNFParser->new();
+    $test->case("Passed new instance CNFParser.");
+    #
+    $test-> nextCase();
+    #
+    $test->case("Confirm and Check argument options defaults.");
+    my $CNF_SCRIPT = qq{
+        <<< ARGUMENTS
+        -x=0            #  x,y positions.
+        -Y = 10 
+        -text  = "Some Value"
+        -text  = This added value. # Will convert -text argument into an array.
+        -text* = cnf_anon_name     # Will link add script of some anon to now array -text.
+        --showLog = 0
+        --dump_pump
+        >>>
+        <<cnf_anon_name<This is a linked value.>>
+    };
+    $cnf->parse(undef,$CNF_SCRIPT);
+
+    $test->case("Check arguments obtained.");
+    my $args = $cnf->anon(CNFParser::APP_ARGS());
+    if($test->isDefined("args", $args)){
+       my @args = @$args;
+       $test->evaluate("\@args has elements?", 7,scalar @args) ;
+
+    }else{
+        $test -> failed("Arguments not have been obtained!")
+    }
+
+    #
+    $test-> nextCase();
+    #
+
+
+    #
+    $test->done();
+    #
+}
+catch{
+   $test -> dumpTermination($@);
+   $test -> doneFailed();
+}
+
+#
+#  TESTING ANY POSSIBLE SUBS ARE FOLLOWING FROM HERE  #
+#
\ No newline at end of file
index e2fbcabf178066afd2b284f416dbfabd981d41ff..b14b1e3b6f2998b295121be5248d3ad112b97714 100644 (file)
@@ -11,21 +11,25 @@ require TestManager;
 require CNFParser;
 require CNFSQL;
 
-my $test = TestManager -> new($0);
+my $test = TestManager -> new($0)->unsuited();
 my $cnf;
 
 try{
 
 
-   $test->case("Test local SQL Database Setup.");
+   $test->case("Test direct local SQL Database Setup and Init.");
    my $content = do {local $/;<DATA>};
    $cnf = CNFParser->new(undef,{DO_ENABLED=>1,DEBUG=>1,'%LOG'=>{console=>1},TZ=>"Australia/Sydney"});
    $cnf->parse(undef,$content);
    my $sql = $cnf->SQL();
    $test->subcase("Test CNFSQL obtained.");
    $test->evaluate("Is CNFSQl ref?","CNFSQL", ref($sql));
-   my $db = CNFSQL::_connectDB('test','test','DBI:SQLite:','test_tasks.db');
+   my $db_path = "$0"; $db_path =~ s/.pl$//; $db_path .= ".db";
+   # `rm $db_path` if -f $db_path;
+   my $db = CNFSQL::_connectDB('test','test','DBI:SQLite:', $db_path);
    $sql->initDatabase($db,0);
+   
+   
    #
    #
    $test->nextCase();
@@ -40,30 +44,35 @@ catch{
 }
 
 __DATA__
-!CNF3.0
+!CNF3.3.4
+//ID when is of CNF_ID column name, AUTOINCREMENT is done by CNF and it is a primary unique key, not by the database.
 << TASKS <DATA> __SQL_TABLE__
-ID`Date _DATE_ `Due _DATE_ `Task __TEXT__`Completed _BOOL_`Priority __ID_~
+ID __CNF_ID__`Date _DATE_ `Due _DATE_ `Task __TEXT__`Completed _BOOL_`Priority __ID_~
 #`2023-10-18`2023-11-22`Write test.`0`1~
-#`2023-10-18`2023-12-01`Implement HSHContact.`0`5~
+#`2023-10-18`2023-12-01`Implement HSHContact.`0`3~
 >><<PRIORITIES <DATA> __SQL_TABLE__
-ID`Name`~
+ID __CNF_ID__`Name`~
 1`High`~
 2`Medium`~
 3`Low`~
 >>
 << TASKS <DATA> __SQL_TABLE__
-ID`Date _DATE_ `Due _DATE_ `Task __TEXT__`Completed _BOOL_`Priority __ID_~
-#`2023-10-18`2023-11-22`Write test.`0`1~
+ID __CNF_ID__`Date      _DATE_ `Due     _DATE_ `Task    __TEXT__`Completed    _BOOL_`Priority    __ID_~
+#`2023-10-18`2023-11-24`Write test2.`0`1~
 #`2023-10-18`2023-12-01`Implement HSHContact.`0`2~
 #`2023-10-20`2023-12-05`Start documentation page for CNFMeta DATA headers.`0`3~
+#`2025-05-21 18:51:43`2023-12-05`Made CNFSQL initDatabase working again.`yes`3~
+#`2025-05-21`2025-05-22`Write test3.`0`1~
+
 >>
-<< SHOPPING_LIST <DATA> __SQL_TABLE__
-ID`Item`Pending __BOOL__ `Date __DATE__~
-#`Tumeric Powder`no`now~
-#`Vanila Essence`yes`now~
-#`Pizza Flour`0`now~
-#`Jasmin Rice``now~
-#`Nutmeg`no`now~
+<< SHOPPING_LIST <DATA> __SQL_TABLE__ 
+ID`Item`Pending __BOOL__ `Date __DATE__`Priority _ID_~
+#`Tumeric Powder`no`now`1~
+#`Vanila Essence`yes`now`1~
+#`Pizza Flour`0`now`3~
+#`Jasmin Rice``now`2~
+#`Nutmeg`no`now`2~
+#`Salt``now`2~
 
 
 >>
\ No newline at end of file
diff --git a/tests/test_CursesProgressBar.pl b/tests/test_CursesProgressBar.pl
new file mode 100644 (file)
index 0000000..a8dda89
--- /dev/null
@@ -0,0 +1,182 @@
+#!/usr/bin/env perl
+use warnings; use strict;
+use Syntax::Keyword::Try;
+#no critic "eval"
+
+###
+use lib "tests";
+use lib "local";
+use lib::relative "../system/modules";
+    require CNFParser;
+    require CNFDateTime;
+    require CNFScriptToANSIFormatter;
+
+
+use lib "system/modules";
+
+require TestManager;
+my $test = TestManager -> new($0)-> unsuited();
+my $cnf;
+
+try{
+    ###
+    # Test instance creation.
+    #
+    # die $test->failed() if not $cnf = CNFParser->blank({DEBUG=>1});
+    # $test->case("Passed new instance CNFParser.");
+    # #
+    # $test-> nextCase();
+    # #
+    $test->case("Initiate Curses UI.");
+
+
+use lib "/home/will/dev_new/web_imports_cloned/CPAN/Curses-UI-0.9609/lib";
+use Curses::UI;
+use Time::HiRes qw(usleep);
+use feature 'say';
+
+
+
+   # Create the root object.
+    my $cui = new Curses::UI (
+        -debug => $cnf->{DEBUG},
+        -color_support => 1, -clear_on_exit => 0
+    );
+
+
+
+    my ($x,$y,$pos)=(0,0,0);
+    my $win = $cui->add('window_id', 'Window');
+
+    my $editor = $win->add(
+       'editor', 'TextEditor',
+       -border          => 1,
+       -padtop          => 0,  
+       -padbottom       => 3,
+       -showlines       => 0,
+       -sbborder        => 0,
+       -vscrollbar      => 1,
+       -hscrollbar      => 1,
+       -showhardreturns => 0,
+       -wrapping        => 0, # wrapping slows down the editor :-(
+       -text            => "Fetching..",
+);
+
+#     my $progressbar = $win->add(
+#             'myprogressbar', 'Progressbar',
+#             #-max       => 250,
+#             -pos       => 0,
+#             -fg => "blue",
+#             -bfg => "yellow",
+#             -y=>$cui->{-height}-4
+#     );
+#     my $action = $win->add(
+#             'myaction', 'Label',
+#             -fg => "red",
+#             -text      => 'Performing test...                     ',
+#             -pos       => 0,
+#             -y=>$cui->{-height}-1
+#     );
+# while($pos<101){
+#     $action->draw;
+# $progressbar->draw;
+# $progressbar->pos(++$pos);
+# usleep(rand(25000));
+# my $text = "Progress position  $pos   ";
+#    $action->text($text);
+# }
+# sleep(1);
+
+    
+use File::Type;
+ my $ft = File::Type->new();
+my $dir = $ENV{HOME};
+opendir DIR,$dir;
+my @dir = readdir(DIR);
+close DIR;
+
+my $max = @dir;
+my ($buffer,$other);
+$pos = 0;
+
+    my $action = $win->add(
+            'myaction', 'Label',
+            -fg => "red",
+            -text      => 'Listing files...                     ',
+            -pos       => 0,
+            -y=>$cui->{-height}-1
+    );
+my $progressbar = $win->add(
+            'myprogressbar2', 'Progressbar',
+            -max       => $max,
+            -pos       => 1,
+            -fg => "red",
+            -bfg => "yellow",
+            -y=>$cui->{-height}-4
+    );
+
+my $end=$cui->{-height}-4;
+my $top=$cui->{-height}-8;
+my $cur=$top;
+$cui->keys_to_lowercase();
+foreach(@dir){
+    usleep(rand(5000));
+    $progressbar->draw;
+    $progressbar->pos($pos);
+    $action->draw;
+if (-f $dir . "/" . $_ ){
+    my $file =  "$dir/$_";
+    $action->text($file);
+    my $mime_type =  $ft->mime_type($file);
+    if($mime_type eq 'text/script' || $ft->checktype_filename($file) =~ /x-sh$/){
+        $buffer .=  $file. " type: ". $mime_type . "\n";
+        $editor->text($buffer);
+        # $win->add(
+        #     'myaction'.$pos, 'Label',
+        #     -fg => "yellow",
+        #     -text      => $file, 
+        #     -x=>0,
+        #     -y=>$cur++
+        #     )->draw;
+        #     if($cur>=$end){
+        #        $cur=$top;
+        #     }
+        $editor->cursor_to_end();
+    }else{
+        $other .= $ft->checktype_filename($file)."::$file\n";
+    }
+}
+# elsif(-d $dir . "/" . $_){
+# }
+$progressbar->pos(int(++$pos));
+}
+
+
+$cui->set_binding(sub{$cui->status("DONE! ctrl+Q")}, "\cC");
+$cui->set_binding(sub{$cui->mainloopExit} , "\cQ");
+$editor->focus();
+$cui->mainloop;
+
+
+$cui->leave_curses ();
+
+say $buffer;
+
+say $other;
+
+$cui->reset_curses ();
+
+
+
+    #
+    $test->done();
+    #
+}
+catch{
+   $test -> dumpTermination($@);
+   $test -> doneFailed();
+}
+
+#
+#  TESTING ANY POSSIBLE SUBS ARE FOLLOWING FROM HERE  #
+#
\ No newline at end of file