App-FuguWeb
view release on metacpan or search on metacpan
t/fuguweb/config.t view on Meta::CPAN
is( $config->lang, 'sv', 'lang' );
is( $config->out_dir, 'out', 'out_dir' );
is( $config->source_dir, 'site', 'source_dir' );
is( $config->entry, 'home.html', 'entry' );
is( $config->module_root, 'code', 'module_root' );
is( $config->mandoc_os, 'Example OS', 'mandoc_os' );
is( $config->man_url, 'https://man.example.org/', 'man_url' );
is( $config->stylesheet, 'site/base.css', 'stylesheet' );
};
subtest 'root, path and source_path' => sub {
my ( $config, $reason, $root ) = load_rc("site = Example\n");
ok( $config, 'the description loads' ) or diag $reason;
is( $config->root, $root, 'root' );
is( $config->path, "$root/.fuguwebrc", 'path' );
is( $config->source_path, "$root/web", 'the source directory' );
is( $config->source_path('footer.body.html'),
"$root/web/footer.body.html",
'one file in the source directory' );
};
subtest 'the inventory holds the whole site, once' => sub {
my $root = write_rc( <<'RC' );
site = Example
page "index.html" {
title = Home
body = index.body.html
}
page "manuals.html" {
title = Manuals
index = yes
}
manuals "Manuals" {
dir = man
anchor = manuals
}
RC
mkdir "$root/man" or die "Cannot create the directory: $!";
mkdir "$root/web" or die "Cannot create the directory: $!";
for my $pair (
[ 'man/tool.1' => ".Sh NAME\n.Nd a tool\n" ],
[ 'web/index.body.html' => "<h1>Home</h1>\n" ],
[ 'web/robots.txt' => "User-agent: *\n" ] )
{
open my $fh, '>', "$root/$pair->[0]"
or die "Cannot write $pair->[0]: $!";
print {$fh} $pair->[1];
close $fh;
}
my $config =
App::FuguWeb::Config->load( root => $root, error => \my $reason );
ok( $config, 'the description loads' ) or diag $reason;
# The pages, one page per manual, the stylesheet, and the
# assets. The body fragment is a source and never an asset.
is_deeply(
[ $config->inventory ],
[ qw(index.html manuals.html tool.1.html style.css
robots.txt) ],
'every name the output must hold, and nothing else'
);
};
subtest 'the navigation keeps its file order' => sub {
my ( $config, $reason ) = load_rc( <<'RC' );
site = Example
nav "index.html" {
label = Home
}
nav "https://example.org/" {
label = Elsewhere
}
RC
ok( $config, 'the description loads' ) or diag $reason;
my @nav = $config->nav;
is( scalar @nav, 2, 'two entries' );
is( $nav[0]{href}, 'index.html', 'the first href' );
is( $nav[0]{label}, 'Home', 'the first label' );
is( $nav[1]{href}, 'https://example.org/', 'the second href' );
is( $nav[1]{label}, 'Elsewhere', 'the second label' );
};
subtest 'the pages keep their file order and their source' => sub {
my ( $config, $reason ) = load_rc( <<'RC' );
site = Example
page "index.html" {
title = Home
body = index.body.html
}
page "install.html" {
title = Install
markdown = INSTALL.md
}
page "manuals.html" {
title = Manuals
index = yes
}
page "404.html" {
body = 404.body.html
unlinked = yes
}
RC
ok( $config, 'the description loads' ) or diag $reason;
my @pages = $config->pages;
is( scalar @pages, 4, 'four pages' );
is( $pages[0]{file}, 'index.html', 'the first file' );
is( $pages[0]{title}, 'Home', 'the first title' );
is( $pages[0]{source}, 'body', 'a body source' );
is( $pages[0]{value}, 'index.body.html', 'the fragment' );
ok( !$pages[0]{unlinked}, 'the front page is linked' );
is( $pages[1]{source}, 'markdown', 'a markdown source' );
is( $pages[1]{value}, 'INSTALL.md', 'the markdown file' );
is( $pages[2]{source}, 'index', 'an index source' );
is( $pages[2]{value}, undef, 'the index names no file' );
is( $pages[3]{title}, '404.html',
'a page with no title takes its file name' );
ok( $pages[3]{unlinked}, 'unlinked = yes' );
};
subtest 'a page block names exactly one source' => sub {
my ( $config, $reason ) = load_rc( <<'RC' );
site = Example
page "index.html" {
body = index.body.html
markdown = README.md
}
RC
is( $config, undef, 'two sources fail the load' );
like( $reason, qr/page "index\.html" names body and markdown/,
'the message names the block and both sources' );
( $config, $reason ) = load_rc( <<'RC' );
site = Example
page "index.html" {
title = Home
}
RC
is( $config, undef, 'no source fails the load' );
like( $reason, qr/page "index\.html" names no source/,
'the message names the block' );
};
subtest 'a page file belongs to one block' => sub {
my ( $config, $reason ) = load_rc( <<'RC' );
site = Example
page "index.html" {
body = index.body.html
}
page "index.html" {
body = other.body.html
}
RC
is( $config, undef, 'a page declared twice fails the load' );
like( $reason, qr/page "index\.html" is declared twice/,
'the message names the page' );
};
subtest 'a nav block needs a label' => sub {
my ( $config, $reason ) = load_rc( <<'RC' );
site = Example
nav "index.html" {
( run in 0.867 second using v1.01-cache-2.11-cpan-364913b4093 )