1#============================================================= -*-perl-*-
2#
3# t/data/text.t
4#
5# Test the Badger::Data::Type::Text module.
6#
7# Written by Andy Wardley <abw@wardley.org>
8#
9# This is free software; you can redistribute it and/or modify it
10# under the same terms as Perl itself.
11#
12#========================================================================
13
14use lib qw( ./lib ../lib ../../lib );
15
16use Badger::Test
17    debug  => 'Badger::Data::Type::Text',
18    args   => \@ARGV,
19    tests  => 8;
20
21use Badger::Debug ':debug :dump';
22use constant
23    TEXT => 'Badger::Data::Type::Text';
24
25use Badger::Data::Type::Text;
26pass('loaded Badger::Data::Type::Text');
27
28my $Text = TEXT->new;
29ok( $Text, 'created text' );
30
31my $facets = $Text->facets;
32ok( $facets, 'fetched facets' );
33
34#main->debug("facets: ", main->dump_data($facets));
35
36my $type = TEXT->new(
37    facets => [
38        min_length => 3,
39        max_length => 6,
40    ]
41);
42
43my $good  = 'hello';
44my $short = 'hi';
45my $long  = 'greetings';
46
47ok( $type->validate(\$good), 'good string is good' );
48
49ok( ! $type->try->validate(\$short), 'short string is not good' );
50is( $type->reason->info,
51    'Text should be at least 3 characters long (got 2)',
52    'short string is too short'
53);
54
55ok( ! $type->try->validate(\$long), 'long string is not good' );
56is( $type->reason->info,
57    'Text should be at most 6 characters long (got 9)',
58    'long string is too long'
59);
60
61