From c40e6ae736f82f133d89b9b60cd6ff23c7690c6a Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 27 Apr 2017 15:01:23 +0200 Subject: Update method sigs, type checking and tests --- t/01-reading.t | 3 +-- t/06-deduce-parser.t | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 t/06-deduce-parser.t (limited to 't') diff --git a/t/01-reading.t b/t/01-reading.t index 0792188..f834226 100644 --- a/t/01-reading.t +++ b/t/01-reading.t @@ -4,14 +4,13 @@ use v6.c; use Test; use lib "lib"; -plan 5; +plan 4; use Config; my $config = Config.new(); throws-like { $config.read("t/files/none") }, Config::Exception::FileNotFoundException, "Reading nonexisting file"; -throws-like { $config.read("t/files/config") }, Config::Exception::UnknownTypeException, "Reading file of unknown type"; throws-like { $config.read("t/files/config", "Config::Parser:NoSuchParserForTest") }, Config::Exception::MissingParserException, "Using non-existing parser"; my $hash = { diff --git a/t/06-deduce-parser.t b/t/06-deduce-parser.t new file mode 100644 index 0000000..2811d19 --- /dev/null +++ b/t/06-deduce-parser.t @@ -0,0 +1,39 @@ +#! /usr/bin/env perl6 + +use v6.c; +use Test; +use lib "lib"; + +use Config; + +plan 4; + +my $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"; +}; -- cgit v1.1