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
|
#include "./filtered_string_view.h"
#include <catch2/catch.hpp>
// Specification: 2.3 - Static Data Members
// Purpose: Ensure that the default predicate function returns true for any
// character passed in.
// Expected: The function should always return true for all possible arguments.
// Note: Taken directly from the specification, modified for catch2.
TEST_CASE("default predicate function always returns true") {
const auto min = std::numeric_limits<char>::min();
const auto max = std::numeric_limits<char>::max();
for (char c = min; c != max; c++) {
REQUIRE(fsv::filtered_string_view::default_predicate(c));
}
}
// Specification: 2.4.1 - Default Constructor
// Purpose: Determine that the default constructor results in the equivalent
// of an empty string.
// Expected: The view should compare equal to an empty string with a zero
// length. Data should be set to nullptr.
// Note: We cannot test where the underlying predicate points to directly as
// this would make the test brittle by introducing implementation details.
// We may only test this implicitly via string comparisons.
TEST_CASE("default constructed is equivalent to an empty string") {
const auto view = fsv::filtered_string_view{};
REQUIRE(std::string{""} == view);
REQUIRE(std::size(view) == 0);
REQUIRE(std::data(view) == nullptr);
}
// Specification: 2.4.2 - Implicit String Constructor
// Purpose: Ensure the implicit string constructor does not modify the string it
// originally refers to or filter the data. It has not been provided
// with an alternative predicate, so it should perform no filtering.
// Expected: The view should be equivalent to the parent string. Data should
// point directly to the parent string. The length should be equal to the parent
// string.
TEST_CASE("implicit string constructor is equivalent to parent string") {
const auto parent = std::string{"parent string"};
const auto view = fsv::filtered_string_view{parent};
REQUIRE(parent == view);
REQUIRE(std::data(parent) == std::data(view));
REQUIRE(std::size(parent) == std::size(view));
};
// Specification: 2.4.3 - String Constructor with Predicate
// Purpose: The string constructor with a supplied predicate should filter the
// original string by the rules provided by the predicate.
// Expected: The view should NOT be equivalent to the parent string. The lengths
// should not be identical. This is provided that the predicate
// filters part of the original string.
TEST_CASE("string constructor with predicate filters parent string") {
const auto parent = std::string{"parent string"};
const auto view = fsv::filtered_string_view{parent, [](const char& c) { return c != 's'; }};
REQUIRE(view == std::string{"parent tring"});
REQUIRE(std::data(parent) == std::data(view));
REQUIRE(std::size(parent) != std::size(view));
};
// Specification: 2.4.4 - Implicit Null-Terminated String Constructor
// Purpose: The implicit null terminated string constructor should perform
// identically to the standard string constructor.
// Expected: The view should be equivalent to the parent string in data, length
// and equality.
TEST_CASE("implicit null terminated string does not filter parent string") {
const auto parent = std::string{"parent string"};
const auto view = fsv::filtered_string_view{parent.c_str()};
REQUIRE(view == parent);
REQUIRE(std::data(parent) == std::data(view));
REQUIRE(std::size(parent) == std::size(view));
};
// Specification: 2.4.5 - Null-Terminated String with Predicate Constructor
// Purpose: The null terminated string with predicate constructor should operate
// identically to the standard string constructor with a predicate.
// Given a predicate, it should filter the string via that rule.
// Expected: The view should not be equivalent to the parent string. Data should
// remain the same, while size should be different.
TEST_CASE("null-terminated string with predicate constructor filters the parent string") {
const auto parent = std::string{"parent string"};
const auto view = fsv::filtered_string_view{parent.c_str(), [](const char& c) { return c != 's'; }};
REQUIRE(view == std::string{"parent tring"});
REQUIRE(std::data(parent) == std::data(view));
REQUIRE(std::size(parent) != std::size(view));
}
// Specification: 2.4.6 - Copy and Move Constructors
// Purpose: Copy constructors function as expected. In addition, the copy
// constructor has an equality constraint.
// Expected: The newly constructed object must compare equal to the copied
// object.
// Note: This test was taken from the specification, modified for catch2. We
// split the test into two for readability (the move constructor is
// separate), and include additional length and non std::data equality
// tests.
TEST_CASE("copy constructors compare equal") {
const auto parent = fsv::filtered_string_view{"parent string"};
const auto copy = parent;
REQUIRE(std::data(copy) == std::data(parent));
REQUIRE(copy == parent);
REQUIRE(std::size(copy) == std::size(parent));
}
// Specification: 2.4.6 - Copy and Move Constructors
// Purpose: Copy and move constructors function as expected. In addition, the
// copy and move constructors have a number of constraints supplied by
// the specification.
// Expected: The move constructor should default construct the moved-from object,
// while the new object should be identical to the original object.
TEST_CASE("move constructor is identical to moved from object before move") {
const auto parent = fsv::filtered_string_view{"parent string"};
auto copy = parent;
const auto move = std::move(copy);
REQUIRE(std::data(copy) == nullptr);
REQUIRE(copy == fsv::filtered_string_view{});
}
// Specification: 2.5.2 - Copy Assignment
// Purpose: Copy assignment should copy at least the length, data and predicate
// of other such that the they compare equal via operator==.
// Expected: The view targeted by the copy assignment should compare equal to
// the parent view.
// Notes: Copied from the specification, modified for catch2.
TEST_CASE("copy assignment passes equality comparison to parent object") {
const auto parent = fsv::filtered_string_view{"42 bro", [](const char& c) { return c == '4' || c == '2'; }};
auto copy = fsv::filtered_string_view{};
copy = parent;
REQUIRE(copy == parent);
}
// Specification: 2.5.2 - Copy Assignment
// Purpose: Copy assignment should not modify itself when self copied.
// Expected: Copy remains identical despite a self-copy.
TEST_CASE("copy assignment should not change object if self copied") {
auto parent = fsv::filtered_string_view{"42 bro", [](const char& c) { return c == '4' || c == '2'; }};
const auto copy = parent; // We copy here so we keep the previous information.
parent = parent;
REQUIRE(copy == parent);
}
// Specification 2.5.3 - Move Assignment
// Purpose: A moved from object should be left in a valid state equal to a
// default constructed view. In addition, the move should move the
// contents of the old view to the new view.
// Expected: The moved from object is default constructed, while the new object
// should be identical to the parent view.
TEST_CASE("move assignment should transfer contents and default construct moved") {
auto parent = fsv::filtered_string_view{"'89 baby", [](const char& c) { return c == '8' || c == '9'; }};
// Copy parent before the move so we can check the move consists of this.
const auto copy = parent;
auto move = fsv::filtered_string_view{};
move = std::move(parent);
REQUIRE(std::data(move) == std::data(copy));
REQUIRE(move == copy);
REQUIRE(std::size(move) == std::size(copy));
// Ensure default construction.
REQUIRE(std::size(parent) == 0);
REQUIRE(std::data(parent) == nullptr);
}
// Specification 2.5.3 - Move Assignment
// Purpose: Move assignment should not modify itself when self moved.
// Expected: Move remains identical despite a self-move.
TEST_CASE("move assignment should not change object if self copied") {
auto parent = fsv::filtered_string_view{"42 bro", [](const char& c) { return c == '4' || c == '2'; }};
const auto copy = parent; // We copy here so we keep the previous information.
parent = std::move(parent);
REQUIRE(copy == parent);
}
// Specification 2.5.4 - Subscript
// Purpose: Test if we can read the string given a specific subscript. We supply
// a predicate which filters some data so we can read into a view.
// Expected: The subscript is equal to the expected characters, filtering out
// those defined by the predicate.
TEST_CASE("subscript should be affected by view predicate") {
const auto parent = fsv::filtered_string_view("123", [](const char& c) { return c != '2'; });
REQUIRE(parent[0] == '1');
REQUIRE(parent[1] == '3');
}
// Specification 2.5.5 - String Type Conversion
// Purpose: We should be able to convert a view back into a string. Filtered out
// data should be removed, as if we were looking at the view.
// Expected: The view converted into a string should return a string affected by
// the predicate.
TEST_CASE("string conversion should be affected by view predicate") {
const auto parent = fsv::filtered_string_view{"123", [](const char& c) { return c != '2'; }};
REQUIRE(static_cast<std::string>(parent) == "13");
}
// Specification 2.5.5 - String Type Conversion
// Purpose: A string conversion should be a copy of the underlying data.
// Expected: The data pointer to the view should be different to the new string.
TEST_CASE("string conversion should return a new string") {
const auto parent = fsv::filtered_string_view{"123", [](const char& c) { return c != '2'; }};
const auto s = static_cast<std::string>(parent);
REQUIRE(std::data(s) != std::data(parent));
}
// Specification: 2.6.1 - At
// Purpose: At performs bounds checking of a filtered string. We ensure at performs
// identically to subscript operators, unless we read out of bounds, in
// which case it throws.
// Expected: The view should return expected at results, similar to subscript.
TEST_CASE("at should be affected by view predicate") {
const auto parent = fsv::filtered_string_view{"123", [](const char& c) { return c != '2'; }};
REQUIRE(parent.at(0) == '1');
REQUIRE(parent.at(1) == '3');
}
// Specification: 2.6.1 - At
// Purpose: At should throw on an out of bounds read, negative or positive, with
// a specific message and std::domain_error.
// Expected: The view should throw if we read outside of size().
TEST_CASE("at should throw on out of bounds reads") {
const auto parent = fsv::filtered_string_view{"123", [](const char& c) { return c != '2'; }};
REQUIRE_THROWS_AS(parent.at(-1), std::domain_error);
REQUIRE_THROWS_WITH(parent.at(-1), "filtered_string_view::at(-1): invalid index");
REQUIRE_THROWS_WITH(parent.at(2), "filtered_string_view::at(2): invalid index");
REQUIRE_THROWS_AS(parent.at(2), std::domain_error);
}
// Specification: 2.6.2 - Size
// Purpose: Size should be equal to the size of the parent string with no pred.
// Expected: The string size should be equal to the view size with no predicate.
TEST_CASE("size should be equal to the parent string with no predicate") {
const auto parent = fsv::filtered_string_view{"Maltese"};
REQUIRE(std::size(parent) == 7);
}
// Specification: 2.6.2 - Size
// Purpose: Size should be equal to the size of the filtered string.
// Expected: The string size should be equal to the amount of times the predicate
// returned true for that parent string.
TEST_CASE("size should be affected by view predicate") {
const auto parent = fsv::filtered_string_view{"Maltese", [](const char& c) { return c == 'a' or c == 'e'; }};
REQUIRE(std::size(parent) == 3);
}
// Specification: 2.6.3 - Empty
// Purpose: Empty should return true when the size of the view is zero.
// Expected: An empty view should return true. A non-empty view should return
// false.
TEST_CASE("empty should return true when size is zero, and false when nonzero") {
REQUIRE(fsv::filtered_string_view{}.empty() == true);
REQUIRE(fsv::filtered_string_view{"1"}.empty() == false);
}
// Specification: 2.6.3 - Empty
// Purpose: Empty should return true when the view with predicate results in an
// empty string.
// Expected: The 'viewed' string with a false predicate should always return true.
TEST_CASE("empty should return true when predicate filters all characters") {
const auto parent = fsv::filtered_string_view{"non_empty", [](const char&) { return false; }};
REQUIRE(parent.size() == 0);
REQUIRE(parent.empty() == true);
}
// Specification: 2.6.3 - Data
// Purpose: Data should return the owned string, without an affected filter.
// Expected: The data of a string view should not be affected by the predicate,
// so should be equal to the parent string despite the predicate.
TEST_CASE("data should not be affected by the predicate") {
const auto parent = std::string{"chars"};
const auto view = fsv::filtered_string_view{parent, [](const char&) { return false; }};
REQUIRE(std::string{std::data(view)} == parent);
}
// Specification: 2.6.3 - Predicate
// Purpose: The predicate method should return the predicate passed in any
// constructor.
// Expected: The effects of a function should passed to the view should be made
// when calling the function provided by the predicate method.
TEST_CASE("predicate returns the same function during construction") {
int count = 0;
const auto view = fsv::filtered_string_view{"", [&](const char&) {
++count;
return true;
}};
// We don't know how many times predicate calls the original function, so we
// store the result of count after the constructor.
const auto before_call = count;
view.predicate()(char{});
REQUIRE(before_call + 1 == count);
}
// Specification: 2.7.1 - Equality Comparison
// Purpose: Ensure that the predicate affects the result of the equality
// comparison.
// Expected: Equality should be true when the predicate results in two
// functionally identical views of strings regardless of its data.
TEST_CASE("equality comparison is true when affected by predicate") {
const auto view1 = fsv::filtered_string_view{"bca", [](const char& c) { return c == 'a'; }};
const auto view2 = fsv::filtered_string_view{"abc", [](const char& c) { return c == 'a'; }};
REQUIRE(view1 == view2);
}
// Specification: 2.7.1 - Equality Comparison
// Purpose: Ensure that the predicate affects the result of the equality
// comparison.
// Expected: Equality should be false when the predicate differs on the same
// string and produces different results through the view.
TEST_CASE("equality comparison is false when affected by predicate") {
const auto parent = std::string{"abc"};
const auto view1 = fsv::filtered_string_view{parent, [](const char& c) { return c == 'a'; }};
const auto view2 = fsv::filtered_string_view{parent, [](const char& c) { return c == 'b'; }};
REQUIRE(not(view1 == view2));
}
// Specification: 2.7.1 - Equality Comparison
// Purpose: Ensure that inequality functions as expected.
// Expected: Equality should be the inverse of inequality.
TEST_CASE("inequality is the inverse of equality") {
const auto view1 = fsv::filtered_string_view{"bca", [](const char& c) { return c == 'a'; }};
const auto view2 = fsv::filtered_string_view{"abc", [](const char& c) { return c == 'a'; }};
REQUIRE(view1 == view2);
REQUIRE(not(view1 != view2));
}
// Specification: 2.7.2 - Relational Comparison
// Purpose: Ensure that relational comparisons functions as expected.
// Expected: Relational comparisons should be logically consistent.
// Note: Test copied from the specification, modified for catch2.
TEST_CASE("relational comparison is logically consistent") {
const auto lo = fsv::filtered_string_view{"aaa"};
const auto hi = fsv::filtered_string_view{"zzz"};
REQUIRE(lo < hi);
REQUIRE(lo <= hi);
REQUIRE(not(lo > hi));
REQUIRE(not(lo >= hi));
REQUIRE(lo <=> hi == std::strong_ordering::less);
}
// Specification: 2.7.2 - Relational Comparison
// Purpose: Ensure that relational comparisons functions are affected by the
// predicate.
// Expected: Relational comparisons should use the result of the view, not the
// source string.
TEST_CASE("relational comparison is affected by predicate") {
const auto lo = fsv::filtered_string_view{"za", [](const auto& c) { return c != 'z'; }};
const auto hi = fsv::filtered_string_view{"az", [](const auto& c) { return c != 'a'; }};
REQUIRE(lo < hi);
REQUIRE(lo <= hi);
REQUIRE(not(lo > hi));
REQUIRE(not(lo >= hi));
REQUIRE(lo <=> hi == std::strong_ordering::less);
}
// Specification: 2.7.3 - Output Stream
// Purpose: Ensure the filtered string outputs to a stream and is filtered by
// the predicate.
// Expected: The output stream filters the underlying data.
TEST_CASE("output stream is affected by predicate") {
const auto view = fsv::filtered_string_view{"output!", [](const auto& c) { return c != 't'; }};
auto stream = std::stringstream{};
stream << view;
REQUIRE(std::string{stream.str()} == "oupu!");
}
// Specification: 2.8.1 - Compose
// Purpose: Ensure that compose results in the logical AND expression equivalent
// defined in the specification.
// Expected: The result of multiple predicates are applied and only those which
// return true for all provided predicates are viewed in the
// underlying filter.
// Notes: Taken from the specification, modified for catch2.
TEST_CASE("compose functions as logical AND expression for predicates") {
const auto best_languages = fsv::filtered_string_view{"c / c++"};
const auto vf = std::vector<fsv::filter>{[](const char& c) { return c == 'c' || c == '+' || c == '/'; },
[](const char& c) { return c > ' '; },
[](const char&) { return true; }};
const auto sv = fsv::compose(best_languages, vf);
REQUIRE(std::string{sv} == "c/c++");
}
// Specification 2.8.2 - Split
// Purpose: Ensure that split conforms to the specification (similar to
// python3's string split).
// Expected: The delimiter should not appear in any of the split views.
// Note: Test from specification, modified for catch2.
TEST_CASE("split does not include delimiters") {
const auto view = fsv::filtered_string_view{"0xDEADBEEF / 0xdeadbeef"};
const auto token = fsv::filtered_string_view{" / "};
const auto result = fsv::split(view, token);
REQUIRE(result == std::vector<fsv::filtered_string_view>{"0xDEADBEEF", "0xdeadbeef"});
}
// Specification 2.8.2 - Split
// Purpose: Ensure that split conforms to the specification (similar to
// python3's string split).
// Expected: The delimiter should produce empty strings when no characters appear
// before or after it.
// Note: Test from specification, modified for catch2.
TEST_CASE("split produces empty strings when around lone delimiters") {
const auto view = fsv::filtered_string_view{"xax"};
const auto token = fsv::filtered_string_view{"x"};
const auto result = fsv::split(view, token);
REQUIRE(result == std::vector<fsv::filtered_string_view>{"", "a", ""});
}
// Specification 2.8.2 - Split
// Purpose: Ensure that split conforms to the specification (similar to
// python3's string split).
// Expected: The delimiter should produce empty strings when only delimiters
// are present.
// Note: Test from specification, modified for catch2.
TEST_CASE("split produces multiple empty strings around only delimiters") {
const auto view = fsv::filtered_string_view{"xx"};
const auto token = fsv::filtered_string_view{"x"};
const auto result = fsv::split(view, token);
REQUIRE(result == std::vector<fsv::filtered_string_view>{"", "", ""});
}
// Specification 2.8.2 - Split
// Purpose: Ensure that split conforms to the specification (IDENTICAL to
// python3's string split). We test multiple edge cases here, with
// multiple delimiters on the outside and inside to ensure we conform.
// Expected: The output should match the python3 equivalent split function.
TEST_CASE("split functions as expected multiple delimiters") {
const auto view = fsv::filtered_string_view{"a a Complicated Split Many Tokens among this stringa haha"};
const auto token = fsv::filtered_string_view{"a"};
const auto result = fsv::split(view, token);
const auto expected = std::vector<fsv::filtered_string_view>{"",
" ",
" Complic",
"ted Split M",
"ny Tokens ",
"mong this string",
" h",
"h",
""};
REQUIRE(result == expected);
}
// Specification 2.8.3 - Substr
// Purpose: Ensure that substr conforms to the specification.
// Expected: The substring should split the view as if an offeset was provided
// to the original string.
// Note: Test from specification, modified for catch2.
TEST_CASE("substr splits at correct offset") {
const auto view = fsv::filtered_string_view{"Siberian Husky"};
REQUIRE(fsv::substr(view, 9) == "Husky");
}
// Specification 2.8.3 - Substr
// Purpose: Ensure that substr conforms to the specification.
// Expected: The substring should split the view as if an offeset was provided
// to the original string.
// Note: Test from specification, modified for catch2.
TEST_CASE("substr respects view predicate") {
const auto view =
fsv::filtered_string_view{"Sled Dog", [](const auto& c) { return std::isupper(static_cast<unsigned char>(c)); }};
REQUIRE(fsv::substr(view, 0, 2) == "SD");
}
// Specification 2.8.3 - Substr
// Purpose: Ensure that substr conforms to the specification.
// Expected: The substring should produce an empty string when provided with
// zero as a length argument.
TEST_CASE("substr produces an empty string with zero length") {
const auto view = fsv::filtered_string_view{"length zero", [](const auto&) { return false; }};
REQUIRE(fsv::substr(view, 0) == "");
}
// Specification: 2.9 - Iterator
// Purpose: Ensure the iterator functions correctly on an empty view.
// Expected: A std::copy of the empty view should result in an empty string.
TEST_CASE("forward iterators function on empty views") {
const auto view = fsv::filtered_string_view{};
auto str = std::string{};
std::copy(std::begin(view), std::end(view), std::back_inserter(str));
REQUIRE(str == "");
}
// Specification: 2.9 - Iterator
// Purpose: Ensure we have access to a valid iterator which conforms to the
// standard. Cend and Cbegin should also be available and identical to
// the standard non-const iterator.
// Expected: A std::copy of the view should remain equal to the underlying
// string, given the predicate does not modify its output.
TEST_CASE("forward iterators function as expected") {
const auto view = fsv::filtered_string_view{"iterator"};
auto str = std::string{};
std::copy(std::begin(view), std::end(view), std::back_inserter(str));
REQUIRE(str == "iterator");
str.clear();
std::copy(std::cbegin(view), std::cend(view), std::back_inserter(str));
REQUIRE(str == "iterator");
}
// Specification: 2.9 - Iterator
// Purpose: Ensure we have access to a valid iterator which conforms to the
// standard. Cend and cbegin should also be available.
// Expected: A std::copy should copy the underlying string filter.
TEST_CASE("forward iterator is affected by predicate") {
const auto view = fsv::filtered_string_view{"iterator", [](const auto& c) { return c != 'r'; }};
auto str = std::string{};
std::copy(std::begin(view), std::end(view), std::back_inserter(str));
REQUIRE(str == "iteato");
str.clear();
std::copy(std::cbegin(view), std::cend(view), std::back_inserter(str));
REQUIRE(str == "iteato");
}
// Specification: 2.10 - Range
// Purpose: Ensure our iterator functions as a bidirectional range.
// Expected: A std::copy of a backwards iterator produces the view in reverse
// of the begin iterators.
TEST_CASE("bidirectional iterators function as expected") {
const auto view = fsv::filtered_string_view{"iterator"};
auto str = std::string{};
std::copy(std::rbegin(view), std::rend(view), std::back_inserter(str));
REQUIRE(str == "rotareti");
str.clear();
std::copy(std::crbegin(view), std::crend(view), std::back_inserter(str));
REQUIRE(str == "rotareti");
}
// Specification: 2.10 - Range
// Purpose: Ensure our iterator functions as a bidirectional range with respect
// to the provided predicate.
// Expected: A std::copy of a backwards iterator produces the view in reverse
// of the begin iterators, including the affects of the predicate.
TEST_CASE("bidirectional iterators are affected by predicate.") {
const auto view = fsv::filtered_string_view{"iterator", [](const auto& c) { return c != 'r'; }};
auto str = std::string{};
std::copy(std::rbegin(view), std::rend(view), std::back_inserter(str));
REQUIRE(str == "otaeti");
str.clear();
std::copy(std::crbegin(view), std::crend(view), std::back_inserter(str));
REQUIRE(str == "otaeti");
}
|