1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use warnings; |
4 |
|
|
use Test; |
5 |
|
|
use FindBin q($Bin); |
6 |
wakaba |
1.2 |
BEGIN {plan tests => 5} |
7 |
wakaba |
1.1 |
use SuikaWiki::DB::FileSystem::YukiWikiDBNS; |
8 |
|
|
|
9 |
|
|
my $dir = $Bin.'/db.tmp'; |
10 |
|
|
mkdir $dir or die "$0: $dir: $!" unless -d $dir; |
11 |
|
|
|
12 |
wakaba |
1.2 |
sub filename ($;$) { |
13 |
|
|
my ($key, $suffix) = (shift, shift || '.txt'); |
14 |
|
|
$dir.'/'.join ('.ns/', map {s/(.)/sprintf '%02X', ord $1/ges;$_} @$key).$suffix; |
15 |
|
|
} |
16 |
|
|
|
17 |
wakaba |
1.1 |
my $db = new SuikaWiki::DB::FileSystem::YukiWikiDBNS |
18 |
|
|
directory => $dir, |
19 |
|
|
suffix => '.txt'; |
20 |
|
|
|
21 |
wakaba |
1.2 |
unshift @{$db->{event}->{error}}, sub { |
22 |
|
|
my ($self, $event) = @_; |
23 |
|
|
unless ({qw/fatal 1 stop 1 warn 1/}->{$event->{error}->{-def}->{level}}) { |
24 |
|
|
warn "DEBUG: ". $event->{error}->stringify; |
25 |
|
|
} |
26 |
|
|
} if $^W; |
27 |
|
|
|
28 |
wakaba |
1.1 |
$db->set (test => ['Key'] => 'Value'); |
29 |
|
|
|
30 |
|
|
ok $db->get (test => ['Key']), 'Value'; |
31 |
|
|
ok $db->get (test => ['other']), undef; |
32 |
|
|
|
33 |
|
|
$db->set (test => ['Key', 'Sub'] => 'SubValue'); |
34 |
|
|
ok $db->get (test => ['Key', 'Sub']), 'SubValue'; |
35 |
|
|
|
36 |
|
|
$db->close; |
37 |
|
|
|
38 |
|
|
undef $db; |
39 |
|
|
|
40 |
|
|
my $file = filename (['Key']); |
41 |
|
|
ok -e $file, 1, 'Value is written on disk'; |
42 |
|
|
unlink $file or warn "$0: $file: $!"; |
43 |
|
|
|
44 |
|
|
$file = filename (['Key', 'Sub']); |
45 |
|
|
ok -e $file, 1, 'Namespaced value is written on disk'; |
46 |
|
|
unlink $file or warn "$0: $file: $!"; |
47 |
|
|
|
48 |
|
|
$file = filename (['Key'], '.ns'); |
49 |
|
|
rmdir $file or warn "$0: $file: $!"; |
50 |
|
|
|