use mount_fstab::fstype::FsType;

#[test]
fn parse_simple() {
    let ft = FsType::parse("ext4").unwrap();
    assert_eq!(ft.as_str(), "ext4");
    assert!(!ft.is_swap());
    assert!(!ft.is_bind());
}

#[test]
fn parse_swap() {
    let ft = FsType::parse("swap").unwrap();
    assert!(ft.is_swap());
}

#[test]
fn parse_none_for_bind() {
    let ft = FsType::parse("none").unwrap();
    assert!(ft.is_bind());
}

#[test]
fn parse_with_subtype() {
    let ft = FsType::parse("fuse.sshfs").unwrap();
    assert_eq!(ft.primary(), "fuse");
    assert_eq!(ft.as_str(), "fuse.sshfs");
}

#[test]
fn parse_type_list() {
    let ft = FsType::parse("nfs,ext4").unwrap();
    assert_eq!(ft.primary(), "nfs");
    let types: Vec<&str> = ft.iter().collect();
    assert_eq!(types, vec!["nfs", "ext4"]);
}

#[test]
fn is_network() {
    assert!(FsType::parse("nfs").unwrap().is_network());
    assert!(FsType::parse("nfs4").unwrap().is_network());
    assert!(FsType::parse("cifs").unwrap().is_network());
    assert!(FsType::parse("smb").unwrap().is_network());
    assert!(!FsType::parse("ext4").unwrap().is_network());
    assert!(!FsType::parse("xfs").unwrap().is_network());
}

#[test]
fn is_pseudo() {
    assert!(FsType::parse("proc").unwrap().is_pseudo());
    assert!(FsType::parse("sysfs").unwrap().is_pseudo());
    assert!(FsType::parse("tmpfs").unwrap().is_pseudo());
    assert!(FsType::parse("devpts").unwrap().is_pseudo());
    assert!(FsType::parse("cgroup2").unwrap().is_pseudo());
    assert!(!FsType::parse("ext4").unwrap().is_pseudo());
}

#[test]
fn parse_empty_is_error() {
    assert!(FsType::parse("").is_err());
}

#[test]
fn swap_constructor() {
    assert_eq!(FsType::swap().as_str(), "swap");
}

#[test]
fn bind_constructor() {
    assert_eq!(FsType::bind().as_str(), "none");
}

#[test]
fn parse_auto_type() {
    let ft = FsType::parse("auto").unwrap();
    assert_eq!(ft.as_str(), "auto");
}

#[test]
fn parse_ignore_is_not_swap() {
    // "ignore" is deprecated but parseable
    let ft = FsType::parse("ignore").unwrap();
    assert!(!ft.is_swap());
    assert!(!ft.is_bind());
}

#[test]
fn parse_ntfs_type() {
    let ft = FsType::parse("ntfs").unwrap();
    assert_eq!(ft.primary(), "ntfs");
    assert!(!ft.is_pseudo());
    assert!(!ft.is_network());
}

#[test]
fn parse_btrfs_type() {
    let ft = FsType::parse("btrfs").unwrap();
    assert_eq!(ft.primary(), "btrfs");
}

#[test]
fn parse_xfs_type() {
    let ft = FsType::parse("xfs").unwrap();
    assert_eq!(ft.primary(), "xfs");
}

#[test]
fn is_network_checks_primary_only() {
    // "nfs4,ext4" → primary is "nfs4" → is_network() true
    let ft = FsType::parse("nfs4,ext4").unwrap();
    assert!(ft.is_network());
}

#[test]
fn parse_three_type_list() {
    let ft = FsType::parse("ext4,ext3,ext2").unwrap();
    let types: Vec<&str> = ft.iter().collect();
    assert_eq!(types, vec!["ext4", "ext3", "ext2"]);
}

#[test]
fn parse_subtype_deep() {
    // Just one dot for subtype per spec
    let ft = FsType::parse("fuse.sshfs").unwrap();
    assert_eq!(ft.primary(), "fuse");
}

#[test]
fn display() {
    assert_eq!(FsType::parse("ext4").unwrap().to_string(), "ext4");
    assert_eq!(
        FsType::parse("fuse.sshfs").unwrap().to_string(),
        "fuse.sshfs"
    );
}
