Repository navigation
Expand file tree
/
Copy pathtest_search.cpp
More file actions
2988 lines (2531 loc) · 140 KB
/
Copy pathtest_search.cpp
File metadata and controls
2988 lines (2531 loc) · 140 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of the Diffractor photo and video organizer
// Copyright 2026 Zac Walker
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Purpose: Search query tests. Verifies search parsing, term matching, date matching,
// selectors, file selection, related results, search navigation and prediction.
#include "pch.h"
#include "test_fixtures.h"
#include "model_postings.h"
#include "model_tokenizer.h"
#include "app_match.h"
// Path syntax is the vehicle in most of these tests, not the subject: what they constrain - where
// the folder ends, what makes a browse recursive, which part is a wildcard, what a parent is - is
// the same wherever Diffractor runs. This spells the same path for the platform under test, so a
// drive root becomes the filesystem root and separators follow suit.
static std::string as_platform_path(std::string_view windows_form)
{
if constexpr (core::windows_path_semantics)
{
return std::string(windows_form);
}
else
{
std::string result;
// A drive letter names nothing here, so the filesystem root stands in for the drive root.
if (windows_form.size() >= 2 && windows_form[1] == ':' && (windows_form[0] | 0x20) >= 'a' &&
(windows_form[0] | 0x20) <= 'z')
{
result = "/";
windows_form.remove_prefix(2);
if (!windows_form.empty() && (windows_form.front() == '\\' || windows_form.front() == '/'))
{
windows_form.remove_prefix(1);
}
}
for (const auto c : windows_form) result += c == '\\' ? '/' : c;
return result;
}
}
static void should_parse_searches()
{
const auto date_filter = df::search_t::parse("2012-09-14");
const df::search_matcher matcher(date_filter);
df::index_file_item info;
info.ft = files::file_type_from_name("test.jpg");
info.safe_ps()->dates.add(prop::date_source::exif_original, core::date_t(2012, 9, 14));
assert_equal(true, matcher.match_item({}, info).is_match(), "date");
info.safe_ps()->dates.clear();
info.safe_ps()->dates.add(prop::date_source::exif_original, core::date_t(2012, 9, 13));
assert_equal(false, matcher.match_item({}, info).is_match(), "date");
}
// Group by Date Original keys on the capture-first ladder and Group by Date Created keys on the
// Created concept, so each header has to be answered by its own key and by nothing else: answered by
// the wrong one, a header lists items the cell never counted; answered by neither, it opens empty.
// That is #184 on whichever order loses the rung.
static void should_answer_a_date_group_header_with_its_own_items()
{
df::index_file_item info;
info.ft = files::file_type_from_name("test.jpg");
// A photograph taken in 2019 and written to this disk by an export in 2026 - the ordinary shape
// of a file whose two dates disagree, and the whole reason Created is an order of its own.
info.safe_ps()->dates.add(prop::date_source::exif_original, core::date_t(2019, 5, 4));
info.safe_ps()->dates.add(prop::date_source::xmp_create, core::date_t(2026, 8, 19));
assert_equal(core::date_t(2019, 5, 4), info.safe_ps()->dates.original(), "the shutter is Original");
assert_equal(core::date_t(2026, 8, 19), info.safe_ps()->dates.created(), "and the export is Created");
// Day zero is the whole month, which is what a group header stands for.
const auto header = [](const int month, const int year, const df::date_parts_prop target)
{
return df::search_t().day(0, month, year, target);
};
assert_equal(true,
df::search_matcher(header(5, 2019, df::date_parts_prop::original)).match_item({}, info).is_match(),
"the Original header lists it");
assert_equal(true,
df::search_matcher(header(8, 2026, df::date_parts_prop::created)).match_item({}, info).is_match(),
"the Created header lists it");
// The two probes that pin the split. While the targets were one word both of these matched, so
// each header listed the other's items and the two orders were the same order.
assert_equal(false,
df::search_matcher(header(8, 2026, df::date_parts_prop::original)).match_item({}, info).is_match(),
"the Original header does not list the export month");
assert_equal(false,
df::search_matcher(header(5, 2019, df::date_parts_prop::created)).match_item({}, info).is_match(),
"the Created header does not list the shutter month");
// Still a date test, not a date-shaped wildcard.
assert_equal(false,
df::search_matcher(header(7, 2022, df::date_parts_prop::original)).match_item({}, info).is_match(),
"a month neither date names lists nothing");
// Where the concept has no tag the header is drawn from the filesystem stamp, so the stamp has
// to answer that order - and only that order, or Created reaches back into the shutter time.
df::index_file_item stamped;
stamped.ft = files::file_type_from_name("test.jpg");
stamped.safe_ps()->dates.add(prop::date_source::exif_original, core::date_t(2019, 5, 4));
stamped.file_created = core::date_t(2021, 3, 9);
assert_equal(false, stamped.safe_ps()->dates.created().is_valid(), "no tag names a creation date");
// Derived rather than written out: the group key converts the stamp to local, so the month the
// header carries depends on the machine and hard-coding one would pin nothing off UTC.
const auto stamp_parts = platform::utc_to_local(stamped.file_created).date();
assert_equal(true,
df::search_matcher(header(stamp_parts.month, stamp_parts.year, df::date_parts_prop::created))
.match_item({}, stamped)
.is_match(),
"the Created header drawn from the stamp lists it");
assert_equal(true,
df::search_matcher(header(5, 2019, df::date_parts_prop::original)).match_item({}, stamped).is_match(),
"and its Original header lists it too");
assert_equal(false,
df::search_matcher(header(5, 2019, df::date_parts_prop::created)).match_item({}, stamped).is_match(),
"while Created still does not reach the shutter time");
}
static void should_calculate_safe_presence_requirements()
{
const auto photo_bit = file_group::photo.search_presence_bit();
const auto video_bit = file_group::video.search_presence_bit();
assert_equal(photo_bit, df::search_t::parse("@photo").calc_required_presence().types,
"positive media type is required");
assert_equal(0u, df::search_t::parse("-@photo").calc_required_presence().types,
"negated media type cannot be required");
assert_equal(0u, df::search_t::parse("@photo or @video").calc_required_presence().types,
"OR branches have no individually required bit");
assert_equal(photo_bit | video_bit, df::search_t::parse("@photo @video").calc_required_presence().types,
"positive conjunction requires every media bit");
}
static void should_update_duplicate_search_presence()
{
df::index_item_infos files(1);
files.front().ft = files::file_type_from_name("test.jpg");
files.front().calc_search_presence();
const auto folder = std::make_shared<df::index_folder_item>(std::move(files));
folder->reset_search_presence();
const auto duplicate_search = df::search_t::parse("@duplicates");
const df::search_matcher matcher(duplicate_search);
const auto& file = folder->files.front();
assert_equal(false, matcher.can_contain(file.search_presence), "initial item presence");
assert_equal(false, matcher.can_contain(folder->search_presence_summary), "initial folder presence");
file.update_duplicates(folder, df::duplicate_info{.group = 7, .count = 2});
assert_equal(true, matcher.can_contain(file.search_presence), "added item presence");
assert_equal(true, matcher.can_contain(folder->search_presence_summary), "added folder presence");
assert_equal(true, matcher.match_item({}, file).is_match(), "added exact duplicate state");
file.update_duplicates(folder, df::duplicate_info{});
assert_equal(false, matcher.can_contain(file.search_presence), "removed item presence");
assert_equal(true, matcher.can_contain(folder->search_presence_summary), "safe stale folder presence");
assert_equal(false, matcher.match_item({}, file).is_match(), "removed exact duplicate state");
}
static void should_search_boolean_presence_terms(shared_test_context& stc)
{
stc.lazy_load_index();
const auto photos = count_search_results(stc.test_index, "@photo");
const auto videos = count_search_results(stc.test_index, "@video");
// The positive media term keeps these comparisons file-only (a bare negative term
// can also match folders). These identities verify that the bitmap prefilter does
// not discard files before the exact Boolean matcher sees them.
assert_equal(photos, count_search_results(stc.test_index, "@photo -@video"), "negated media search");
assert_equal(photos + videos, count_search_results(stc.test_index, "@photo or @video"), "OR media search");
const auto duplicate_photos = count_search_results(stc.test_index, "@photo @duplicates");
assert_equal(photos - duplicate_photos, count_search_results(stc.test_index, "@photo -@duplicates"),
"negated duplicate search");
}
static void should_match_terms()
{
prop_test()
.tag("aaa")
.is_match("#aaa")
.is_not_match("#bbb")
.is_match("-#bbb")
.is_match("!#bbb")
.is_not_match("-#aaa")
.is_not_match("!#aaa")
.is_match("#aaa or #bbb")
.is_not_match("#aaa and #bbb")
.is_not_match("#aaa #bbb");
prop_test().tag("bbb").is_not_match("#aaa").is_match("#bbb").is_match("#aaa or #bbb");
prop_test().tag("'aa bb'").is_not_match("#aaa").is_not_match("#bb").is_match("#'aa bb'");
prop_test()
.tag("aaa bbb")
.is_match("#aaa")
.is_match("#bbb")
.is_match("#aaa or #bbb")
.is_match("#aaa and #bbb")
.is_match("#aaa #bbb")
.is_not_match("#aaa !#bbb");
prop_test()
.rate(4)
.is_match("rate:4")
.is_match("4")
.is_match(">= 4")
.is_not_match("> 4")
.is_match(">3")
.is_match("3 | 4")
.is_match("3 or 4")
.is_not_match("3 and 4");
prop_test()
.desc("one two three")
.is_match("two")
.is_match("one two")
.is_match("two three")
.is_match("'two three'")
.is_not_match("'one three'");
prop_test().date(1999, 12, 27).is_match("age:5").is_match("age:10").is_not_match("age:1").is_not_match("age:2");
prop_test().date(2000, 1, 1).is_match("age:1").is_match("age:5").is_not_match("-age:5").is_not_match("!age:5");
// original: is the capture-first ladder the tile shows and Group by Date Original keys on;
// created: is the Created concept alone. A file carrying only a shutter time answers the first
// and not the second, which is what stops the two words being synonyms.
prop_test()
.tag("aaa")
.date(2000, 1, 1)
.is_match("#aaa age:1")
.is_match("#aaa original:2000-jan")
.is_not_match("original:2000-feb")
.is_not_match("#bbb original:2000-jan")
.is_not_match("created:2000-jan");
// The reverse asymmetry: the shutter time answers original: and the filesystem stamp behind it
// answers created:, so neither word reaches the other's date.
prop_test()
.file_created_date(2000, 1, 1)
.date(1999, 5, 25)
.is_match("original:1999-may")
.is_not_match("original:1998-mar")
.is_not_match("created:1999-may");
// With no metadata date at all both ladders fall back to the same stamp, which is what keeps a
// header drawn from it clickable under either order.
prop_test()
.file_created_date(2000, 1, 1)
.is_match("age:10")
.is_match("created:2000-jan")
.is_match("original:2000-jan");
}
// A query the user is midway through typing has an unbalanced '(' on almost every
// keystroke. The Boolean evaluator must fold that open group back into the outermost
// level, otherwise the outermost level keeps its initial 'true' and the query silently
// matches every item in scope.
static void should_match_unbalanced_groups()
{
prop_test()
.tag("aaa")
.is_match("(#aaa")
.is_match("(#aaa)")
.is_not_match("(#bbb")
.is_not_match("(#bbb)")
.is_match("#aaa (#bbb or #aaa")
.is_not_match("#aaa (#bbb")
.is_match("((#aaa")
.is_not_match("((#bbb");
prop_test().tag("bbb").is_not_match("(#aaa").is_match("(#aaa or #bbb").is_not_match("(#aaa #bbb");
}
// An unknown property name after with:/without: used to build a null-key term, which
// inverted into "match everything" for without: and "match nothing" for with:.
static void should_ignore_unknown_property_scopes()
{
prop_test()
.tag("aaa")
.is_match("without:rating")
.is_not_match("with:rating")
.is_not_match("without:not-a-property #bbb")
.is_match("with:tag");
prop_test().rate(4).is_match("with:rating").is_not_match("without:rating");
}
// Property kinds that the parser used to drop entirely, leaving an empty term list and
// therefore an unfiltered result set.
static void should_match_parsed_property_values()
{
// int_pair: "N" matches that number of any total, "N/M" must match both parts.
prop_test()
.track(3, 12)
.is_match("track:3")
.is_match("track:3/12")
.is_not_match("track:4")
.is_not_match("track:3/11");
prop_test().track(4, 12).is_match(">track:3").is_match(">=track:3").is_not_match("<track:3");
prop_test().track(2, 12).is_match("<track:3").is_match("<=track:3").is_not_match(">track:3");
prop_test().track(3, 13).is_match("track:3").is_match(">track:3/12").is_not_match("=track:3/12");
prop_test().disk(4, 12).is_match(">disk:3").is_not_match("<disk:3");
prop_test().disk(3, 13).is_match("disk:3").is_match(">disk:3/12");
prop_test().episode(4, 12).is_match(">episode:3").is_not_match("<episode:3");
prop_test().episode(3, 13).is_match("episode:3").is_match(">episode:3/12");
// A number with no total is still that number.
prop_test().episode(5).is_match("episode:5").is_not_match("episode:6");
prop_test().track(7).is_match("track:7");
// What a library of films and television says an item is.
prop_test()
.kind(prop::media_kind::film)
.is_match("@movie")
.is_match("@film")
.is_not_match("@episode")
.is_match("-@episode");
prop_test().kind(prop::media_kind::episode).is_match("@episode").is_match("@tv").is_not_match("@movie");
prop_test().is_not_match("@movie").is_not_match("@episode");
// Started and not finished; neither just opened nor played to the credits.
prop_test().duration(3600).media_position(1200).is_match("@inprogress").is_match("@watching");
prop_test().duration(3600).media_position(10).is_not_match("@inprogress");
prop_test().duration(3600).media_position(3500).is_not_match("@inprogress");
prop_test().duration(3600).is_not_match("@inprogress");
prop_test()
.dimensions(4000, 3000)
.is_match(">dimensions:3000x2000")
.is_not_match("<dimensions:3000x2000")
.is_match("dimensions:4000");
prop_test().dimensions(3000, 2200).is_match(">dimensions:3000x2000").is_not_match("=dimensions:3000x2000");
// a date property other than created/modified reached a poisoned comparison
prop_test().digitized(2000, 1, 1).is_match("digitized:2000-jan").is_not_match("digitized:2000-feb");
// "ISO400" parsed the number but then matched against zero
prop_test().iso(400).is_match("iso:ISO400").is_match("iso:400").is_not_match("iso:800");
// "%d:%d" also matches the prefix of "1:02:03", so H:MM:SS must be tried first
prop_test().duration(3723).is_match("duration:1:02:03").is_not_match("duration:1:02");
}
static void should_match_multi_value_genre()
{
// A single ';'-separated genre field should match a query for any one of its values.
prop_test()
.genre("Rock; Pop; Hip Hop")
.is_match("genre:Rock")
.is_match("genre:Pop")
.is_match("genre:'Hip Hop'")
.is_not_match("genre:Jazz")
.is_match("genre:Rock or genre:Jazz")
.is_not_match("-genre:Rock");
// A single-value genre still matches exactly.
prop_test().genre("Jazz").is_match("genre:Jazz").is_not_match("genre:Rock");
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Issue #139 / #178 - Quoted terms containing spaces.
// A quoted value with spaces (e.g. a path or multi-word tag) must be parsed as a
// single term, not split on the space, and must survive round-tripping through
// the parser. This is the search-engine capability behind #139 (auto-quoting
// paths with spaces) and #178 (quoted/edited terms must not be silently dropped);
// the search-bar UI behaviour in those reports is tracked separately.
///////////////////////////////////////////////////////////////////////////////////////////////////
static void should_match_quoted_terms()
{
// A multi-word tag is kept whole when quoted and does not match its parts.
prop_test().tag("'holiday photos'").is_match("#'holiday photos'").is_not_match("#holiday").is_not_match("#photos");
// A quoted phrase matches a contiguous substring only.
prop_test().desc("new york city").is_match("'new york'").is_not_match("'york new'");
// A path-like value with spaces round-trips through parse + match.
prop_test().desc("C:/My Photos/trip").is_match("'My Photos'").is_not_match("'Your Photos'");
}
// Issue #178 - the search bar must echo exactly what the user typed instead of
// silently reverting it to the normalized form. Issue #139 - a bare path that
// contains spaces is auto-quoted so it reads as a single term.
static void should_preserve_and_auto_quote_search_input()
{
const df::search_t base;
// #178: user text is preserved, not reverted to a normalized reconstruction.
assert_equal("#a #b #a"s, base.parse_from_input("#a #b #a").text(), "duplicate tags preserved in search bar text");
assert_equal("\"aaa\""s, base.parse_from_input("\"aaa\"").text(), "quotes preserved in search bar text");
// #139: a bare path containing spaces is auto-quoted.
const auto my_photos = as_platform_path("C:\\My Photos");
const auto photos = as_platform_path("C:\\Photos");
assert_equal("\"" + my_photos + "\"", base.parse_from_input(my_photos).text(), "path with spaces auto-quoted");
assert_equal(photos, base.parse_from_input(photos).text(), "path without spaces left unquoted");
assert_equal("\"" + my_photos + "\"", base.parse_from_input("\"" + my_photos + "\"").text(),
"already-quoted path not double-quoted");
const auto folder_query = std::string(test_files_folder().text()) + " Test";
const auto scoped = base.parse_from_input(folder_query);
assert_equal(1_z, scoped.selectors().size(), "folder query has one selector");
assert_equal(1_z, scoped.terms().size(), "the filename term is separate from the folder");
assert_equal(folder_query, scoped.text(), "the whole query is not quoted as one folder");
const auto resubmitted = base.parse_from_input(scoped.text());
assert_equal(scoped.format_terms(), resubmitted.format_terms(), "resubmission preserves the query");
assert_equal(scoped.selectors().front().folder().text(), resubmitted.selectors().front().folder().text(),
"resubmission preserves the folder");
}
static void should_preserve_unavailable_path_scopes()
{
struct unavailable_state_strategy final : null_state_strategy
{
int unavailable = 0;
void report_scope_unavailable(const df::search_t&) override { ++unavailable; }
} ss;
null_async_strategy as;
const location_cache locations;
index_state index(as, locations);
view_state state(ss, as, index, make_test_player());
const view_host_base_ptr view;
const auto root = test_temps.next_folder("unavailable-scope");
const auto current = df::search_t().add_selector(root);
state.view_mode(view_type::items);
assert_equal(true, state.open(view, current, {}), "the starting scope is available");
for (const auto name : {"missing", "missing photos"})
{
const auto missing = root.combine(name);
const auto path = std::string(missing.text());
for (const auto& text : {path, path + core::preferred_path_sep, "\"" + path + "\"", "'" + path + "'"})
{
for (const auto& search : {df::search_t::parse(text), current.parse_from_input(text)})
{
assert_equal(1_z, search.selectors().size(), "an unavailable absolute path retains its scope");
assert_equal(missing.text(), search.selectors().front().folder().text(),
"the intended folder is retained");
assert_equal(true, search.terms().empty(), "a missing path is not a collection text term");
const auto before = ss.unavailable;
assert_equal(false, state.open(view, search, {}), "unavailable navigation is refused");
assert_equal(before + 1, ss.unavailable, "the existing unavailable-scope recovery is reached");
assert_equal(true, state.search() == current, "refused navigation retains the current scope");
}
}
}
}
// Issue #157 - scope-aware search auto-completion. The active (last) token of a query
// is classified so the value part of a scoped term can be completed from the matching
// vocabulary, and matches are formatted back into the text that will be committed.
static void should_classify_search_scope()
{
using k = df::search_scope_kind;
// A plain word / empty query is not scoped.
assert_equal(true, df::classify_search_scope("hello").kind == k::none, "plain word not scoped");
assert_equal(true, df::classify_search_scope("").kind == k::none, "empty query not scoped");
// '#' tag scope: completes from "#tag" vocabulary and keeps the '#' form.
{
const auto s = df::classify_search_scope("#do");
assert_equal(true, s.kind == k::tag, "# is a tag scope");
assert_equal(false, s.tag_as_scope, "# is not the tag: form");
assert_equal("do"s, s.value, "# value fragment");
assert_equal("#do"s, s.vocab_query(), "# vocabulary query");
assert_equal("#dog"s, s.format("#dog"), "# keeps the hash form");
}
// 'tag:' scope: completes from the same vocabulary but rewrites to the tag: form.
{
const auto s = df::classify_search_scope("tag:do");
assert_equal(true, s.kind == k::tag, "tag: is a tag scope");
assert_equal(true, s.tag_as_scope, "tag: form recorded");
assert_equal("#do"s, s.vocab_query(), "tag: uses the # vocabulary");
assert_equal("tag:dog"s, s.format("#dog"), "tag: rewrites #dog -> tag:dog");
}
// '@' media group scope.
{
const auto s = df::classify_search_scope("@vi");
assert_equal(true, s.kind == k::group, "@ is a group scope");
assert_equal("@vi"s, s.vocab_query(), "@ vocabulary query");
assert_equal("@video"s, s.format("@video"), "@ keeps the group form");
}
// with: / without: complete from property scope names (no vocabulary query).
{
const auto sw = df::classify_search_scope("with:ex");
assert_equal(true, sw.kind == k::with, "with: scope");
assert_equal(""s, sw.vocab_query(), "with: has no word vocabulary");
assert_equal("with:exposure"s, sw.format("exposure"), "with: formats the scope name");
const auto swo = df::classify_search_scope("without:ta");
assert_equal(true, swo.kind == k::without, "without: scope");
assert_equal("without:tag"s, swo.format("tag"), "without: formats the scope name");
}
// Only the last token is scoped; the lead text is preserved verbatim.
{
const auto s = df::classify_search_scope("beach tag:do");
assert_equal(true, s.kind == k::tag, "last token classified");
assert_equal("beach "s, s.lead, "lead text preserved");
assert_equal("do"s, s.value, "value taken from last token");
assert_equal("beach tag:dog"s, core::combine2(s.lead, s.format("#dog")), "lead + formatted value");
}
// Scope prefixes are case-insensitive.
assert_equal(true, df::classify_search_scope("TAG:do").kind == k::tag, "tag: is case-insensitive");
assert_equal(true, df::classify_search_scope("WITH:x").kind == k::with, "with: is case-insensitive");
// An empty value (just the prefix) still classifies and yields a broad vocabulary query.
{
const auto s = df::classify_search_scope("tag:");
assert_equal(true, s.kind == k::tag, "bare tag: is a tag scope");
assert_equal("#"s, s.vocab_query(), "bare tag: matches all tags");
}
// locations.md 3.4/3.5: every location scope completes from the gazetteer, differing only in
// the level it constrains to, and the candidate arrives as a finished canonical term.
{
using l = df::location_level;
const auto loc = df::classify_search_scope("loc:lond");
assert_equal(true, loc.kind == k::location, "loc: is a location scope");
assert_equal(true, loc.level == l::any, "loc: is unqualified");
assert_equal("lond"s, loc.value, "loc: value fragment");
assert_equal(""s, loc.vocab_query(), "loc: has no word vocabulary");
assert_equal("loc:\"London, United Kingdom\""s, loc.format("loc:\"London, United Kingdom\""),
"location candidates commit verbatim");
assert_equal(true, df::classify_search_scope("near:lond").kind == k::location, "near: is a location scope");
assert_equal(true, df::classify_search_scope("place:lond").level == l::place, "place: is place level");
assert_equal(true, df::classify_search_scope("city:lond").level == l::place, "city: is place level");
assert_equal(true, df::classify_search_scope("state:cali").level == l::state, "state: is state level");
assert_equal(true, df::classify_search_scope("country:fra").level == l::country, "country: is country level");
assert_equal(true, df::classify_search_scope("countries:fra").level == l::country,
"countries: is country level");
assert_equal(true, df::classify_search_scope("LOC:x").kind == k::location, "loc: is case-insensitive");
// Only the last token is scoped, and a bare prefix still classifies.
const auto lead = df::classify_search_scope("beach loc:lond");
assert_equal(true, lead.kind == k::location, "last token classified");
assert_equal("beach "s, lead.lead, "lead text preserved");
assert_equal(""s, df::classify_search_scope("loc:").value, "bare loc: matches all places");
// A word that merely begins with a scope name is not a scope.
assert_equal(true, df::classify_search_scope("location").kind == k::none, "'location' is a plain word");
}
}
// A completion match needs a strategy to report back to. Nothing here selects, so the callbacks
// are never reached.
class null_complete_strategy final : public ui::complete_strategy_t
{
public:
std::string no_results_message() override { return {}; }
void selected(const ui::auto_complete_match_ptr& /*i*/, select_type /*st*/) override {}
ui::auto_complete_match_ptr selected() const override { return nullptr; }
void search(const std::string& /*query*/,
std::function<void(const ui::auto_complete_results&)> /*complete*/) override
{
}
void initialise(std::function<void(const ui::auto_complete_results&)> /*complete*/) override {}
};
static void should_format_search_predictions()
{
assert_equal("#holiday #beach"s, core::combine2(auto_complete_lead("#holiday"), "#beach"),
"missing separator is inserted");
assert_equal("#holiday #beach"s, core::combine2(auto_complete_lead("#holiday "), "#beach"),
"existing separator is preserved");
// Issue #139 - a completed path containing spaces reads as one term. Committing it after a lead
// term is the case the whole-input auto-quote cannot reach.
null_complete_strategy strategy;
const auto my_photos = as_platform_path("C:\\My Photos");
const auto photos = as_platform_path("C:\\Photos");
assert_equal("\"" + my_photos + "\"", folder_match(strategy, core::folder_path(my_photos)).edit_text(),
"completed path with spaces is quoted");
assert_equal(photos, folder_match(strategy, core::folder_path(photos)).edit_text(),
"completed path without spaces is left alone");
assert_equal("#holiday \"" + my_photos + "\"",
folder_match(strategy, core::folder_path(my_photos), "#holiday"s).edit_text(),
"completed path after a lead term is quoted");
assert_equal(my_photos,
folder_match(strategy, core::folder_path(my_photos), ui::match_highlights{}, 1, true).edit_text(),
"folder picker completions keep raw paths");
assert_equal(true, search_icon("holiday") == icon_index::search, "plain text uses search icon");
assert_equal(true, search_icon(as_platform_path("C:\\Photos")) == icon_index::folder, "path uses folder icon");
assert_equal(true, search_icon("#holiday") == icon_index::tag, "tag uses tag icon");
assert_equal(true, search_icon("rating:4") == prop::rating.icon, "property uses property icon");
assert_equal(true, search_icon("2012-09-14") == icon_index::time, "date uses time icon");
assert_equal(true, search_icon("@photo") == icon_index::photo, "media group uses media icon");
}
// A bare byte count went through an int, so anything above two billion wrapped and matched small
// files, and TB was not a unit the parser knew at all - the formatter already wrote it, so a
// terabyte query did not survive a round trip through the address box.
static void should_parse_file_size_terms()
{
const auto size_of = [](const std::string_view query) -> uint64_t
{
const auto search = df::search_t::parse(query);
const auto& terms = search.terms();
return terms.empty() ? 0ull : terms.front().int64_val;
};
constexpr uint64_t kb = 1024ull;
constexpr uint64_t mb = kb * 1024ull;
constexpr uint64_t gb = mb * 1024ull;
constexpr uint64_t tb = gb * 1024ull;
assert_equal(14ull * kb, size_of("size:14kb"), "kilobytes");
assert_equal(mb, size_of("size:1mb"), "megabytes");
assert_equal(2ull * gb, size_of("size:2gb"), "gigabytes");
assert_equal(tb, size_of("size:1tb"), "terabytes");
assert_equal(3ull * tb / 2ull, size_of("size:1.5tb"), "fractional terabytes");
assert_equal(512ull, size_of("size:512"), "a bare byte count");
// Larger than a signed 32-bit count, which is where the int overflowed.
assert_equal(3'000'000'000ull, size_of("size:3000000000"), "a bare count past the int range");
assert_equal(tb, size_of("size:1099511627776"), "a bare count of a terabyte");
// The formatter writes a terabyte as "size: 1 TB", the unit apart from its number, so the unit
// has to be recognised on its own as well or the query reads back as one byte and a text term.
const auto formatted = df::search_t::parse("size:1tb").format_terms();
assert_equal(1_z, df::search_t::parse(formatted).terms().size(), "a formatted terabyte is still one term");
assert_equal(tb, size_of(formatted), "and still a terabyte");
}
static void should_not_match_folder_without()
{
const auto now_days = core::date_t(2000, 1, 1).to_days();
const auto search = df::search_t::parse("without:tag");
const df::search_matcher matcher(search, now_days);
assert_equal(false, matcher.match_folder(test_files_folder().text(), "test"_c).is_match(), "folder name test");
}
// A level used to start at `true`, the identity for AND but the annihilator for OR. A group opened
// by an OR term folded into a parent seeded with `true`, so the parent stayed true whatever it
// received and the whole expression matched every item.
static void should_group_search_terms()
{
const auto matches = [](const std::string_view query, const std::string_view name)
{
df::index_file_item file;
file.name = core::cache(name);
file.ft = files::file_type_from_name(name);
file.safe_ps();
const auto search = df::search_t::parse(query);
const df::search_matcher matcher(search, core::date_t(2000, 1, 1).to_days());
return matcher.match_all_terms(test_files_folder().text(), file).is_match();
};
assert_equal(true, matches("alpha or (beta gamma)", "alpha.jpg"), "the left side of an or still matches");
assert_equal(false, matches("alpha or (beta gamma)", "beta.jpg"), "half of an and-group does not");
assert_equal(false, matches("alpha or (beta gamma)", "delta.jpg"), "neither side matches nothing");
// The regression: the same expression with the group nested one deeper.
assert_equal(false, matches("alpha or ((beta gamma))", "delta.jpg"),
"a nested group after or does not match everything");
assert_equal(false, matches("alpha or ((beta gamma))", "beta.jpg"), "and still binds inside the nested group");
assert_equal(true, matches("alpha or ((beta gamma))", "alpha.jpg"), "and the or still matches its left side");
assert_equal(false, matches("(alpha) (beta)", "alpha.jpg"), "two and-groups both have to match");
assert_equal(true, matches("(alpha) or (beta)", "beta.jpg"), "either or-group may match");
assert_equal(false, matches("(alpha) or (beta)", "delta.jpg"), "an or of groups is not unconditional");
// A bare f/N reads as text or as an aperture, a pair that stands where the term stood. The
// aperture arm took the group's closing bracket with it, so it was ored in a level outside the
// group - and an f/2.8 from any camera answered "(camera:canon f/2.8)".
const auto shot =
[](const std::string_view query, const std::string_view camera, const float aperture, const uint16_t iso)
{
df::index_file_item file;
file.name = "shot.jpg"_c;
file.ft = files::file_type_from_name("shot.jpg");
const auto md = file.safe_ps();
md->camera_model = core::cache(camera);
md->f_number = aperture;
md->iso_speed = iso;
const auto search = df::search_t::parse(query);
const df::search_matcher matcher(search, core::date_t(2000, 1, 1).to_days());
return matcher.match_all_terms(test_files_folder().text(), file).is_match();
};
constexpr auto grouped = "(camera:canon f/2.8) or iso:100"sv;
assert_equal(false, shot(grouped, "Nikon", 2.8f, 200), "the aperture alone does not answer the group");
assert_equal(true, shot(grouped, "Canon", 2.8f, 200), "the whole group does");
assert_equal(true, shot(grouped, "Nikon", 4.0f, 100), "and so does the term ored after it");
assert_equal(false, shot(grouped, "Canon", 4.0f, 200), "a group with its aperture unmet does not");
assert_equal(true, shot("(f/2.8 camera:canon) or iso:100"sv, "Canon", 2.8f, 200),
"an f/N that opens a group keeps the group's and");
assert_equal(false, shot("(f/2.8 camera:canon) or iso:100"sv, "Nikon", 2.8f, 200), "with the rest of its group");
}
// Four ways a query came back as a different question from the one that was asked. Each is a silent
// wrong answer: the search runs, returns a plausible set, and never says the question changed.
static void should_read_a_query_back_as_it_was_asked()
{
// Dimensions are written "WxH", but the pair was split on '/' alone - so the height fell off,
// and compare_term reads a zero second component as "any". The query then matched every image
// of that width whatever its height, which is broader than what was asked and than what the
// list had shown.
{
const auto parsed = df::search_t::parse("dimensions:1920x1080");
assert_equal(1_z, parsed.terms().size(), "a dimension is one term");
assert_equal(1920, static_cast<int>(parsed.terms().front().xy_val.x), "the width is read");
assert_equal(1080, static_cast<int>(parsed.terms().front().xy_val.y), "and so is the height");
const auto track = df::search_t::parse("track:3/12");
assert_equal(3, static_cast<int>(track.terms().front().xy_val.x), "a track still reads its number");
assert_equal(12, static_cast<int>(track.terms().front().xy_val.y), "and its total");
}
// Every delimiter the tokenizer would otherwise split is quoted when it is data, not grammar.
for (const auto value : {"Part(1)"sv, "a,b"sv, "a;b"sv, "a|b"sv, "a#b"sv, "<3"sv, ">x"sv, "=x"sv, "&ME"sv})
{
auto query = df::search_t().with(prop::title, value);
const auto text = query.format_terms();
const auto reparsed = df::search_t::parse(text);
assert_equal(1_z, reparsed.terms().size(), std::format("{} stays one term", value));
assert_equal(value, reparsed.terms().front().text, std::format("{} operand survives", value));
assert_equal(text, reparsed.format_terms(), std::format("{} canonical form is stable", value));
}
// Numeric query operands keep the exact predicate value rather than the rounded display label.
{
const auto query = df::search_t().with(prop::focal_length, 8.8);
const auto text = query.format_terms();
assert_equal("focal.length: 8.8mm", text, "focal length query text");
const auto reparsed = df::search_t::parse(text);
assert_equal(8.8, reparsed.terms().front().float_val, "focal length operand survives");
prop_test().focal_length(8.8).is_match(text);
prop_test().focal_length(9.0).is_not_match(text);
const auto sub_mm = df::search_t().with(prop::focal_length, 0.8).format_terms();
assert_equal("focal.length: 0.8mm", sub_mm, "sub-millimetre focal length text");
prop_test().focal_length(0.8).is_match(sub_mm);
for (const auto exposure : {0.3, 1.6, 1.0 / 250.0})
{
const auto exposure_text = df::search_t().with(prop::exposure_time, exposure).format_terms();
prop_test().exposure_time(exposure).is_match(exposure_text);
}
for (const auto sample_rate : {uint16_t{22050}, uint16_t{44100}})
{
const auto sample_rate_text = df::search_t().with(prop::audio_sample_rate, sample_rate).format_terms();
prop_test().audio_sample_rate(sample_rate).is_match(sample_rate_text);
}
}
// A quoted word is the word. Rewriting it into an operator changed the query's own logic
// instead of matching the text between the quotes.
{
const auto quoted = df::search_t::parse("alpha \"and\" beta");
assert_equal(3_z, quoted.terms().size(), "a quoted and is a term of its own");
const auto bare = df::search_t::parse("alpha and beta");
assert_equal(2_z, bare.terms().size(), "an unquoted one still joins the two either side");
// Written back it has to stay quoted: format_terms is what the address box shows once the
// typed text is gone, and a bare "and" there reads back as the operator again.
const auto reread = df::search_t::parse(quoted.format_terms());
assert_equal(3_z, reread.terms().size(), "a quoted and survives being written back");
}
// "-f/2.8" expands to a group matching either reading of the value: the text of a lens
// description, or the aperture. Negated, the arms have to be joined the other way round -
// "not either" is "neither". Left as an OR the pair read as "not the text or not the
// aperture", which is true whenever the two readings disagree, so the exclusion let through
// exactly the photographs it was asked to remove.
{
// A zoom whose description names f/3.5, on a frame actually taken at f/5.6. That is the one
// shape where the two arms disagree, so it is the only one where the join between them can
// be observed at all.
const auto matches = [](const std::string_view query)
{
df::index_file_item file;
file.name = "shot.jpg"_c;
file.ft = files::file_type_from_name("shot.jpg");
const auto md = file.safe_ps();
md->lens = "EF 24-105mm f/3.5-5.6 IS"_c;
md->f_number = 5.6f;
const auto search = df::search_t::parse(query);
const df::search_matcher matcher(search, core::date_t(2000, 1, 1).to_days());
return matcher.match_all_terms(test_files_folder().text(), file).is_match();
};
assert_equal(true, matches("f/3.5"), "the lens description is one of the two readings");
assert_equal(false, matches("-f/3.5"), "so excluding that value excludes this photograph");
assert_equal(true, matches("f/5.6"), "the aperture it was taken at is the other reading");
assert_equal(false, matches("-f/5.6"), "and excluding that excludes it too");
}
}
// A cancelled walk stops where the token was raised, so what it holds is a prefix of the answer.
// Reporting that as complete let a superseded pass settle the list showing fewer items than exist
// and announce that it had finished - and because re-opening the same search leaves the search
// identity unchanged, the identity test at the publication point could not tell the two apart.
static void should_not_call_a_cancelled_query_complete(shared_test_context& stc)
{
const auto search = df::search_t().add_selector(test_files_folder());
auto complete_runs = 0;
auto partial_runs = 0;
auto cb = [&complete_runs, &partial_runs](const index_state::query_item_results& /*items*/, const bool is_complete)
{
if (is_complete) ++complete_runs;
else ++partial_runs;
};
stc.test_index.query_items(search, cb, test_token);
assert_equal(1, complete_runs, "a walk that ran to the end reports completion");
assert_equal(0, partial_runs, "and reports it once");
complete_runs = 0;
partial_runs = 0;
std::atomic_bool cancelled = true;
const core::cancel_token stopped(cancelled);
stc.test_index.query_items(search, cb, stopped);
assert_equal(0, complete_runs, "a cancelled walk does not claim to be complete");
assert_equal(1, partial_runs, "it still answers, but as the partial set it holds");
}
static void should_match_volume_label()
{
// Map a drive letter to a volume label so the volume: term can be matched
// deterministically without depending on the drives present on the machine.
core::hash_map<char, core::cached> labels;
labels['X'] = core::cache("Backup");
const auto exact = df::search_t::parse("volume:Backup");
const auto& exact_term = exact.terms().front();
assert_equal(true, df::match_volume_label("X:\\photos\\2024", labels, exact_term), "match on drive X");
assert_equal(true, df::match_volume_label("x:\\photos", labels, exact_term), "drive letter case-insensitive");
assert_equal(false, df::match_volume_label("Y:\\photos", labels, exact_term), "different drive");
assert_equal(false, df::match_volume_label("\\\\server\\share", labels, exact_term),
"unc path has no drive letter");
assert_equal(true, df::match_volume_label("X:\\x", labels, df::search_t::parse("volume:BACKUP").terms().front()),
"label case-insensitive");
assert_equal(true, df::match_volume_label("X:\\x", labels, df::search_t::parse("volume:Back*").terms().front()),
"label wildcard");
assert_equal(false, df::match_volume_label("X:\\x", labels, df::search_t::parse("volume:Other").terms().front()),
"non-matching label");
}
static void should_match_date(const std::string_view query, const core::date_t d)
{
df::index_file_item props_without_val;
props_without_val.ft = files::file_type_from_name("test.jpg");
props_without_val.file_modified = core::date_t(1972, 5, 25);
props_without_val.safe_ps();
df::index_file_item props_with_val;
props_with_val.ft = files::file_type_from_name("test.jpg");
props_with_val.safe_ps()->dates.add(prop::date_source::exif_original, d);
const auto search = df::search_t::parse(query);
df::search_matcher matcher(search, core::date_t(2000, 1, 1).to_days());
assert_equal(true, matcher.match_all_terms(test_files_folder().text(), props_with_val).is_match(), query);
assert_equal(false, matcher.match_all_terms(test_files_folder().text(), props_without_val).is_match(), query);
}
static void assert_parse(const std::string_view selector, const std::string_view display, const std::string_view folder,
const bool is_recursive, const std::string_view wildcard)
{
const core::item_selector sel(selector);
assert_equal(display, sel.str(), "item_selector.str");
assert_equal(folder, sel.folder().text(), "item_selector.folder");
assert_equal(is_recursive, sel.is_recursive(), "item_selector.is_recursive");
assert_equal(wildcard, sel.wildcard(), "item_selector.wildcard");
}
static void assert_parse(const std::string_view selector, const std::string_view folder, const bool is_recursive,
const std::string_view wildcard)
{
assert_parse(selector, selector, folder, is_recursive, wildcard);
}
static void should_parse_selector()
{
const auto p = as_platform_path;
assert_parse(p("c:\\"), p("c:\\"), false, "*.*");
assert_parse(p("c:\\**"), p("c:\\"), true, "*.*");
assert_parse(p("c:\\**\\"), p("c:\\**"), p("c:\\"), true, "*.*");
assert_parse(p("c:/**/"), p("c:\\**"), p("c:\\"), true, "*.*");
assert_parse(p("c:\\*.jpg"), p("c:\\"), false, "*.jpg");
assert_parse(p("c:\\temp\\*.jpg"), p("c:\\temp"), false, "*.jpg");
assert_parse(p(R"(c:\temp\**\*.jpg)"), p("c:\\temp"), true, "*.jpg");
assert_parse(p("c:\\temp\\***.jpg"), p("c:\\temp"), false, "***.jpg");
assert_parse(p("c:\\temp\\?x.jpg"), p("c:\\temp"), false, "?x.jpg");
}
static void should_detect_folder_browse()
{
// A plain folder path (with no search terms) is a folder browse. This drives the
// "Empty Folder" vs "Nothing found" message when the view has no items.
//
// parse_path only accepts a folder that exists, so this uses the fixtures folder rather than a
// system one that only happens to be there on one platform.
const std::string folder(test_files_folder().text());
#ifdef _WIN32
// A UNC path is a Windows spelling; elsewhere a leading backslash is an ordinary name character. "\\"
// names no server, so it searches for nothing. A server is a place - its folders are the shares it
// offers - read from its spelling alone, since the file system would only wait on the network to say it
// is no folder.
assert_equal(true, df::search_t::parse("\\\\").is_empty(), "a UNC prefix alone names nothing");
const auto server = df::search_t().add_selector(core::item_selector(core::folder_path("\\\\server")));
assert_equal(true, df::search_t::parse("\\\\server") == server, "a server opens on its shares");
assert_equal(true, df::search_t::parse("\\\\server\\") == server, "with or without a closing separator");
assert_equal(true, server.is_folder(), "browsed as a folder is");
assert_equal(true, server.can_be_read_from("\\\\server"), "and read back from its text, as a favourite is");
#endif
assert_equal(true, df::search_t::parse(folder).is_folder(), "plain folder path");
assert_equal(true, df::search_t::parse(folder + core::preferred_path_sep + "**").is_folder(),
"recursive folder browse");
assert_equal(true, df::search_t::parse(folder + core::preferred_path_sep + "*.jpg").is_folder(),
"folder with wildcard, no terms");
// A search - even one scoped to a folder - is not a folder browse.
assert_equal(false, df::search_t::parse(folder + " with:tag").is_folder(), "folder scoped search");
assert_equal(false, df::search_t::parse("dog").is_folder(), "term with no selector");
assert_equal(false, df::search_t::parse("2014").is_folder(), "date term");
assert_equal(false, df::search_t().is_folder(), "empty search");
}
// The favourite star compares the search in view with every favourite at each navigation, on the UI
// thread, so it reads them rather than parsing them: parsing asks the file system, and a favourite on a
// share that was away held the window for twenty seconds. Wherever parsing matched, reading has to.
static void should_read_a_favourite_without_the_file_system()
{
const std::string folder(test_files_folder().text());
const auto quoted = df::quote_path_term(folder);
const std::string sep(1, core::preferred_path_sep);
const auto plain = test_temps.next_folder("favourite");
const std::string spaced(test_temps.next_folder("favourite place").text());
for (const auto& typed : {folder, spaced, folder + sep + "**", folder + sep + "*.jpg", quoted + " @photo",
quoted + " 2019", df::quote_path_term(spaced) + " 2019", "dog"s, "@photo"s})
{
const auto search = df::search_t::parse(typed);
const auto saved = search.text();
assert_equal(true, df::search_t::parse(saved) == search, typed + " parses back as the star compared it");
assert_equal(true, search.can_be_read_from(saved), typed + " reads back as saved");
assert_equal(true, search.can_be_read_from(typed), typed + " reads back as typed");
}
const auto file = folder + sep + "Test.jpg";
const auto file_search = df::search_t::parse(file);
assert_equal(1_z, file_search.terms().size(), "a file parses as its folder and its name");
assert_equal(true, file_search.can_be_read_from(file), "a file reads back");
// Without the file system a path and the words after it read either way: the folder named by all of
// it, or a folder and a year. Parsing picks the one that is there, as the place in view is.
const auto ambiguous = std::string(plain.text()) + " 2019";
assert_equal(true, df::search_t::parse(ambiguous).can_be_read_from(ambiguous), "a folder and a year");
assert_equal(true, df::search_t().add_selector(core::item_selector(ambiguous)).can_be_read_from(ambiguous),
"a folder named with a year, read without asking whether it is there");
// A favourite on a place that is away reads as that place, as parsing it does.