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