usaidwat 4.0.1

Answers the age-old question, "Where does a Redditor comment the most?"
Documentation
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
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2025 Michael Dippery <michael@monkey-robot.com>

//! General-purpose search utilities.

use crate::reddit::thing::HasSubreddit;
use regex::Regex;
use std::collections::HashSet;

/// A thing that can be searched.
pub trait Searchable {
    /// The haystack that can be searched for a needle.
    fn search_text(&self) -> String;

    /// True if the search pattern can be found in the [`Searchable::search_text()`].
    ///
    /// The search is case-insensitive.
    ///
    /// `pattern` can be a regular expression.
    fn matches(&self, pattern: impl AsRef<str>) -> bool {
        let pattern = pattern.as_ref();
        match Regex::new(&format!("(?i){pattern}")) {
            Ok(re) => re.is_match(&self.search_text()),
            Err(_) => self.search_text().contains(pattern),
        }
    }
}

/// A container for filtering Reddit things.
pub struct RedditFilter<I>
where
    I: Iterator,
    I::Item: Searchable + HasSubreddit,
{
    things: I,
}

impl<I> RedditFilter<I>
where
    I: Iterator,
    I::Item: Searchable + HasSubreddit,
{
    /// Creates a new `RedditFilter` that wraps the given iterator.
    pub fn new(things: I) -> Self {
        Self { things }
    }

    /// Returns the first n items.
    ///
    /// If `limit` is `None`, then all items are returned.
    pub fn take(self, limit: &Option<u32>) -> RedditFilter<impl Iterator<Item = I::Item>> {
        let things: Vec<I::Item> = match limit {
            None => self.things.collect(),
            Some(n) => self.things.take(*n as usize).collect(),
        };
        let things = things.into_iter();
        RedditFilter { things }
    }

    /// Returns all items with searchable text that matches the given needle.
    ///
    /// If `needle` is `None`, all items are returned.
    pub fn grep(self, needle: &Option<String>) -> RedditFilter<impl Iterator<Item = I::Item>> {
        let things: Vec<I::Item> = match needle {
            None => self.things.collect(),
            Some(needle) => self.things.filter(|thing| thing.matches(needle)).collect(),
        };
        let things = things.into_iter();
        RedditFilter { things }
    }

    /// Returns all items with subreddits matching the given set of subreddits.
    ///
    /// If `subreddits` is empty, all items are returned.
    pub fn filter(self, subreddits: &StringSet) -> RedditFilter<impl Iterator<Item = I::Item>> {
        let things: Vec<I::Item> = if subreddits.is_empty() {
            self.things.collect()
        } else {
            self.things
                .filter(|item| subreddits.contains(item.subreddit()))
                .collect()
        };
        let things = things.into_iter();

        RedditFilter { things }
    }

    /// Collects all items into a vector.
    pub fn collect(self) -> Vec<I::Item> {
        self.things.collect()
    }
}

/// A set of strings.
///
/// This set can function like a normal set, but it can also store _negated_
/// strings, meaning that [`StringSet::contains()`] will return `true` if the test
/// string is _not_ contained in the set.
#[derive(Debug)]
pub struct StringSet {
    kind: StringSetKind,
}

impl StringSet {
    /// Converts a list of strings into a `StringSet`.
    ///
    /// Strings can be negated by prefixing them with a `-`; for example,
    /// `-string` will match any needles that are _not_ `"string"`.
    ///
    /// All strings passed in must either be negated or not negated.
    /// If strings are mixed, `None` is returned.
    pub fn from<S>(strings: S) -> Option<Self>
    where
        S: IntoIterator,
        S::Item: AsRef<str>,
    {
        let validator = StringSetValidator::from(strings);

        if !validator.is_valid() {
            None
        } else {
            let all_positive = validator.all_positive();
            let set = validator.into_set();
            let kind = if all_positive {
                StringSetKind::Positive(set)
            } else {
                StringSetKind::Negative(set)
            };
            Some(Self { kind })
        }
    }

    /// True if the set contains the `needle`.
    ///
    /// If there are only non-negated strings in the set, this means that
    /// `needle` is a member of the set. If there are only _negated_ strings
    /// in the set, this means that `needle` is _not_ contained in the set.
    pub fn contains(&self, needle: impl AsRef<str>) -> bool {
        let needle = needle.as_ref();
        match &self.kind {
            StringSetKind::Negative(set) => !set.contains(&needle.to_lowercase()),
            StringSetKind::Positive(set) => set.contains(&needle.to_lowercase()),
        }
    }

    /// True if the set contains no items.
    pub fn is_empty(&self) -> bool {
        match &self.kind {
            StringSetKind::Negative(set) | StringSetKind::Positive(set) => set.is_empty(),
        }
    }

    /// True if the set contains _negated_ strings.
    ///
    /// As a set must contain only negated or only non-negated strings,
    /// this means that every single string in the set is negated if
    /// this method returns true; conversely, it means that no string
    /// in the set is negated if this method returns false.
    pub fn is_negated(&self) -> bool {
        self.kind.is_negated()
    }
}

/// Indicates whether a set is negated or not.
#[derive(Debug)]
enum StringSetKind {
    Positive(HashSet<String>),
    Negative(HashSet<String>),
}

impl StringSetKind {
    pub fn is_negated(&self) -> bool {
        matches!(self, StringSetKind::Negative(_))
    }
}

/// Processes a vector of strings into a flattened vector and checks
/// it for validity.
struct StringSetValidator {
    strings: Vec<String>,
}

impl StringSetValidator {
    /// Flattens a vector of strings and returns a new validator.
    ///
    /// Some or all of the elements of `strings` may be comma-separated;
    /// `new()` will flatten them into a single vector.
    pub fn from<S>(strings: S) -> Self
    where
        S: IntoIterator,
        S::Item: AsRef<str>,
    {
        let strings = strings
            .into_iter()
            .flat_map(|s| {
                s.as_ref()
                    .replace(" ", "")
                    .split(',')
                    .map(str::to_owned)
                    .collect::<Vec<String>>()
            })
            .collect();
        Self { strings }
    }

    /// Returns true if either:
    ///
    /// - All strings are positive (not prefixed with `-`)
    /// - All strings are negative (prefixed with `-`)
    pub fn is_valid(&self) -> bool {
        self.all_positive() || self.all_negative()
    }

    /// True if every string is prefixed with `-`.
    pub fn all_negative(&self) -> bool {
        self.strings.iter().all(|s| s.starts_with('-'))
    }

    /// True if none of the strings are prefixed with `-`.
    pub fn all_positive(&self) -> bool {
        self.strings.iter().all(|s| !s.starts_with('-'))
    }

    /// Converts the internally stored strings into a hash set, consuming
    /// the validator in the process.
    pub fn into_set(self) -> HashSet<String> {
        HashSet::from_iter(
            self.strings
                .into_iter()
                .map(|s| s.trim_start_matches('-').to_lowercase()),
        )
    }
}

#[cfg(test)]
mod tests {
    mod searchable {
        use super::super::*;

        #[derive(Default, Debug)]
        struct TestSearchable;

        impl Searchable for TestSearchable {
            fn search_text(&self) -> String {
                String::from("peter piper picked a peck of pickled peppers")
            }
        }

        #[test]
        fn it_returns_true_if_there_is_a_match() {
            let t = TestSearchable::default();
            assert!(t.matches("peppers"));
        }

        #[test]
        fn it_returns_true_if_there_are_multiple_matches() {
            let t = TestSearchable::default();
            assert!(t.matches("pick"));
        }

        #[test]
        fn it_matches_substrings() {
            let t = TestSearchable::default();
            assert!(t.matches("pip"));
        }

        #[test]
        fn it_matches_needles_with_spaces() {
            let t = TestSearchable::default();
            assert!(t.matches("picked a peck"));
        }

        #[test]
        fn it_returns_false_if_there_are_no_matches() {
            let t = TestSearchable::default();
            assert!(!t.matches("usaidwait"));
        }

        #[test]
        fn it_matches_regexes() {
            let t = TestSearchable::default();
            assert!(t.matches("pep{2,}ers"));
        }

        #[test]
        fn it_matches_regexes_case_insensitively() {
            let t = TestSearchable::default();
            assert!(t.matches("Piper"));
        }

        #[test]
        fn it_treats_invalid_regexes_as_a_fixed_string() {
            let t = TestSearchable::default();
            assert!(!t.matches("pic{?}kl**ed"));
        }

        #[test]
        fn it_takes_a_string() {
            let t = TestSearchable::default();
            let s = String::from("Piper");
            assert!(t.matches(s))
        }
    }

    mod reddit_filter {
        use super::super::*;

        #[derive(Debug)]
        struct TestSearchable {
            string: String,
            subreddit: String,
        }

        impl TestSearchable {
            pub fn new(string: &str, subreddit: &str) -> Self {
                TestSearchable {
                    string: String::from(string),
                    subreddit: String::from(subreddit),
                }
            }
        }

        impl Searchable for TestSearchable {
            fn search_text(&self) -> String {
                self.string.clone()
            }
        }

        impl HasSubreddit for TestSearchable {
            // Doesn't matter, not tested but required to meet trait constraints
            fn subreddit(&self) -> &str {
                self.subreddit.as_str()
            }
        }

        fn load_test() -> Vec<TestSearchable> {
            let strings = vec![
                (
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
                    "subreddit",
                ),
                ("In sodales urna et libero commodo varius.", "subreddit"),
                ("Morbi vitae varius orci.", "other"),
                ("Sed luctus turpis ac fringilla maximus.", "another"),
                (
                    "In libero nisl, condimentum in gravida eget, bibendum id lectus.",
                    "words",
                ),
                ("Nunc sit amet odio dolor.", "poetry"),
                ("Nunc quis urna vel sem iaculis dapibus.", "subreddit"),
                (
                    "Donec justo metus, vulputate a purus at, tincidunt porttitor erat.",
                    "blah",
                ),
                (
                    "Quisque in metus molestie, dictum metus nec, malesuada tortor.",
                    "foo",
                ),
                ("Nam sed turpis eu tortor semper rhoncus.", "bar"),
                (
                    "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
                    "baz",
                ),
            ];
            strings
                .iter()
                .map(|(s, sr)| TestSearchable::new(s, sr))
                .collect()
        }

        #[test]
        fn it_returns_the_first_n_items() {
            let texts = load_test();
            let limit = Some(3);
            let results = RedditFilter::new(texts.into_iter()).take(&limit);
            assert_eq!(results.collect().len(), 3);
        }

        #[test]
        fn it_returns_all_items_when_limit_is_none() {
            let texts = load_test();
            let n = texts.len();
            let limit = None;
            let results = RedditFilter::new(texts.into_iter()).take(&limit);
            assert_eq!(results.collect().len(), n);
        }

        #[test]
        fn it_returns_all_items_when_limit_exceeds_the_total_count() {
            let texts = load_test();
            let n = texts.len();
            let limit = Some(n as u32 + 1);
            let results = RedditFilter::new(texts.into_iter()).take(&limit);
            assert_eq!(results.collect().len(), n);
        }

        #[test]
        fn it_finds_items_matching_a_string() {
            let texts = load_test();
            let grep = Some(String::from("\\bnunc\\b"));
            let matches = RedditFilter::new(texts.into_iter()).grep(&grep);
            assert_eq!(matches.collect().len(), 2);
        }

        #[test]
        fn it_returns_everything_if_there_is_no_needle() {
            let texts = load_test();
            let n = texts.len();
            let grep = None;
            let matches = RedditFilter::new(texts.into_iter()).grep(&grep);
            assert_eq!(matches.collect().len(), n);
        }

        #[test]
        fn it_returns_nothing_if_there_are_no_matches() {
            let texts = load_test();
            let grep = Some(String::from("some text"));
            let matches = RedditFilter::new(texts.into_iter()).grep(&grep);
            assert_eq!(matches.collect().len(), 0);
        }

        #[test]
        fn it_returns_everything_if_subreddit_filter_is_empty() {
            let texts = load_test();
            let n = texts.len();
            let filter = StringSet::from(Vec::<String>::new())
                .expect("should create string set from empty vector");
            let filtered = RedditFilter::new(texts.into_iter()).filter(&filter);
            assert_eq!(filtered.collect().len(), n);
        }

        #[test]
        fn it_returns_a_subset_if_subreddit_filter_is_positive() {
            let texts = load_test();
            let n = texts
                .iter()
                .filter(|t| t.subreddit() == "subreddit")
                .count();
            let filter = StringSet::from(&vec!["subreddit", "doesnotexist"])
                .expect("should create string set from empty vector");
            let filtered = RedditFilter::new(texts.into_iter()).filter(&filter);
            assert_eq!(filtered.collect().len(), n);
        }

        #[test]
        fn it_returns_everything_if_subreddit_filter_is_negative() {
            let texts = load_test();
            let n = texts.len();
            let x = texts
                .iter()
                .filter(|t| t.subreddit() == "subreddit")
                .count();
            let filter = StringSet::from(&vec!["-subreddit", "-doesnotexist"])
                .expect("should create string set from empty vector");
            let filtered = RedditFilter::new(texts.into_iter()).filter(&filter);
            assert_eq!(filtered.collect().len(), n - x);
        }
    }

    mod string_set {
        use super::super::*;

        #[test]
        fn it_accepts_all_positive_strings() {
            let strings = vec!["alpha", "beta", "charlie", "delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_accepts_all_positive_comma_separated_strings() {
            let strings = vec!["alpha,beta,charlie,delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_accepts_all_positive_nested_strings() {
            let strings = vec!["alpha,beta", "charlie", "delta,echo,foxtrot", "golf"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_accepts_all_negative_strings() {
            let strings = vec!["-alpha", "-beta", "-charlie", "-delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_accepts_all_negative_comma_separated_strings() {
            let strings = vec!["-alpha,-beta,-charlie,-delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_accepts_all_negative_nested_strings() {
            let strings = vec!["-alpha,-beta", "-charlie", "-delta,-echo,-foxtrot", "-golf"];
            let set = StringSet::from(&strings);
            assert!(set.is_some());
        }

        #[test]
        fn it_rejects_mixed_strings() {
            let strings = vec!["alpha", "-beta", "-charlie", "delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_none());
        }

        #[test]
        fn it_rejects_mixed_comma_separated_strings() {
            let strings = vec!["-alpha,beta,-charlie,delta"];
            let set = StringSet::from(&strings);
            assert!(set.is_none());
        }

        #[test]
        fn it_rejects_mixed_nested_strings() {
            let strings = vec!["-alpha,-beta", "charlie", "delta,-echo,foxtrot", "-golf"];
            let set = StringSet::from(&strings);
            assert!(set.is_none());
        }

        #[test]
        fn it_returns_true_if_it_contains_negated_strings() {
            let strings = vec!["-alpha", "-beta", "-charlie", "-delta"];
            let set =
                StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
            assert!(set.is_negated());
        }

        #[test]
        fn it_returns_false_if_it_contains_positive_strings() {
            let strings = vec!["alpha", "beta", "charlie", "delta"];
            let set =
                StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
            assert!(!set.is_negated());
        }

        #[test]
        fn it_is_empty_if_it_contains_no_items() {
            let set =
                StringSet::from(Vec::<String>::new()).expect("should build set from empty vector");
            assert!(set.is_empty());
        }

        #[test]
        fn it_is_not_empty_if_it_contains_items() {
            let strings = vec!["alpha", "beta", "charlie", "delta"];
            let set =
                StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
            assert!(!set.is_empty());
        }

        mod when_positive {
            use super::super::super::*;

            #[test]
            fn it_accepts_a_string_in_the_set() {
                let strings = vec!["alpha,beta", "charlie", "delta,echo,foxtrot", "golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(set.contains("echo"));
            }

            #[test]
            fn it_accepts_a_string_in_the_set_case_insensitively() {
                let strings = vec!["Alpha,Beta", "Charlie", "Delta,Echo,Foxtrot", "golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(
                    set.contains("echo"),
                    "'echo' should be in {set:?}, but is not"
                );
            }

            #[test]
            fn it_rejects_a_string_not_in_the_set() {
                let strings = vec!["alpha,beta", "charlie", "delta,echo,foxtrot", "golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(!set.contains("romeo"));
            }

            #[test]
            fn it_takes_a_string_as_a_needle() {
                let strings = vec!["alpha,beta", "charlie", "delta,echo,foxtrot", "golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                let needle = String::from("romeo");
                assert!(!set.contains(needle));
            }
        }

        mod when_negative {
            use super::super::super::*;

            #[test]
            fn it_accepts_a_string_not_in_the_set() {
                let strings = vec!["-alpha,-beta", "-charlie", "-delta,-echo,-foxtrot", "-golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(set.contains("romeo"));
            }

            #[test]
            fn it_rejects_a_string_in_the_set() {
                let strings = vec!["-alpha,-beta", "-charlie", "-delta,-echo,-foxtrot", "-golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(
                    !set.contains("echo"),
                    "'echo' should not be in {set:?}, but is"
                );
            }

            #[test]
            fn it_rejects_a_string_in_the_set_case_insensitively() {
                let strings = vec!["-Alpha,-Beta", "-Charlie", "-Delta,-Echo,-Foxtrot", "-golf"];
                let set =
                    StringSet::from(&strings).expect(&format!("should build set from {strings:?}"));
                assert!(
                    !set.contains("echo"),
                    "'echo' should not be in {set:?}, but is"
                );
            }
        }
    }

    mod string_set_validator {
        use super::super::*;

        #[test]
        fn it_accepts_all_positive_strings() {
            let strings = vec!["alpha", "beta", "charlie", "delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(validator.all_positive());
            assert!(!validator.all_negative());
        }

        #[test]
        fn it_accepts_all_positive_comma_separated_strings() {
            let strings = vec!["alpha,beta,charlie,delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(validator.all_positive());
            assert!(!validator.all_negative());
        }

        #[test]
        fn it_accepts_all_positive_nested_strings() {
            let strings = vec!["alpha,beta", "charlie", "delta,echo,foxtrot", "golf"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(validator.all_positive());
            assert!(!validator.all_negative());
        }

        #[test]
        fn it_accepts_all_negative_strings() {
            let strings = vec!["-alpha", "-beta", "-charlie", "-delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(!validator.all_positive());
            assert!(validator.all_negative());
        }

        #[test]
        fn it_accepts_all_negative_comma_separated_strings() {
            let strings = vec!["-alpha,-beta,-charlie,-delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(!validator.all_positive());
            assert!(validator.all_negative());
        }

        #[test]
        fn it_accepts_all_negative_nested_strings() {
            let strings = vec!["-alpha,-beta", "-charlie", "-delta,-echo,-foxtrot", "-golf"];
            let validator = StringSetValidator::from(&strings);
            assert!(validator.is_valid());
            assert!(!validator.all_positive());
            assert!(validator.all_negative());
        }

        #[test]
        fn it_rejects_mixed_strings() {
            let strings = vec!["alpha", "-beta", "-charlie", "delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(!validator.is_valid());
            assert!(!validator.all_positive());
            assert!(!validator.all_negative());
        }

        #[test]
        fn it_rejects_mixed_comma_separated_strings() {
            let strings = vec!["-alpha,beta,-charlie,delta"];
            let validator = StringSetValidator::from(&strings);
            assert!(!validator.is_valid());
            assert!(!validator.all_positive());
            assert!(!validator.all_negative());
        }

        #[test]
        fn it_rejects_mixed_nested_strings() {
            let strings = vec!["-alpha,-beta", "charlie", "delta,-echo,foxtrot", "-golf"];
            let validator = StringSetValidator::from(&strings);
            assert!(!validator.is_valid());
            assert!(!validator.all_positive());
            assert!(!validator.all_negative());
        }
    }
}