From b366ef7066f63df2e19bd93e34de202f34a1c282 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 27 Apr 2017 14:53:13 +0200 Subject: Initial commit --- t/01-read.t | 33 +++++++++++++++++++++++++++++++++ t/02-write.t | 34 ++++++++++++++++++++++++++++++++++ t/files/config.toml | 3 +++ t/files/merge.toml | 5 +++++ t/files/write.toml | 6 ++++++ 5 files changed, 81 insertions(+) create mode 100644 t/01-read.t create mode 100644 t/02-write.t create mode 100644 t/files/config.toml create mode 100644 t/files/merge.toml create mode 100644 t/files/write.toml (limited to 't') 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 -- cgit v1.1