Skip to content

Commit

Permalink
Update actual tests to use new stuff [#28]
Browse files Browse the repository at this point in the history
  • Loading branch information
genehack committed Apr 3, 2015
1 parent e27dbd7 commit 171e05f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
19 changes: 14 additions & 5 deletions t/file.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ use HiD::File;
use Test::More;
use Test::Routine::Util;

my( $fh , $input_file ) = tempfile( DIR => tempdir , SUFFIX => '.html' );
my $tmpdir = tempdir();
my( $fh , $input_file ) = tempfile( DIR => $tmpdir , SUFFIX => '.html' );
print $fh 'this is a regular file.';
close $fh;

my( $base ) = $input_file =~ m|^$tmpdir.(.+?).html$|;

run_tests(
"basic file test" ,
[ 'Test::HiD::Role::IsPublished' , 'Test::HiD::File' ] ,
{
expected_url => "$input_file" ,
subject => HiD::File->new({
expected_basename => $base ,
expected_dir => $tmpdir ,
expected_suffix => 'html' ,
expected_url => "$input_file" ,
subject => HiD::File->new({
dest_dir => tempdir() ,
input_filename => $input_file ,
}) ,
Expand All @@ -38,8 +44,11 @@ run_tests(
"nested file test" ,
[ 'Test::HiD::Role::IsPublished' , 'Test::HiD::File' ] ,
{
expected_url => "$nested_file" ,
subject => HiD::File->new({
expected_basename => 'nested' ,
expected_dir => "$dir/nest" ,
expected_suffix => 'html' ,
expected_url => "$nested_file" ,
subject => HiD::File->new({
dest_dir => tempdir ,
input_filename => $nested_file ,
}) ,
Expand Down
22 changes: 22 additions & 0 deletions t/page.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use Test::HiD::Util qw/ make_layout make_page /;
use Test::More;
use Test::Routine::Util;

my $tmp = tempdir();

# make layout
my $layouts = {
default => make_layout( content => 'PAGE: [% content %]' ),
Expand All @@ -22,10 +24,14 @@ my $layouts = {
my %tests = (
"basic page test" => {
converted_content_regexp => qr/this is some page content./,
expected_basename => 'input' ,
expected_dir => $tmp ,
expected_suffix => 'html' ,
expected_url => '/input.html' ,
output_regexp => qr/PAGE: this is some page content/ ,
rendered_content_regexp => qr/PAGE: this is some page content/ ,
subject => make_page(
dir => $tmp ,
file => 'input.html',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -38,10 +44,14 @@ EOF
},
"markdown conversion test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'markdown' ,
expected_dir => $tmp ,
expected_suffix => 'mkdn' ,
expected_url => '/markdown.html',
output_regexp => qr|PAGE: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: <h1>this should be h1</h1>| ,
subject => make_page(
dir => $tmp ,
file => 'markdown.mkdn' ,
layouts => $layouts ,
content => <<EOF,
Expand All @@ -54,10 +64,14 @@ EOF
},
"textile conversion test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'textile' ,
expected_dir => $tmp ,
expected_suffix => 'textile' ,
expected_url => '/textile.html' ,
output_regexp => qr|PAGE: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: <h1>this should be h1</h1>| ,
subject => make_page(
dir => $tmp ,
file => 'textile.textile',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -70,10 +84,14 @@ EOF
},
"permalink = pretty" => {
converted_content_regexp => qr/this is some pretty page content./,
expected_basename => 'pretty' ,
expected_dir => $tmp ,
expected_suffix => 'html' ,
expected_url => '/pretty/' ,
output_regexp => qr/PAGE: this is some pretty page content/ ,
rendered_content_regexp => qr/PAGE: this is some pretty page content/ ,
subject => make_page(
dir => $tmp ,
file => 'pretty.html',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -87,10 +105,14 @@ EOF
},
"permalink = constant" => {
converted_content_regexp => qr/this is some page content./,
expected_basename => 'perma' ,
expected_dir => $tmp ,
expected_suffix => 'html' ,
expected_url => '/permalink',
output_regexp => qr/PAGE: this is some page content/ ,
rendered_content_regexp => qr/PAGE: this is some page content/ ,
subject => make_page(
dir => $tmp ,
file => 'perma.html' ,
layouts => $layouts ,
content => <<EOF,
Expand Down
46 changes: 44 additions & 2 deletions t/post.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ use warnings;

use lib 't/lib';

use File::Temp qw/ tempdir tempfile /;
use HiD::Layout;
use HiD::Post;

use Path::Tiny;
use Template;

use Test::HiD::Util qw/ make_layout make_post /;
use Test::More;
use Test::Routine::Util;

# make layouts
# set up base stuff
my $dir = Path::Tiny->tempdir()->child( '_posts' )->stringify;
my $default = make_layout( content => 'PAGE: [% content %]' );
my $layouts = {
default => $default ,
Expand All @@ -32,13 +34,17 @@ EOF
my %tests = (
"basic post test" => {
converted_content_regexp => qr/this is some post content./,
expected_basename => 'test' ,
expected_categories => [],
expected_date => '2010-01-01',
expected_dir => $dir ,
expected_suffix => 'html' ,
expected_title => 'this is a post' ,
expected_url => '/2010/01/01/test.html',
output_regexp => qr/PAGE: POST: this is some post content/ ,
rendered_content_regexp => qr/PAGE: POST: this is some post content/ ,
subject => make_post(
dir => $dir ,
file => '2010-01-01-test.html' ,
layouts => $layouts ,
content => <<EOF,
Expand All @@ -53,13 +59,17 @@ EOF
},
"markdown post test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'markdown' ,
expected_categories => [ qw/ markdown / ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '/markdown/2010/10/10/markdown.html',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-markdown.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -74,13 +84,17 @@ EOF
},
"textile conversion test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'textile' ,
expected_categories => [] ,
expected_date => '2011-11-11',
expected_dir => $dir ,
expected_suffix => 'textile' ,
expected_title => 'textile post',
expected_url => '/2011/11/11/textile.html',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2011-11-11-textile.textile',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -94,13 +108,17 @@ EOF
},
"permalink = pretty" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'markdown2' ,
expected_categories => [ qw/ foo bar / ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '/foo/bar/2010/10/10/markdown2/',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-markdown2.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -116,13 +134,17 @@ EOF
},
"permalink = string" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'permalink-string' ,
expected_categories => [ ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => 'permalink/',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-permalink-string.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -137,13 +159,17 @@ EOF
},
"permalink = format string" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'permalink-format-string' ,
expected_categories => [ ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '2010-10-10-permalink',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-permalink-format-string.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -159,13 +185,17 @@ EOF
"excerpt" => {
converted_content_regexp => qr|<h1>this should be h1</h1>\s*<p>content</p>|,
converted_excerpt_regexp => qr|<h1>this should be h1</h1>.+read more|s,
expected_basename => 'excerpt' ,
expected_categories => [ ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a excerpt test',
expected_url => '2010-10-10-excerpt',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-excerpt.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -183,13 +213,17 @@ EOF
},
"metadata:date" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'metadata-date' ,
expected_categories => [ ] ,
expected_date => '2012-12-12 01:02:03' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '/2012/12/12/metadata-date/',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-metadata-date.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -205,13 +239,17 @@ EOF
},
"category post test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'markdown' ,
expected_categories => [ qw/ foo bar / ] ,
expected_date => '2010-10-10' ,
expected_dir => "$dir/foo/bar/_posts" ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '/foo/bar/2010/10/10/markdown.html',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => 'foo/bar/_posts/2010-10-10-markdown.markdown',
layouts => $layouts ,
content => <<EOF,
Expand All @@ -226,13 +264,17 @@ EOF
},
"yaml category post test" => {
converted_content_regexp => qr|<h1>this should be h1</h1>|,
expected_basename => 'markdown' ,
expected_categories => [ qw/ bar foo / ] ,
expected_date => '2010-10-10' ,
expected_dir => $dir ,
expected_suffix => 'markdown' ,
expected_title => 'this is a markdown post',
expected_url => '/bar/foo/2010/10/10/markdown.html',
output_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
rendered_content_regexp => qr|PAGE: POST: <h1>this should be h1</h1>| ,
subject => make_post(
dir => $dir ,
file => '2010-10-10-markdown.markdown',
layouts => $layouts ,
content => <<EOF,
Expand Down

0 comments on commit 171e05f

Please sign in to comment.