Add more tests
[zeal.git] / t / Zeal.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 20;
6 BEGIN { use_ok('Zeal') };
7
8 note 'Working with t/ds/b.docset';
9 my $ds = Zeal::Docset->new('t/ds/b.docset');
10 is $ds->name, 'B', 'docset name is B';
11 is $ds->id, 'b', 'docset id is b';
12 is $ds->family, 'consonants', 'docset family is consonants';
13
14 my @results = $ds->query('buil%');
15 is @results, 2, 'query(buil%) returns two results';
16 my $doc = $ds->query('building');
17 is $doc->name, 'building', 'document name is building';
18 is $doc->type, 'Word', 'document type is Word';
19 like $doc->fetch, qr/^Dummy/, 'document HTML starts with "Dummy"';
20 is $doc->anchor, 'dummy_anchor', 'document anchor is dummy_anchor';
21
22 @results = sort {$a->name cmp $b->name} $ds->list;
23 is @results, 2, 'docset contains two documents';
24 is $results[0]->name, 'building', 'first result is "building"';
25
26 note 'Working with all docsets in t/ds/';
27 my $zeal = Zeal->new('t/ds/');
28 eval {
29 $zeal->query('family:term');
30 fail 'An exception was not thrown when searching for a nonexistent family';
31 1
32 } or like $@, qr/^No docsets/, 'An exception is thrown when searching for a nonexistent family';
33
34 my @sets = $zeal->sets;
35 is @sets, 3, '3 docsets loaded';
36 @results = $zeal->query('buil%');
37 is @results, 2, '2 documents begin with "buil"';
38 @results = $zeal->query('%t%');
39 is @results, 3, '3 documents contain letter t';
40 @results = $zeal->query('consonants:%t%');
41 is @results, 2, '2 documents from the consonants family contain letter t';
42 @results = $zeal->query('%t%', 'vowels');
43 is @results, 1, '1 document from the vowels family contain letter t';
44
45 note 'Working with t/ds/a.docset via Zeal and ->add';
46 $zeal = Zeal->new;
47 $zeal->add('t/ds/a.docset');
48 @sets = $zeal->sets;
49 is @sets, 1, '1 docset loaded';
50 like $sets[0]->get('abou%'), qr/word/, 'HTML for abou% contains the word "word"';
51
52 note 'Working with t/ds/a.docset via ZEAL_PATH';
53 $ENV{ZEAL_PATH} = 't/ds/a.docset';
54 $zeal = Zeal->new;
55 is $zeal->query('about')->name, 'about';
This page took 0.029142 seconds and 4 git commands to generate.