// License: see LICENSE file at root directory of `master` branch

use core::convert::TryFrom;

use std::collections::HashSet;

use sub_strs::CainStr;

#[test]
fn test_cain_str() {
    const FISRT: &str = "FiRsT";
    const SECOND: &str = "sEcOnD";
    const THIRD: &str = "THIRD";
    const FAKE: &str = "third";
    const STRS: &[&str] = &[FISRT, SECOND, THIRD, FAKE];

    let mut set: HashSet<CainStr> = HashSet::new();
    for s in STRS {
        let cain_str = CainStr::from(*s);
        assert_eq!(cain_str, CainStr::from(s.to_uppercase()));
        assert_eq!(cain_str, CainStr::from(s.to_lowercase()));
        set.insert(cain_str);
    }

    let mut vec: Vec<_> = set.into_iter().collect();
    vec.sort();
    let mut iter = vec.into_iter().map(|cain_str| <&str>::try_from(cain_str).unwrap());
    assert_eq!(iter.next().unwrap(), FISRT);
    assert_eq!(iter.next().unwrap(), SECOND);
    assert!([THIRD, FAKE].contains(&iter.next().unwrap()));
    assert!(iter.next().is_none());
}
