#!perl -T

use strict;
use warnings;

use Test::More tests => 3;
use WWW::BashOrg;

my $b = WWW::BashOrg->new;
isa_ok($b, 'WWW::BashOrg');

my $q = $b->get_quote(443);

# The bash-org-archive.com HTML indents each quote line and leaves
# trailing whitespace inside the <p class="qt"> element, so compare
# on whitespace-normalised text to verify we fetched the real quote.
my $expected = "<VicViper> dorm = jail cell with internet\n"
    . "<SYch0> w/ fast internet";

my $normalise = sub {
    my $s = shift;
    return $s unless defined $s;
    $s =~ s/\r\n/\n/g;      # CRLF -> LF
    $s =~ s/[^\S\n]+\n/\n/g; # trailing horizontal space on each line
    $s =~ s/\n[^\S\n]+/\n/g; # leading horizontal space on each line
    $s =~ s/^\s+//;          # leading whitespace
    $s =~ s/\s+$//;          # trailing whitespace
    return $s;
};

SKIP:{
    if ( $b->error and $b->error =~ /^Network/ ) {
        skip 'Got network error: ' . $b->error, 2;
    }

    is( $normalise->($q), $expected, 'Got an expected quote' );
    is( $normalise->("$b"), $expected,
        'Got an expected quote (interpolating object)' );
}
