use v6.d;

use Test;
use Test::Run:auth<zef:CIAvash> :runs_ok;
use Test::Differences:auth<zef:rbt>;

plan 8;

my IO::Path:D $test_dir          = $?FILE.IO.parent;
my IO::Path:D $module            = $test_dir.parent;
my IO::Path:D $script            = $module.add:   'bin', 'sway-config';
my IO::Path:D $config_dir        = $test_dir.add: 'data';
my IO::Path:D $expected_data_dir = $test_dir.add: 'expected_data';

my @args = «"$*EXECUTABLE" -I "$module" "$script"»;

runs_ok :args«@args[] -v», :out(/'sway-config v' [\d+ %% '.'] ** 3 .+/), 'Prints version';

runs_ok :args«@args[] configs -i», :in('exec raku'), :out("[\n  \"exec raku\"\n]\n"), 'Prints config using STDIN';

@args.append: «-c $config_dir.add('config')»;

for <match configs variable mode key_binding all> {
    my Str:D $expected_data = $expected_data_dir.add("$_.json").slurp;

    runs_ok :args«@args[] $_», :out($expected_data), "Prints $_ correctly", :test_stdout(&eq_or_diff);
}
