aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-07-04 13:46:25 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-07-12 08:59:13 +0200
commitbd3bc6769547e89dc5d3e255aa4babc2cc5ffe48 (patch)
tree974bf72d443dbf0d1bffea29793becee806b43bc /t
parent2d0de9cc3f93f661044f20b55c6a03860e8a0de8 (diff)
Overhaul Config to 3.0.0
Diffstat (limited to 't')
-rw-r--r--t/01-reading.t35
-rw-r--r--t/02-getting.t18
-rw-r--r--t/04-setting.t2
-rw-r--r--t/05-null-parser.t10
-rw-r--r--t/06-deduce-parser.t38
-rw-r--r--t/07-keys.t2
-rw-r--r--t/08-unsetting.t.t7
-rw-r--r--t/10-template.t53
8 files changed, 82 insertions, 83 deletions
diff --git a/t/01-reading.t b/t/01-reading.t
index 722d6eb..ba9bd55 100644
--- a/t/01-reading.t
+++ b/t/01-reading.t
@@ -1,28 +1,17 @@
-#! /usr/bin/env perl6
+#! /usr/bin/env raku
-use v6.c;
+use v6.d;
use Test;
-plan 6;
+plan 4;
use Config;
+use Config::Parser::NULL;
-my Config $config = Config.new();
-my Str $null-parser = "Config::Parser::NULL";
+my Config $config = Config.new;
+my Config::Parser $null-parser = Config::Parser::NULL;
-throws-like { $config.read("t/files/none") }, Config::Exception::FileNotFoundException, "Reading nonexisting file";
-throws-like { $config.read("t/files/config", "Config::Parser:NoSuchParserForTest") }, Config::Exception::MissingParserException, "Using non-existing parser";
-
-subtest ".read allows for non-fatal execution with skip-not-found set", {
- plan 3;
-
- my %old = $config.get;
- my $result = $config.read("t/files/none", $null-parser, :skip-not-found);
-
- ok $result, "Result is ok";
- is-deeply $result.get, %old, "Config did not change";
- isa-ok $result, Config, ".read returned a Config";
-}
+throws-like { $config.read('t/files/none'.IO) }, X::Config::FileNotFound, 'Reading nonexisting file';
my %hash = %(
"a" => "a",
@@ -33,9 +22,9 @@ my %hash = %(
$config.read: %hash;
-is-deeply $config.get, %hash, "Correctly sets hash";
+is-deeply $config.get, %hash, 'Correctly sets hash';
-$config.read: %(
+$config.=read: %(
"b" => %(
"d" => "another",
),
@@ -52,7 +41,7 @@ is-deeply $config.get, %(
subtest {
plan 3;
- ok $config.read(("t/files/config", "t/files/config.yaml"), $null-parser, :skip-not-found), "All paths exist";
- ok $config.read(("t/files/config", "t/files/none", "t/files/config.yaml"), $null-parser, :skip-not-found), "At least one path exists";
- ok $config.read(("t/files/none", "t/files/none.yaml"), $null-parser, :skip-not-found), "No paths exist";
+ ok $config.read(("t/files/config".IO, "t/files/config.yaml".IO), $null-parser, :skip-not-found), "All paths exist";
+ ok $config.read(("t/files/config".IO, "t/files/none".IO, "t/files/config.yaml".IO), $null-parser, :skip-not-found), "At least one path exists";
+ ok $config.read(("t/files/none".IO, "t/files/none.yaml".IO), $null-parser, :skip-not-found), "No paths exist";
}, "Read with a List of paths";
diff --git a/t/02-getting.t b/t/02-getting.t
index 487b150..04859e2 100644
--- a/t/02-getting.t
+++ b/t/02-getting.t
@@ -18,17 +18,17 @@ $config.read({
is $config.get("a"), "a", "Get simple key";
is $config.get("b.c"), "c", "Get nested key";
-is $config.get("nonexistant", "test"), "test", "Get nonexistant key with default";
-ok $config.get("nonexistant") === Nil, "Get nonexistant key";
+is $config.get("nonexistent", "test"), "test", "Get nonexistent key with default";
+ok $config.get("nonexistent") === Nil, "Get nonexistent key";
is $config.get(["a"]), "a", "Get simple key by array";
is $config.get(["b", "c"]), "c", "Get nested key by array";
-is $config.get(["nonexistant"], "test"), "test", "Get nonexistant key by array with default";
-ok $config.get(["nonexistant"]) === Nil, "Get nonexistant key by array";
+is $config.get(["nonexistent"], "test"), "test", "Get nonexistent key by array with default";
+ok $config.get(["nonexistent"]) === Nil, "Get nonexistent key by array";
-is $config.<a>, "a", "Get simple key via associative index";
-is $config.<b.c>, "c", "Get nested key via associative index";
-ok $config.<nonexistant> === Nil, "Get nonexistant key via associative index";
+is $config<a>, "a", "Get simple key via associative index";
+is $config<b.c>, "c", "Get nested key via associative index";
+is $config<nonexistent>, Nil, "Get nonexistent key via associative index";
-is $config.get(Nil, "test"), "test", "Attempt .get with Nil key with default";
-ok $config.get(Nil) === Nil, "Attempt to .get with Nil key";
+is $config.get('nonexistent', "test"), "test", "Attempt .get with nonexistent key with default";
+is $config.get('nonexistent'), Nil, "Attempt to .get with nonexistent key";
diff --git a/t/04-setting.t b/t/04-setting.t
index 77039ca..96ab7c3 100644
--- a/t/04-setting.t
+++ b/t/04-setting.t
@@ -8,7 +8,7 @@ plan 4;
use Config;
-my $config = Config.new();
+my $config = Config.new;
is $config.set("a", "test").get("a"), "test", "Setting simple key";
is $config.set("b.c", "test").get("b.c"), "test", "Setting nested key";
diff --git a/t/05-null-parser.t b/t/05-null-parser.t
index 93be062..72aedf8 100644
--- a/t/05-null-parser.t
+++ b/t/05-null-parser.t
@@ -8,22 +8,22 @@ use Config::Parser::NULL;
plan 3;
-::("Config::Parser::NULL").set-config({
+Config::Parser::NULL.set-config({
"a" => "a",
"b" => {
"c" => "c"
}
});
-my Config $config = Config.new();
+my Config $config = Config.new;
-ok $config.read("t/files/config", "Config::Parser::NULL"), "Attempt to read a file with Config::Parser::NULL";
+ok $config.read('t/files/config'.IO, Config::Parser::NULL), "Attempt to read a file with Config::Parser::NULL";
-is-deeply $config.get(), {
+is-deeply $config.get, {
"a" => "a",
"b" => {
"c" => "c"
}
}, "Check read config from Config::Parser::NULL";
-ok $config.write("t/t/t"), "Attempt to write a file with Config::Parser::NULL";
+ok $config.write('t/t/t'.IO, Config::Parser::NULL), "Attempt to write a file with Config::Parser::NULL";
diff --git a/t/06-deduce-parser.t b/t/06-deduce-parser.t
deleted file mode 100644
index d1c065a..0000000
--- a/t/06-deduce-parser.t
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /usr/bin/env perl6
-
-use v6.c;
-use Test;
-
-use Config;
-
-plan 4;
-
-my Config $config = Config.new();
-
-subtest "Unknown parser type" => {
- plan 1;
-
- is $config.get-parser-type("config"), "", "Type for plain file without extension";
-};
-
-subtest "Check parser type by file extension" => {
- plan 2;
-
- is $config.get-parser-type("config.yaml"), "yaml", "Should return extension";
- is $config.get-parser-type("config.TOML"), "toml", "Should return lower-cased extension";
-};
-
-subtest "Check parser type for edge-cases defined in get-parser-type" => {
- plan 1;
-
- is $config.get-parser-type("config.yml"), "yaml", "yml --> yaml";
-};
-
-subtest "Returns correct fully qualified module name" => {
- plan 4;
-
- is $config.get-parser("config"), "Config::Parser::", "Empty parser on unknown type";
- is $config.get-parser("config.yaml"), "Config::Parser::yaml", "Extension when available";
- is $config.get-parser("config.TOML"), "Config::Parser::toml", "Lowercased extension";
- is $config.get-parser("config", "Config::Parser::NULL"), "Config::Parser::NULL", "Given string";
-};
diff --git a/t/07-keys.t b/t/07-keys.t
index 99bae81..ddc4fdf 100644
--- a/t/07-keys.t
+++ b/t/07-keys.t
@@ -19,6 +19,6 @@ my Config $c .= new.read: %(
my @keys = < a b c.a c.b >;
-is $c.keys, @keys, ".keys returns a list of all keys";
+is $c.keys.sort, @keys, ".keys returns a list of all keys";
# vim: ft=perl6 noet
diff --git a/t/08-unsetting.t.t b/t/08-unsetting.t.t
index 330ba5a..da76164 100644
--- a/t/08-unsetting.t.t
+++ b/t/08-unsetting.t.t
@@ -3,7 +3,7 @@
use v6.c;
use Test;
-plan 8;
+plan 4;
use Config;
@@ -16,11 +16,6 @@ $config.read: %(
),
);
-ok $config<a>:exists, "'a' exists";
-ok $config<a>:delete, "'a' gets deleted";
-nok $config<a>:exists, "'a' no longer exists";
-ok $config<c>:exists, "'c' remains untouched";
-
ok $config.has("c.d"), "'c.d' exists";
ok $config.unset("c.d"), "'c.d' gets deleted";
nok $config.has("c.d"), "'c.d' no longer exists";
diff --git a/t/10-template.t b/t/10-template.t
new file mode 100644
index 0000000..3baa15b
--- /dev/null
+++ b/t/10-template.t
@@ -0,0 +1,53 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+use Test;
+
+use Config;
+
+plan 2;
+
+subtest 'Flat template', {
+ plan 6;
+
+ my $config = Config.new({
+ foo => Any,
+ bar => Any,
+ }, :name<raku-config>);
+
+ ok $config, 'Config object instantiated';
+
+ ok $config.has('foo'), 'Config contains "foo"';
+ ok $config.has('bar'), 'Config contains "bar"';
+
+ nok $config.has('alpha'), 'Config does not contain "alpha"';
+ nok $config.has('beta'), 'Config does not contain "beta"';
+
+ is $config.keys.sort, < bar foo >, 'Config.keys is correct';
+}
+
+subtest 'Nested template', {
+ plan 7;
+
+ my $config = Config.new({
+ foo => {
+ alpha => Any,
+ },
+ bar => {
+ beta => Any,
+ },
+ baz => Any,
+ }, :name<raku-config>);
+
+ ok $config, 'Config object instantiated';
+
+ ok $config.has('foo'), 'Config contains "foo"';
+ ok $config.has('foo.alpha'), 'Config contains "foo.alpha"';
+ ok $config.has('baz'), 'Config contains "baz"';
+
+ nok $config.has('omega.phi'), 'Config does not contain "omega.phi"';
+ nok $config.has('omega'), 'Config does not contain "omega"';
+
+ is $config.keys.sort, < bar.beta baz foo.alpha >, 'Config.keys is correct';
+}