use super::*;

#[test]
fn load_file() {
    assert!(!GsblTable::parse_file("tests/example.gsbl").is_err(), "File 'tests/example.gsbl' should be able to load");
}

#[test]
fn rise_and_shine() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    assert_eq!(file.get_string("hello_world"), Some("hello, world!".to_string()), "'tests/example.gsbl': Variable 'hello_world' should contain a string 'hello, world!'");
    assert_eq!(file.get_string("also_valid"), Some("hello, world!".to_string()), "'tests/example.gsbl': Variable 'also_valid' should contain a string 'hello, world!'");
}

#[test]
fn tables() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    let cool_table = file.get_table("cool_table").unwrap();
    let is_this_an_array = cool_table.get_table("is_this_an_array").unwrap();
    assert_eq!(is_this_an_array.get_string("no").unwrap(), "no".to_string(), "\"tests/example.gsbl\": Variable 'no' inside of the nested table 'is_this_an_array' should 
        contain the string 'no'");
}

#[test]
fn integers() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    let cool_table = file.get_table("cool_table").unwrap();
    assert_eq!(cool_table.get_int("series_of_skibidi_toilet_watched"), Some(723), "'tests/example.gsbl': Variable 'series_of_skibidi_toilet_watched' 
        (i'm sorry) should contain an integer 723");
}

#[test]
fn floats() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    let cool_table = file.get_table("cool_table").unwrap();
    assert_eq!(cool_table.get_float("pi_just_for_tests"), Some(3.141592), "tests/example.gsbl: Variable 'pi_just_for_tests' should contain 
        a floating point number 3.141592");
}

#[test]
fn arrays() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    let cool_table = file.get_table("cool_table").unwrap();
    assert_eq!(cool_table.get_string_array("favorite_episodes_of_st"), Some(vec!["all".to_string(), "of".to_string(), "them".to_string()]),
        "'tests/example.gsbl': Variable 'favorite_episodes_of_st' should contain the strings ['all', 'of', 'them']");
}

#[test]
fn booleans() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    let cool_table = file.get_table("cool_table").unwrap();
    assert_eq!(cool_table.get_bool("do_i_love_skibidi_sigma_gyatt"), Some(true),
        "'tests/example.gsbl': Variable 'do_i_love_skibidi_sigma_gyatt' (this is a stupid brainrot language, remember?)
        should contain a boolean 'true'");
}

#[test]
fn no_such_variable() {
    let file = GsblTable::parse_file("tests/example.gsbl").unwrap();
    assert!(file.get_bool("this_variable_doesnt_exist").is_none(),
        "'get_*' methods should return None when a variable of the requested type or name doesn't exist");
}

#[test]
fn malformed_code() {
    let file = GsblTable::parse_file("tests/malformed.gsbl");
    assert_eq!(file, Err(GsblError::MalformedCode("Unterminated table".to_string())),
        "'tests/malformed.gsbl': Table 'good_question' should be unterminated");
}

#[test]
fn empty() {
    let file = GsblTable::parse_file("tests/empty.gsbl");
    assert_eq!(file.unwrap().data, vec![], "'tests/empty.gsbl': File should not contain a main table, or if it does, it must not contain any variables");
}
