aboutsummaryrefslogtreecommitdiff
path: root/lib/Config
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-26 23:08:59 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-07-25 02:16:19 +0200
commit312b33592df7409745b44503e5558bb173a8e6f7 (patch)
treefafb21c1c9db6f543fb213c9d658e5f91f027788 /lib/Config
parent0a93729f52df56663ba61766663166de9db98f23 (diff)
Add Config::Parser::NULL for testcases
Diffstat (limited to 'lib/Config')
-rw-r--r--lib/Config/Parser.pm66
-rw-r--r--lib/Config/Parser/NULL.pm631
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/Config/Parser.pm6 b/lib/Config/Parser.pm6
index 1a99ad6..d067513 100644
--- a/lib/Config/Parser.pm6
+++ b/lib/Config/Parser.pm6
@@ -6,6 +6,8 @@ use Config::Exception::UnimplementedMethodException;
class Config::Parser
{
+ #| Attempt to read the file at a given $path, and returns its
+ #| parsed contents as a Hash.
method read(Str $path --> Hash)
{
Config::Exception::UnimplementedMethodException.new(
@@ -13,7 +15,9 @@ class Config::Parser
).throw();
}
- method write(Str $path, Hash $config --> Hash)
+ #| Attempt to write the $config Hash at a given $path. Returns
+ #| True on success, False on failure.
+ method write(Str $path, Hash $config --> Bool)
{
Config::Exception::UnimplementedMethodException.new(
method => "write"
diff --git a/lib/Config/Parser/NULL.pm6 b/lib/Config/Parser/NULL.pm6
new file mode 100644
index 0000000..ff384b1
--- /dev/null
+++ b/lib/Config/Parser/NULL.pm6
@@ -0,0 +1,31 @@
+#! /usr/bin/env false
+
+use v6.c;
+
+use Config::Parser;
+
+#| The Config::Parser::NULL is a parser to mock with for testing purposes.
+#| It exposes an additional method, set-config, so you can set a config
+#| Hash to return when calling `read`.
+class Config::Parser::NULL is Config::Parser
+{
+ my $mock-config;
+
+ #| Return the mock config, skipping the file entirely.
+ method read(Str $path --> Hash)
+ {
+ $mock-config;
+ }
+
+ #| Set the mock config to return on read.
+ method set-config(Hash $config)
+ {
+ $mock-config = $config;
+ }
+
+ #| Return True, as if writing succeeded.
+ method write(Str $path, Hash $config --> Bool)
+ {
+ True;
+ }
+}