From c183301cb6690b9cdb8f50f476d5195adc57fdb2 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sun, 26 Aug 2018 13:06:38 +0200 Subject: Return self on .read --- t/01-reading.t | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 't') diff --git a/t/01-reading.t b/t/01-reading.t index 3a4388e..722d6eb 100644 --- a/t/01-reading.t +++ b/t/01-reading.t @@ -13,37 +13,46 @@ my Str $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"; -is $config.read("t/files/none", $null-parser, skip-not-found => True), True, ".read allows for non-fatal execution with skip-not-found set"; +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); -my $hash = { + ok $result, "Result is ok"; + is-deeply $result.get, %old, "Config did not change"; + isa-ok $result, Config, ".read returned a Config"; +} + +my %hash = %( "a" => "a", - "b" => { - "c" => "test" - } -}; + "b" => %( + "c" => "test", + ), +); -$config.read($hash); +$config.read: %hash; -is-deeply $config.get(), $hash, "Correctly sets hash"; +is-deeply $config.get, %hash, "Correctly sets hash"; -$config.read({ - "b" => { - "d" => "another" - } -}); +$config.read: %( + "b" => %( + "d" => "another", + ), +); -is-deeply $config.get(), { +is-deeply $config.get, %( "a" => "a", - "b" => { + "b" => %( "c" => "test", - "d" => "another" - } -}, "Correctly merges new hash into existing config"; + "d" => "another", + ), +), "Correctly merges new hash into existing config"; subtest { plan 3; - is $config.read(("t/files/config", "t/files/config.yaml"), $null-parser, skip-not-found => True), True, "All paths exist"; - is $config.read(("t/files/config", "t/files/none", "t/files/config.yaml"), $null-parser, skip-not-found => True), True, "At least one path exists"; - is $config.read(("t/files/none", "t/files/none.yaml"), $null-parser, skip-not-found => True), False, "No paths exist"; + 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"; }, "Read with a List of paths"; -- cgit v1.1