//! Test for issue #1791 - Failure when struct has more than 64 fields
//!
//! The ISet type used a u64 to track field initialization, limiting structs
//! to 64 fields. This test ensures the fix allows structs with any number
//! of fields.

use facet::Facet;
use facet_testhelpers::test;

/// Struct with 89 fields - matching the issue report
#[derive(Debug, PartialEq, Facet)]
pub struct Big {
    pub field1: String,
    pub field2: String,
    pub field3: String,
    pub field4: String,
    pub field5: String,
    pub field6: String,
    pub field7: String,
    pub field8: String,
    pub field9: String,
    pub field10: String,
    pub field11: String,
    pub field12: String,
    pub field13: String,
    pub field14: String,
    pub field15: String,
    pub field16: String,
    pub field17: String,
    pub field18: String,
    pub field19: String,
    pub field20: String,
    pub field21: String,
    pub field22: String,
    pub field23: String,
    pub field24: String,
    pub field25: String,
    pub field26: String,
    pub field27: String,
    pub field28: String,
    pub field29: String,
    pub field30: String,
    pub field31: String,
    pub field32: String,
    pub field33: String,
    pub field34: String,
    pub field35: String,
    pub field36: String,
    pub field37: String,
    pub field38: String,
    pub field39: String,
    pub field40: String,
    pub field41: String,
    pub field42: String,
    pub field43: String,
    pub field44: String,
    pub field45: String,
    pub field46: String,
    pub field47: String,
    pub field48: String,
    pub field49: String,
    pub field50: String,
    pub field51: String,
    pub field52: String,
    pub field53: String,
    pub field54: String,
    pub field55: String,
    pub field56: String,
    pub field57: String,
    pub field58: String,
    pub field59: String,
    pub field60: String,
    pub field61: String,
    pub field62: String,
    pub field63: String,
    pub field64: String,
    pub field65: String,
    pub field66: String,
    pub field67: String,
    pub field68: String,
    pub field69: String,
    pub field70: String,
    pub field71: String,
    pub field72: String,
    pub field73: String,
    pub field74: String,
    pub field75: String,
    pub field76: String,
    pub field77: String,
    pub field78: String,
    pub field79: String,
    pub field80: String,
    pub field81: String,
    pub field82: String,
    pub field83: String,
    pub field84: String,
    pub field85: String,
    pub field86: String,
    pub field87: String,
    pub field88: String,
    pub field89: String,
}

fn make_big() -> Big {
    Big {
        field1: "v1".to_string(),
        field2: "v2".to_string(),
        field3: "v3".to_string(),
        field4: "v4".to_string(),
        field5: "v5".to_string(),
        field6: "v6".to_string(),
        field7: "v7".to_string(),
        field8: "v8".to_string(),
        field9: "v9".to_string(),
        field10: "v10".to_string(),
        field11: "v11".to_string(),
        field12: "v12".to_string(),
        field13: "v13".to_string(),
        field14: "v14".to_string(),
        field15: "v15".to_string(),
        field16: "v16".to_string(),
        field17: "v17".to_string(),
        field18: "v18".to_string(),
        field19: "v19".to_string(),
        field20: "v20".to_string(),
        field21: "v21".to_string(),
        field22: "v22".to_string(),
        field23: "v23".to_string(),
        field24: "v24".to_string(),
        field25: "v25".to_string(),
        field26: "v26".to_string(),
        field27: "v27".to_string(),
        field28: "v28".to_string(),
        field29: "v29".to_string(),
        field30: "v30".to_string(),
        field31: "v31".to_string(),
        field32: "v32".to_string(),
        field33: "v33".to_string(),
        field34: "v34".to_string(),
        field35: "v35".to_string(),
        field36: "v36".to_string(),
        field37: "v37".to_string(),
        field38: "v38".to_string(),
        field39: "v39".to_string(),
        field40: "v40".to_string(),
        field41: "v41".to_string(),
        field42: "v42".to_string(),
        field43: "v43".to_string(),
        field44: "v44".to_string(),
        field45: "v45".to_string(),
        field46: "v46".to_string(),
        field47: "v47".to_string(),
        field48: "v48".to_string(),
        field49: "v49".to_string(),
        field50: "v50".to_string(),
        field51: "v51".to_string(),
        field52: "v52".to_string(),
        field53: "v53".to_string(),
        field54: "v54".to_string(),
        field55: "v55".to_string(),
        field56: "v56".to_string(),
        field57: "v57".to_string(),
        field58: "v58".to_string(),
        field59: "v59".to_string(),
        field60: "v60".to_string(),
        field61: "v61".to_string(),
        field62: "v62".to_string(),
        field63: "v63".to_string(),
        field64: "v64".to_string(),
        field65: "v65".to_string(),
        field66: "v66".to_string(),
        field67: "v67".to_string(),
        field68: "v68".to_string(),
        field69: "v69".to_string(),
        field70: "v70".to_string(),
        field71: "v71".to_string(),
        field72: "v72".to_string(),
        field73: "v73".to_string(),
        field74: "v74".to_string(),
        field75: "v75".to_string(),
        field76: "v76".to_string(),
        field77: "v77".to_string(),
        field78: "v78".to_string(),
        field79: "v79".to_string(),
        field80: "v80".to_string(),
        field81: "v81".to_string(),
        field82: "v82".to_string(),
        field83: "v83".to_string(),
        field84: "v84".to_string(),
        field85: "v85".to_string(),
        field86: "v86".to_string(),
        field87: "v87".to_string(),
        field88: "v88".to_string(),
        field89: "v89".to_string(),
    }
}

#[test]
fn test_roundtrip_89_fields() {
    let big = make_big();
    let big_json = facet_json::to_string(&big).unwrap();
    let big_back: Big = super::json_backend::from_str(&big_json).unwrap();
    assert_eq!(big, big_back);
}

#[test]
fn test_serialize_89_fields() {
    let big = make_big();
    let big_json = facet_json::to_string(&big).unwrap();
    // Sanity check that the JSON contains some of our fields
    assert!(big_json.contains("\"field1\":\"v1\""));
    assert!(big_json.contains("\"field64\":\"v64\""));
    assert!(big_json.contains("\"field65\":\"v65\""));
    assert!(big_json.contains("\"field89\":\"v89\""));
}
