aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-27 14:53:13 +0200
committerPatrick Spek <p.spek@tyil.nl>2017-04-27 14:53:13 +0200
commitb366ef7066f63df2e19bd93e34de202f34a1c282 (patch)
treeb05a1017ca725e6d8f429836f6d76a3e7085ec42 /t
Initial commit
Diffstat (limited to 't')
-rw-r--r--t/01-read.t33
-rw-r--r--t/02-write.t34
-rw-r--r--t/files/config.toml3
-rw-r--r--t/files/merge.toml5
-rw-r--r--t/files/write.toml6
5 files changed, 81 insertions, 0 deletions
diff --git a/t/01-read.t b/t/01-read.t
new file mode 100644
index 0000000..fa5a75b
--- /dev/null
+++ b/t/01-read.t
@@ -0,0 +1,33 @@
+#! /usr/bin/env perl6
+
+use v6.c;
+use Test;
+use lib "lib";
+
+use Config;
+use Config::Parser::toml;
+
+plan 4;
+
+my $config = Config.new();
+
+ok $config.read("t/files/config.toml"), "File reading throws no error";
+
+subtest "Contents match" => {
+ plan 2;
+
+ is $config.get("header.a"), "a", "a = a";
+ is $config.get("header.b"), "b", "b = b";
+};
+
+ok $config.read("t/files/merge.toml"), "File merging throws no error";
+
+subtest "Contents match after merging" => {
+ plan 4;
+
+ is $config.get("header.a"), "a", "a = a";
+ is $config.get("header.b"), "b", "b = b";
+ is $config.get("header.c"), "c", "c = c";
+
+ is $config.get("merge-header.a"), "a", "a = a";
+};
diff --git a/t/02-write.t b/t/02-write.t
new file mode 100644
index 0000000..5eb7d92
--- /dev/null
+++ b/t/02-write.t
@@ -0,0 +1,34 @@
+#! /usr/bin/env perl6
+
+use v6.c;
+use Test;
+use lib "lib";
+
+use Config;
+use Config::Parser::toml;
+use File::Temp;
+
+plan 4;
+
+my $config = Config.new();
+
+$config.read({
+ first => {
+ a => "a",
+ b => "b"
+ },
+ second => {
+ a => "a",
+ c => "c"
+ }
+});
+
+my ($filename, $fh) = tempfile;
+
+ok $config.write($filename, "Config::Parser::toml"), "Write succeeded";
+
+is slurp("t/files/write.toml"), slurp($filename), "Written config is correct";
+
+ok $config.write($filename, "Config::Parser::toml"), "Write over non-empty file";
+
+is slurp("t/files/write.toml"), slurp($filename), "Written config is still correct";
diff --git a/t/files/config.toml b/t/files/config.toml
new file mode 100644
index 0000000..2e411d3
--- /dev/null
+++ b/t/files/config.toml
@@ -0,0 +1,3 @@
+[header]
+a = "a"
+b = "b"
diff --git a/t/files/merge.toml b/t/files/merge.toml
new file mode 100644
index 0000000..fee4bc5
--- /dev/null
+++ b/t/files/merge.toml
@@ -0,0 +1,5 @@
+[header]
+c = "c"
+
+[merge-header]
+a = "a"
diff --git a/t/files/write.toml b/t/files/write.toml
new file mode 100644
index 0000000..bb8d31a
--- /dev/null
+++ b/t/files/write.toml
@@ -0,0 +1,6 @@
+[first]
+a = "a"
+b = "b"
+[second]
+a = "a"
+c = "c" \ No newline at end of file