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