packing
|
1 |
use Test::More; |
2 |
use strict; |
|
3 |
use warnings; |
|
4 |
use utf8; |
|
5 |
use Encode qw/decode encode/; |
|
6 | ||
7 |
BEGIN { |
|
8 |
eval { require DBD::SQLite; 1 } |
|
9 |
or plan skip_all => 'DBD::SQLite required'; |
|
10 |
eval { DBD::SQLite->VERSION >= 1 } |
|
11 |
or plan skip_all => 'DBD::SQLite >= 1.00 required'; |
|
12 | ||
13 |
plan 'no_plan'; |
|
14 |
use_ok('DBIx::Custom'); |
|
15 |
} |
|
16 | ||
17 |
# Function for test name |
|
18 |
my $test; |
|
19 |
sub test { |
|
20 |
$test = shift; |
|
21 |
} |
|
22 | ||
23 |
# Constant varialbes for test |
|
24 |
my $CREATE_TABLE = { |
|
25 |
0 => 'create table table1 (key1 char(255), key2 char(255));', |
|
26 |
1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));', |
|
27 |
2 => 'create table table2 (key1 char(255), key3 char(255));' |
|
28 |
}; |
|
29 | ||
30 |
my $SELECT_TMPL = { |
|
31 |
0 => 'select * from table1;' |
|
32 |
}; |
|
33 | ||
34 |
my $DROP_TABLE = { |
|
35 |
0 => 'drop table table1' |
|
36 |
}; |
|
37 | ||
38 |
my $NEW_ARGS = { |
|
39 |
0 => {data_source => 'dbi:SQLite:dbname=:memory:'} |
|
40 |
}; |
|
41 | ||
42 |
# Variables for test |
|
43 |
my $dbi; |
|
44 |
my $decoded_str; |
|
45 |
my $encoded_str; |
|
46 |
my $array; |
|
47 | ||
48 |
use DBIx::Custom::Basic; |
|
49 | ||
50 |
test 'Filter'; |
|
51 |
$dbi = DBIx::Custom::Basic->new($NEW_ARGS->{0}); |
|
52 |
ok($dbi->filters->{default_bind_filter}, "$test : exists default_bind_filter"); |
|
53 |
ok($dbi->filters->{default_fetch_filter}, "$test : exists default_fetch_filter"); |
|
54 |
is($dbi->bind_filter, $dbi->filters->{default_bind_filter}, 'default bind filter'); |
|
55 |
is($dbi->fetch_filter, $dbi->filters->{default_fetch_filter}, 'default fetch filter'); |
|
56 | ||
57 |
$decoded_str = 'あ'; |
|
58 |
$encoded_str = $dbi->bind_filter->('', $decoded_str); |
|
59 |
is($encoded_str, encode('UTF-8', $decoded_str), 'encode utf8'); |
|
60 |
is($decoded_str, $dbi->fetch_filter->('', $encoded_str), "$test : fetch_filter"); |