use strict; use warnings; use Test::More; # Ensure the main script can be loaded require 'foostats.pl'; ok(1, 'loaded foostats.pl'); # Test truncate_url subtest 'truncate_url' => sub { is(Foostats::Reporter::truncate_url('http://example.com', 20), 'http://example.com', 'URL shorter than max length'); is(Foostats::Reporter::truncate_url('http://example.com/a/very/long/path', 20), 'http:/...y/long/path', 'URL longer than max length'); is(Foostats::Reporter::truncate_url('12345678901234567890', 20), '12345678901234567890', 'URL equal to max length'); is(Foostats::Reporter::truncate_url('http://example.com/a/very/long/path', 30), 'http://exa.../a/very/long/path', 'URL with custom max length'); }; subtest 'format_table' => sub { my $headers = ['Name', 'Value']; my $rows = [ ['foo', '123'], ['bar', '45'], ]; my $expected = <<'TABLE'; |------|-------| | Name | Value | |------|-------| | foo | 123 | | bar | 45 | |------|-------| TABLE chomp $expected; my $got = Foostats::Reporter::format_table($headers, $rows); is($got, $expected, 'format_table output is correct'); }; subtest 'gemtext_to_html headings' => sub { my $gemtext = "# Title\n## Subtitle\n### Sub-subtitle"; my $expected = "
\nmy \$code = 1;\n\n"; my $html = Foostats::Reporter::gemtext_to_html($gemtext); is($html, $expected, 'Code blocks are converted correctly'); }; subtest 'gemtext_to_html ascii tables' => sub { my $gemtext = "```\n| a | b |\n|---|---|\n| 1 | 2 |\n```"; my $expected = "
| a | \nb | \n
|---|---|
| 1 | \n2 | \n