[Commits] [SCM] clawsker branch, master, updated. 1.3.3-6-g2d22700

mones at claws-mail.org mones at claws-mail.org
Sun Feb 21 22:41:40 UTC 2021


The branch, master has been updated
       via  2d22700ecba55e22ef657242c414cf12e20d3372 (commit)
      from  a1944ba9b1b6a2b0c4150f292c37171ea4320ad1 (commit)

Summary of changes:
 t/load_resource.t | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 t/save_resource.t | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+)
 create mode 100644 t/load_resource.t
 create mode 100644 t/save_resource.t


- Log -----------------------------------------------------------------
commit 2d22700ecba55e22ef657242c414cf12e20d3372
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Feb 21 23:41:13 2021 +0100

    Add tests for {load|save}_resource

diff --git a/t/load_resource.t b/t/load_resource.t
new file mode 100644
index 0000000..47bf7ae
--- /dev/null
+++ b/t/load_resource.t
@@ -0,0 +1,65 @@
+use 5.010_000;
+use strict;
+use utf8;
+use File::Temp qw(tempdir);
+use File::Spec::Functions;
+use Test::More tests => 7;
+
+require_ok ('Clawsker');
+
+my ($temp, $rc1);
+
+BEGIN {
+    $temp = tempdir (CLEANUP => 1);
+    $rc1 = catfile ($temp, 'ok.rc');
+    open my $rcf, '>', $rc1
+        or die "opening $rc1 for writing: $!\n";
+    print $rcf <<EORC
+[sect1]
+key1=value 1
+# some comment
+key2=value 2
+
+[sect2]
+# another comment
+# with two lines
+key1=value 3
+
+[sect3]
+# empty
+
+EORC
+}
+
+use Clawsker;
+
+my ($data, $meta) = Clawsker::load_resource($rc1);
+is ( ref $data, 'HASH', 'data is map' );
+is ( ref $meta, 'HASH', 'meta is map' );
+is ( keys %$data, 3, 'data has 2 keys' );
+is ( keys %$meta, 3, 'meta has 2 keys' );
+is_deeply (
+  $data,
+  { 'sect1' => {
+    'key1' => 'value 1',
+    'key2' => 'value 2',
+    '_' => [ '# some comment' ]
+  }, 'sect2' => {
+    'key1' => 'value 3',
+    '_' => [ '# another comment', '# with two lines' ]
+  }, 'sect3' => {
+    '_' => [ '# empty' ]
+  }},
+  'data ok'
+);
+is_deeply (
+  $meta,
+  { 'sect2' => {
+    'key1' => 9, '#' => 6
+  }, 'sect1' => {
+  'key1' => 2, 'key2' => 4, '#' => 1
+  }, 'sect3' => {
+    '#' => 11
+  }},
+  'meta ok'
+);
diff --git a/t/save_resource.t b/t/save_resource.t
new file mode 100644
index 0000000..a24fd66
--- /dev/null
+++ b/t/save_resource.t
@@ -0,0 +1,66 @@
+use 5.010_000;
+use strict;
+use utf8;
+use File::Temp qw(tempdir);
+use File::Spec::Functions;
+use Test::More tests => 4;
+
+require_ok ('Clawsker');
+
+my ($temp, $rc1, $data1, $meta1);
+
+BEGIN {
+    $temp = tempdir (CLEANUP => 1);
+    $rc1 = catfile ($temp, 'ok.rc');
+    $data1 = { 'sect1' => {
+        'key1' => 'value 1',
+        'key2' => 'value 2',
+        '_' => [ '# some comment' ]
+      }, 'sect2' => {
+        'key1' => 'value 3',
+        '_' => [ '# another comment', '# with two lines' ]
+      }, 'sect3' => {
+        '_' => [ '# empty' ]
+      }
+    };
+    $meta1 = { 'sect2' => {
+        'key1' => 9, '#' => 6
+      }, 'sect1' => {
+        'key1' => 2, 'key2' => 4, '#' => 1
+      }, 'sect3' => {
+        '#' => 11
+      }
+    };
+}
+
+use Clawsker;
+
+ok ( ! -e $rc1, 'no file yet' );
+
+Clawsker::save_resource($rc1, $data1, $meta1);
+
+ok ( -s $rc1, 'file has data' );
+
+open my $fh, '<', $rc1
+    or die "opening $rc1 for reading: $!\n";
+chomp(my @lines = <$fh>);
+close $fh;
+
+is_deeply (
+  \@lines,
+  [ '[sect1]',
+    '# some comment',
+    'key1=value 1',
+    'key2=value 2',
+    '',
+    '[sect2]',
+    '# another comment',
+    '# with two lines',
+    'key1=value 3',
+    '',
+    '[sect3]',
+    '# empty',
+    ''
+  ],
+  'data ok'
+);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Hidden preferences editor for Claws Mail


More information about the Commits mailing list