#!/usr/bin/env perl

use 5.16.0;
use warnings;
use Zonemaster::Engine;
use File::Basename;

# page header
print '<!-- File generated by ', basename ($0), ", script in zonemaster/zonemaster util directory.\n";
print "Use that script to generate a new file for each release of Zonemaster when \n";
print "Zonemaster-Engine also has been updated.-->\n\n";
print "# Mapping test messages to Test Cases\n\n";
print "Index of Text Cases are found in [README](README.md).\n\n";

# table header
print "| Message tag from [Zonemaster-Engine] | Module | Method (implemented test case) |\n";
print "|:-------------------------------------|:-------|:-------------------------------|\n";

# table content
foreach my $module ( sort { fc $a cmp fc $b } Zonemaster::Engine::Test->modules ) {
    my $full = "Zonemaster::Engine::Test::$module";
    my $ref  = $full->metadata;
    for my $key (sort keys %$ref) {
        my $list = $ref->{$key};
        for my $tag (sort { $a cmp $b } @$list) {
            my $testlevel = "${module}-TP";
	    my $testlevellink = "$module-TP/README.md";
            my $testcasefile = "$key.md";
            my $testcaselink = "$testlevel/$testcasefile";
            printf "| %-40s | [%s](%s) | [%s](%s) |\n", $tag, $module, $testlevellink, $key, $testcaselink;
        }
    }
}

print "\n[Zonemaster-Engine]: https://github.com/zonemaster/zonemaster-engine\n";

