#! /usr/bin/perl #--------------------------------------------------------------------- # 10-find.t # Copyright 2012 Christopher J. Madsen # # Test the find_charset_in function #--------------------------------------------------------------------- use strict; use warnings; use Test::More 0.88; # done_testing use Scalar::Util 'blessed'; use IO::HTML 'find_charset_in'; plan tests => 23; sub test { my $charset = shift; my @data = shift; push @data, shift if ref $_[0]; # options for find_charset_in my $name = shift; local $Test::Builder::Level = $Test::Builder::Level + 1; is(scalar find_charset_in(@data), $charset, $name); } # end test #--------------------------------------------------------------------- test 'utf-8-strict' => <<''; test 'utf-8-strict' => <<''; test 'iso-8859-15' => <<''; test 'iso-8859-15' => <<''; test 'iso-8859-15' => <<''; test 'utf-8-strict' => <<''; test 'cp1252' => <<''; test undef, <<'', 'misspelled charset'; test 'utf-8-strict' => <<''; test 'cp1252' => <<''; Title test 'iso-8859-15' => <<''; Title test 'iso-8859-15' => <<''; Title test 'iso-8859-15' => <<''; Title test 'cp1252' => <<''; Title test undef, <<'', 'incomplete attribute'; --> test 'iso-8859-15' => <<'', 'strange comment'; --> test undef, <<'', 'inside comment'; test undef, <<'', 'wrong pragma'; Title test 'utf-8-strict', <<'', {need_pragma => 0}, 'need_pragma 0'; Title test 'iso-8859-15' => <<'', 'bogus encoding'; { my $encoding = find_charset_in('', { encoding => 1 }); ok(blessed($encoding), 'encoding is an object'); is(eval { $encoding->name }, 'utf-8-strict', 'encoding is UTF-8'); } done_testing;