2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # FIXME: some is probably redundant with more round-trip PSGI tests
6 # nowadays with run_script and TEST_RUN_MODE=2 spawn-avoidance speedups
9 use PublicInbox::TestCommon;
10 require_mods(qw(DBD::SQLite Xapian));
11 require PublicInbox::SearchIdx;
12 require PublicInbox::Inbox;
13 require PublicInbox::InboxWritable;
15 use POSIX qw(strftime);
16 my ($tmpdir, $for_destroy) = tmpdir();
17 my $git_dir = "$tmpdir/a.git";
18 my $ibx = PublicInbox::Inbox->new({ inboxdir => $git_dir });
19 my ($root_id, $last_id);
21 is(0, xsys(qw(git init --shared -q --bare), $git_dir), "git init (main)")
22 or BAIL_OUT("`git init --shared' failed, weird FS or seccomp?");
23 eval { PublicInbox::Search->new($ibx)->xdb };
24 ok($@, "exception raised on non-existent DB");
26 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
27 $ibx->with_umask(sub {
33 $rw->commit_txn_lazy if $rw;
34 $rw = PublicInbox::SearchIdx->new($ibx, 1);
35 $rw->{qp_flags} = 0; # quiet a warning
41 # git repository perms
42 use_ok 'PublicInbox::Umask';
43 oct_is($ibx->_git_config_perm(),
44 PublicInbox::Umask::PERM_GROUP(),
45 'undefined permission is group');
47 [ '0644', 0022, '644 => umask(0022)' ],
48 [ '0600', 0077, '600 => umask(0077)' ],
49 [ '0640', 0027, '640 => umask(0027)' ],
50 [ 'group', 0007, 'group => umask(0007)' ],
51 [ 'everybody', 0002, 'everybody => umask(0002)' ],
52 [ 'umask', umask, 'umask => existing umask' ],
55 my ($perm, $exp, $msg) = @$_;
56 my $got = PublicInbox::Umask::_umask_for(
57 PublicInbox::Umask->_git_config_perm($perm));
58 oct_is($got, $exp, $msg);
63 my $crlf_adjust = \&PublicInbox::Smsg::crlf_adjust;
64 is($crlf_adjust->("hi\r\nworld\r\n"), 0, 'no adjustment needed');
65 is($crlf_adjust->("hi\nworld\n"), 2, 'LF-only counts two CR');
66 is($crlf_adjust->("hi\r\nworld\n"), 1, 'CRLF/LF-mix 1 counts 1 CR');
67 is($crlf_adjust->("hi\nworld\r\n"), 1, 'CRLF/LF-mix 2 counts 1 CR');
70 $ibx->with_umask(sub {
71 my $root = PublicInbox::Eml->new(<<'EOF');
72 Date: Fri, 02 Oct 1993 00:00:00 +0000
75 From: John Smith <js@example.com>
77 List-Id: I'm not mad <i.m.just.bored>
81 my $last = PublicInbox::Eml->new(<<'EOF');
82 Date: Sat, 02 Oct 2010 00:00:00 +0000
83 Subject: Re: Hello world
86 From: John Smith <js@example.com>
89 List-Id: there's nothing <left.for.me.to.do>
95 $root_id = $rw->add_message($root);
96 is($root_id, int($root_id), "root_id is an integer: $root_id");
97 $last_id = $rw->add_message($last);
98 is($last_id, int($last_id), "last_id is an integer: $last_id");
103 sort(map { $_->{mid} } @$msgs);
107 my ($query_string, $opt) = @_;
108 my $mset = $ibx->search->mset($query_string, $opt);
109 $ibx->search->mset_to_smsg($ibx, $mset);
114 my $found = $query->('m:root@s');
115 is(scalar(@$found), 1, "message found");
116 is($found->[0]->{mid}, 'root@s', 'mid set correctly') if @$found;
119 my @exp = sort qw(root@s last@s);
121 $res = $query->('s:(Hello world)');
122 @res = filter_mids($res);
123 is_deeply(\@res, \@exp, 'got expected results for s:() match');
125 $res = $query->('s:"Hello world"');
126 @res = filter_mids($res);
127 is_deeply(\@res, \@exp, 'got expected results for s:"" match');
129 $res = $query->('s:"Hello world"', {limit => 1});
130 is(scalar @$res, 1, "limit works");
131 my $first = $res->[0];
133 $res = $query->('s:"Hello world"', {offset => 1});
134 is(scalar @$res, 1, "offset works");
135 my $second = $res->[0];
137 isnt($first, $second, "offset returned different result from limit");
141 $ibx->with_umask(sub {
143 my $rmid = '<ghost-message@s>';
144 my $reply_to_ghost = PublicInbox::Eml->new(<<"EOF");
145 Date: Sat, 02 Oct 2010 00:00:00 +0000
147 Message-ID: <ghost-reply\@s>
149 From: Time Traveler <tt\@example.com>
150 To: list\@example.com
155 my $reply_id = $rw->add_message($reply_to_ghost);
156 is($reply_id, int($reply_id), "reply_id is an integer: $reply_id");
158 my $was_ghost = PublicInbox::Eml->new(<<"EOF");
159 Date: Sat, 02 Oct 2010 00:00:01 +0000
162 From: Laggy Sender <lag\@example.com>
163 To: list\@example.com
167 my $ghost_id = $rw->add_message($was_ghost);
168 is($ghost_id, int($ghost_id), "ghost_id is an integer: $ghost_id");
169 my $msgs = $rw->{oidx}->get_thread('ghost-message@s');
170 is(scalar(@$msgs), 2, 'got both messages in ghost thread');
171 foreach (qw(sid tid)) {
172 is($msgs->[0]->{$_}, $msgs->[1]->{$_}, "{$_} match");
174 isnt($msgs->[0]->{num}, $msgs->[1]->{num}, "num do not match");
175 ok($_->{num} > 0, 'positive art num') foreach @$msgs
178 # search thread on ghost
183 my $res = $query->('ghost');
184 my @exp = sort qw(ghost-message@s ghost-reply@s);
185 my @res = filter_mids($res);
186 is_deeply(\@res, \@exp, 'got expected results for Subject match');
189 $res = $query->('goodbye');
190 is(scalar(@$res), 1, "goodbye message found");
191 is($res->[0]->{mid}, 'last@s', 'got goodbye message body') if @$res;
194 $res = $query->('dt:20101002000001..20101002000001');
195 @res = filter_mids($res);
196 is_deeply(\@res, ['ghost-message@s'], 'exact Date: match works');
197 $res = $query->('dt:20101002000002..20101002000002');
198 is_deeply($res, [], 'exact Date: match down to the second');
202 $ibx->with_umask(sub {
204 my $long_mid = 'last' . ('x' x 60). '@s';
205 my $long = PublicInbox::Eml->new(<<EOF);
206 Date: Sat, 02 Oct 2010 00:00:00 +0000
207 Subject: long message ID
208 References: <root\@s> <last\@s>
209 In-Reply-To: <last\@s>
210 Message-ID: <$long_mid>,
211 From: "Long I.D." <long-id\@example.com>
212 To: list\@example.com
216 my $long_id = $rw->add_message($long);
217 is($long_id, int($long_id), "long_id is an integer: $long_id");
223 my $long_reply_mid = 'reply-to-long@1';
224 my $long_reply = PublicInbox::Eml->new(<<EOF);
225 Subject: I break references
226 Date: Sat, 02 Oct 2010 00:00:00 +0000
227 Message-ID: <$long_reply_mid>
228 In-Reply-To: <$long_mid>
229 From: no1 <no1\@example.com>
230 To: list\@example.com
234 ok($rw->add_message($long_reply) > $long_id, "inserted long reply");
237 my $t = $ibx->over->get_thread('root@s');
238 is(scalar(@$t), 4, "got all 4 messages in thread");
239 my @exp = sort($long_reply_mid, 'root@s', 'last@s', $long_mid);
240 @res = filter_mids($t);
241 is_deeply(\@res, \@exp, "get_thread works");
244 # quote prioritization
245 $ibx->with_umask(sub {
247 $rw->add_message(PublicInbox::Eml->new(<<'EOF'));
248 Date: Sat, 02 Oct 2010 00:00:01 +0000
250 Message-ID: <quote@a>
251 From: Quoter <quoter@example.com>
257 $rw->add_message(PublicInbox::Eml->new(<<'EOF'));
258 Date: Sat, 02 Oct 2010 00:00:02 +0000
260 Message-ID: <nquote@a>
261 From: Non-Quoter<non-quoter@example.com>
268 my $res = $query->("theatre");
269 is(scalar(@$res), 2, "got both matches");
271 is($res->[0]->{mid}, 'nquote@a', 'non-quoted scores higher');
272 is($res->[1]->{mid}, 'quote@a', 'quoted result still returned');
274 $res = $query->("illusions");
275 is(scalar(@$res), 1, "got a match for quoted text");
276 is($res->[0]->{mid}, 'quote@a',
277 "quoted result returned if nothing else") if scalar(@$res);
280 # circular references
281 $ibx->with_umask(sub {
282 my $s = 'foo://'. ('Circle' x 15).'/foo';
283 my $doc_id = $rw->add_message(PublicInbox::Eml->new(<<EOF));
285 Date: Sat, 02 Oct 2010 00:00:01 +0000
286 Message-ID: <circle\@a>
287 References: <circle\@a>
288 In-Reply-To: <circle\@a>
289 From: Circle <circle\@example.com>
290 To: list\@example.com
294 ok($doc_id > 0, "doc_id defined with circular reference");
296 my $smsg = $query->('m:circle@a', {limit=>1})->[0];
297 is(defined($smsg), 1, 'found m:circl@a');
299 is($smsg->{references}, '', "no references created");
300 is($smsg->{subject}, $s, 'long subject not rewritten');
305 my $msgs = $query->('d:19931002..20101002');
306 ok(scalar(@$msgs) > 0, 'got results within range');
307 $msgs = $query->('d:20101003..');
308 is(scalar(@$msgs), 0, 'nothing after 20101003');
309 $msgs = $query->('d:..19931001');
310 is(scalar(@$msgs), 0, 'nothing before 19931001');
313 $ibx->with_umask(sub {
314 my $mime = eml_load 't/utf8.eml';
315 my $doc_id = $rw->add_message($mime);
316 ok($doc_id > 0, 'message indexed doc_id with UTF-8');
318 my $msg = $query->('m:testmessage@example.com', {limit => 1})->[0];
319 is(defined($msg), 1, 'found testmessage@example.com');
321 is($mime->header('Subject'), $msg->{subject},
322 'UTF-8 subject preserved');
326 # names and addresses
328 my $mset = $ibx->search->mset('t:list@example.com');
329 is($mset->size, 9, 'searched To: successfully');
330 foreach my $m ($mset->items) {
331 my $smsg = $ibx->over->get_art($m->get_docid);
332 like($smsg->{to}, qr/\blist\@example\.com\b/, 'to appears');
333 my $doc = $m->get_document;
334 my $col = PublicInbox::Search::BYTES();
335 my $bytes = PublicInbox::Search::int_val($doc, $col);
336 like($bytes, qr/\A[0-9]+\z/, '$bytes stored as digit');
337 ok($bytes > 0, '$bytes is > 0');
338 is($bytes, $smsg->{bytes}, 'bytes Xapian value matches Over');
340 $col = PublicInbox::Search::UID();
341 my $uid = PublicInbox::Search::int_val($doc, $col);
342 is($uid, $smsg->{num}, 'UID column matches {num}');
343 is($uid, $m->get_docid, 'UID column matches docid');
346 $mset = $ibx->search->mset('tc:list@example.com');
347 is($mset->size, 9, 'searched To+Cc: successfully');
348 foreach my $m ($mset->items) {
349 my $smsg = $ibx->over->get_art($m->get_docid);
350 my $tocc = join("\n", $smsg->{to}, $smsg->{cc});
351 like($tocc, qr/\blist\@example\.com\b/, 'tocc appears');
354 foreach my $pfx ('tcf:', 'c:') {
355 my $mset = $ibx->search->mset($pfx . 'foo@example.com');
356 is($mset->items, 1, "searched $pfx successfully for Cc:");
357 foreach my $m ($mset->items) {
358 my $smsg = $ibx->over->get_art($m->get_docid);
359 like($smsg->{cc}, qr/\bfoo\@example\.com\b/,
364 foreach my $pfx ('', 'tcf:', 'f:') {
365 my $res = $query->($pfx . 'Laggy');
367 "searched $pfx successfully for From:");
368 foreach my $smsg (@$res) {
369 like($smsg->{from_name}, qr/Laggy Sender/,
370 "From appears with $pfx");
377 my $res = $query->('b:hello');
378 is(scalar(@$res), 0, 'no match on body search only');
379 $res = $query->('bs:smith');
381 'no match on body+subject search for From');
383 $res = $query->('q:theatre');
384 is(scalar(@$res), 1, 'only one quoted body');
385 like($res->[0]->{from_name}, qr/\AQuoter/,
386 'got quoted body') if (scalar(@$res));
388 $res = $query->('nq:theatre');
389 is(scalar @$res, 1, 'only one non-quoted body');
390 like($res->[0]->{from_name}, qr/\ANon-Quoter/,
391 'got non-quoted body') if (scalar(@$res));
393 foreach my $pfx (qw(b: bs:)) {
394 $res = $query->($pfx . 'theatre');
395 is(scalar @$res, 2, "searched both bodies for $pfx");
396 like($res->[0]->{from_name}, qr/\ANon-Quoter/,
397 "non-quoter first for $pfx") if scalar(@$res);
401 $ibx->with_umask(sub {
402 my $amsg = eml_load 't/search-amsg.eml';
404 my $smsg = bless { blob => $oid }, 'PublicInbox::Smsg';
405 ok($rw->add_message($amsg, $smsg), 'added attachment');
407 my $n = $query->('n:attached_fart.txt');
408 is(scalar @$n, 1, 'got result for n:');
409 my $res = $query->('part_deux.txt');
410 is(scalar @$res, 1, 'got result without n:');
411 is($n->[0]->{mid}, $res->[0]->{mid},
412 'same result with and without') if scalar(@$res);
413 my $txt = $query->('"inside another"');
414 is(scalar @$txt, 1, 'found inside another');
415 is($txt->[0]->{mid}, $res->[0]->{mid},
416 'search inside text attachments works') if scalar(@$txt);
419 if (scalar(@$n) >= 1) {
420 my $mid = $n->[0]->{mid};
422 $art = $ibx->over->next_by_mid($mid, \$id, \$prev);
423 ok($art, 'article exists in OVER DB');
426 $rw->v1_unindex_eml($oid, $amsg);
427 $rw->commit_txn_lazy;
429 skip('$art not defined', 1) unless defined $art;
430 is($ibx->over->get_art($art->{num}), undef,
431 'gone from OVER DB');
435 my $all_mask = 07777;
436 my $dir_mask = 02770;
438 # FreeBSD, OpenBSD and NetBSD do not allow non-root users to set S_ISGID,
439 # so git doesn't set it, either (see DIR_HAS_BSD_GROUP_SEMANTICS in git.git)
440 # Presumably all *BSDs behave the same way.
446 foreach my $f ("$git_dir/public-inbox/msgmap.sqlite3",
447 "$git_dir/public-inbox",
448 glob("$git_dir/public-inbox/xapian*/"),
449 glob("$git_dir/public-inbox/xapian*/*")) {
451 my ($bn) = (split(m!/!, $f))[-1];
452 oct_is($st[2] & $all_mask, -f _ ? 0660 : $dir_mask,
453 "sharedRepository respected for $bn");
456 $ibx->with_umask(sub {
458 my $digits = '10010260936330';
459 my $ua = 'Pine.LNX.4.10';
460 my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
461 is($ibx->search->mset("m:$digits")->size, 0, 'no results yet');
462 my $pine = PublicInbox::Eml->new(<<EOF);
465 From: torvalds\@transmeta
466 To: list\@example.com
469 my $x = $rw->add_message($pine);
470 $rw->commit_txn_lazy;
471 $ibx->search->reopen;
472 is($ibx->search->mset("m:$digits")->size, 1,
473 'searching only digit yielded result');
478 is($ibx->search->mset("m:$wild*")->size, 1,
479 "searching chopped($i) digit yielded result $wild ");
481 is($ibx->search->mset('m:Pine m:LNX m:10010260936330')->size, 1);
484 { # List-Id searching
485 my $found = $query->('lid:i.m.just.bored');
486 is_deeply([ filter_mids($found) ], [ 'root@s' ],
487 'got expected mid on exact lid: search');
489 $found = $query->('lid:just.bored');
490 is_deeply($found, [], 'got nothing on lid: search');
492 $found = $query->('lid:*.just.bored');
493 is_deeply($found, [], 'got nothing on lid: search');
495 $found = $query->('l:i.m.just.bored');
496 is_deeply([ filter_mids($found) ], [ 'root@s' ],
497 'probabilistic search works on full List-Id contents');
499 $found = $query->('l:just.bored');
500 is_deeply([ filter_mids($found) ], [ 'root@s' ],
501 'probabilistic search works on partial List-Id contents');
503 $found = $query->('lid:mad');
504 is_deeply($found, [], 'no match on phrase with lid:');
506 $found = $query->('lid:bored');
507 is_deeply($found, [], 'no match on partial List-Id with lid:');
509 $found = $query->('l:nothing');
510 is_deeply($found, [], 'matched on phrase with l:');
513 $ibx->with_umask(sub {
515 my $doc_id = $rw->add_message(eml_load('t/data/message_embed.eml'));
516 ok($doc_id > 0, 'messages within messages');
517 $rw->commit_txn_lazy;
518 $ibx->search->reopen;
519 my $n_test_eml = $query->('n:test.eml');
520 is(scalar(@$n_test_eml), 1, 'got a result');
521 my $n_embed2x_eml = $query->('n:embed2x.eml');
522 is_deeply($n_test_eml, $n_embed2x_eml, '.eml filenames searchable');
523 for my $m (qw(20200418222508.GA13918@dcvr 20200418222020.GA2745@dcvr
524 20200418214114.7575-1-e@yhbt.net)) {
525 is($query->("m:$m")->[0]->{mid},
526 '20200418222508.GA13918@dcvr', 'probabilistic m:'.$m);
527 is($query->("mid:$m")->[0]->{mid},
528 '20200418222508.GA13918@dcvr', 'boolean mid:'.$m);
530 is($query->('dfpost:4dc62c50')->[0]->{mid},
531 '20200418222508.GA13918@dcvr',
532 'diff search reaches inside message/rfc822');
533 is($query->('s:"mail header experiments"')->[0]->{mid},
534 '20200418222508.GA13918@dcvr',
535 'Subject search reaches inside message/rfc822');
537 my $eml = eml_load('t/data/binary.patch');
538 my $body = $eml->body;
539 $rw->add_message($eml);
542 $eml = PublicInbox::Eml->new($eml->header_obj->as_string."\n".$body);
543 $eml->header_set('Message-ID', '<binary-patch-reply@example>');
544 $rw->add_message($eml);
546 $rw->commit_txn_lazy;
547 $ibx->search->reopen;
548 my $res = $query->('HcmV');
549 is_deeply($res, [], 'no results against trailer');
550 $res = $query->('IcmZPo000310RR91');
551 is_deeply($res, [], 'no results against 1-byte binary patch');
552 $res = $query->('"GIT binary patch"');
553 is(scalar(@$res), 2, 'got binary results from "GIT binary patch"');
554 is($res->[0]->{mid}, 'binary-patch-test@example', 'msgid for binary');
555 is($res->[1]->{mid}, 'binary-patch-reply@example', 'msgid for reply');
556 my $s = $query->('"literal 1"');
557 is_deeply($s, $res, 'got binary result from exact literal size');
558 $s = $query->('"literal 2"');
559 is_deeply($s, [], 'no results for wrong size');
563 my ($s, $g) = ($ibx->search, $ibx->git);
564 my $q = $s->query_argv_to_string($g, ["quoted phrase"]);
565 is($q, q["quoted phrase"], 'quoted phrase');
566 $q = $s->query_argv_to_string($g, ['s:pa ce']);
567 is($q, q[s:"pa ce"], 'space with prefix');
568 $q = $s->query_argv_to_string($g, ["\(s:pa ce", "AND", "foo\)"]);
569 is($q, q[(s:"pa ce" AND foo)], 'space AND foo');
571 local $ENV{TZ} = 'UTC';
572 my $now = strftime('%H:%M:%S', gmtime(time));
573 if ($now =~ /\A23:(?:59|60)/ || $now =~ /\A00:00:0[01]\z/) {
574 skip 'too close to midnight, time is tricky', 6;
576 $q = $s->query_argv_to_string($g, [qw(d:20101002 blah)]);
577 is($q, 'dt:20101002000000..20101003000000 blah',
578 'YYYYMMDD expanded to range');
579 $q = $s->query_argv_to_string($g, [qw(d:2010-10-02)]);
580 is($q, 'dt:20101002000000..20101003000000',
581 'YYYY-MM-DD expanded to range');
582 $q = $s->query_argv_to_string($g, [qw(rt:2010-10-02.. yy)]);
584 $q =~ /\Art:(\d+)\.\. yy/ or fail("rt: expansion failed: $q");
585 is(strftime('%Y-%m-%d', gmtime($1//0)), '2010-10-02', 'rt: beg expand');
586 $q = $s->query_argv_to_string($g, [qw(rt:..2010-10-02 zz)]);
587 $q =~ /\Art:\.\.(\d+) zz/ or fail("rt: expansion failed: $q");
588 is(strftime('%Y-%m-%d', gmtime($1//0)), '2010-10-02', 'rt: end expand');
589 $q = $s->query_argv_to_string($g, [qw(something dt:2010-10-02..)]);
590 like($q, qr/\Asomething dt:20101002\d{6}\.\./, 'dt: expansion');
591 $q = $s->query_argv_to_string($g, [qw(x dt:yesterday.. y)]);
592 my $exp = strftime('%Y%m%d', gmtime(time - 86400));
593 like($q, qr/x dt:$exp[0-9]{6}\.\. y/, '"yesterday" handled');
594 $q = $s->query_argv_to_string($g, [qw(x dt:20101002054123)]);
595 is($q, 'x dt:20101002054123..20101003054123', 'single dt: expanded');
596 $q = $s->query_argv_to_string($g, [qw(x dt:2010-10-02T05:41:23Z)]);
597 is($q, 'x dt:20101002054123..20101003054123', 'ISO8601 dt: expanded');
598 $q = $s->query_argv_to_string($g, [qw(rt:1970..1971)]);
599 $q =~ /\Art:(\d+)\.\.(\d+)\z/ or fail "YYYY rt: expansion: $q";
600 my ($beg, $end) = ($1, $2);
601 is(strftime('%Y', gmtime($beg)), 1970, 'rt: starts at 1970');
602 is(strftime('%Y', gmtime($end)), 1971, 'rt: ends at 1971');
603 $q = $s->query_argv_to_string($g, [qw(rt:1970-01-01)]);
604 $q =~ /\Art:(\d+)\.\.(\d+)\z/ or fail "YYYY-MM-DD rt: expansion: $q";
605 ($beg, $end) = ($1, $2);
606 is(strftime('%Y-%m-%d', gmtime($beg)), '1970-01-01',
607 'rt: date-only w/o range');
608 is(strftime('%Y-%m-%d', gmtime($end)), '1970-01-02',
609 'rt: date-only auto-end');
610 $q = $s->query_argv_to_string($g, [qw{OR (rt:1993-10-02)}]);
611 like($q, qr/\AOR \(rt:749\d{6}\.\.749\d{6}\)\z/,
612 'trailing parentheses preserved');
614 my $qs = qq[f:bob rt:1993-10-02..2010-10-02];
615 $s->query_approxidate($g, $qs);
616 like($qs, qr/\Af:bob rt:749\d{6}\.\.128\d{7}\z/,
617 'no phrases, no problem');
619 my $orig = $qs = qq[f:bob "d:1993-10-02..2010-10-02"];
620 $s->query_approxidate($g, $qs);
621 is($qs, $orig, 'phrase preserved');
623 $orig = $qs = qq[f:bob "d:1993-10-02..2010-10-02 "] .
624 qq["dt:1993-10-02..2010-10-02 " \x{201c}];
625 $s->query_approxidate($g, $qs);
626 is($qs, $orig, 'phrase preserved even with escaped ""');
628 $orig = $qs = qq[f:bob "hello world" d:1993-10-02..2010-10-02];
629 $s->query_approxidate($g, $qs);
630 is($qs, qq[f:bob "hello world" dt:19931002000000..20101002000000],
631 'post-phrase date corrected');
633 # Xapian uses "" to escape " inside phrases, we don't explictly
634 # handle that, but are able to pass the result through unchanged
635 for my $pair (["\x{201c}", "\x{201d}"], ['"', '"']) {
636 my ($x, $y) = @$pair;
637 $orig = $qs = qq[${x}hello d:1993-10-02.."" world$y];
638 $s->query_approxidate($g, $qs);
639 is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y));
641 $s->query_approxidate($g, my $tmp = "$qs d:..2010-10-02");
642 is($tmp, "$orig dt:..20101002000000",
643 'two phrases did not throw off date parsing');
645 $orig = $qs = qq[${x}hello d:1993-10-02..$y$x world$y];
646 $s->query_approxidate($g, $qs);
647 is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y));
649 $s->query_approxidate($g, $tmp = "$qs d:..2010-10-02");
650 is($tmp, "$orig dt:..20101002000000",
651 'two phrases did not throw off date parsing');
654 my $x_days_ago = strftime('%Y%m%d', gmtime(time - (5 * 86400)));
655 $orig = $qs = qq[broken d:5.days.ago..];
656 $s->query_approxidate($g, $qs);
657 like($qs, qr/\Abroken dt:$x_days_ago[0-9]{6}\.\./,
658 'date.phrase.with.dots');
660 $orig = $qs = 'd:20101002..now';
661 $s->query_approxidate($g, $qs);
662 like($qs, qr/\Adt:20101002000000\.\.[0-9]{14}\z/,
663 'approxidate on range-end only');
665 $ENV{TEST_EXPENSIVE} or
666 skip 'TEST_EXPENSIVE not set for argv overflow check', 1;
668 local $SIG{__WARN__} = sub { push @w, @_ }; # for pure Perl version
669 my @fail = map { 'dt:1993-10-02..2010-10-02' } (1..(4096 * 32));
670 eval { $s->query_argv_to_string($g, \@fail) };
671 ok($@, 'exception raised');