// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2025 lacklustr@protonmail.com https://github.com/eadf
// This file is part of the hronn crate.

use super::*;
use std::io::Cursor;
use vector_traits::glam::DVec3;

#[test]
fn test_simple_triangle_obj() {
    let obj_content = "o TestObject
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 0.0 1.0 0.0
f 1 2 3";

    let obj = Obj::<DVec3>::new_from_reader(Cursor::new(obj_content), None::<String>).unwrap();

    assert_eq!(obj.name, "TestObject");
    assert_eq!(obj.vertices.len(), 3);
    assert_eq!(obj.indices, vec![0, 1, 2]);
    assert_eq!(obj.lines.len(), 0);
}

#[test]
fn test_obj_with_lines() {
    let obj_content = "o LineTest
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 2.0 0.0 0.0
l 1 2
l 2 3";

    let obj = Obj::<DVec3>::new_from_reader(Cursor::new(obj_content), None::<String>).unwrap();

    assert_eq!(obj.name, "LineTest");
    assert_eq!(obj.vertices.len(), 3);
    assert_eq!(obj.indices.len(), 0);
    assert_eq!(obj.lines.len(), 2);
    assert_eq!(obj.lines[0], vec![0, 1]);
    assert_eq!(obj.lines[1], vec![1, 2]);
}

#[test]
fn test_obj_with_polyline() {
    let obj_content = "o PolylineTest
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 2.0 0.0 0.0
v 3.0 0.0 0.0
l 1 2 3 4";

    let obj = Obj::<DVec3>::new_from_reader(Cursor::new(obj_content), None::<String>).unwrap();

    assert_eq!(obj.name, "PolylineTest");
    assert_eq!(obj.vertices.len(), 4);
    assert_eq!(obj.indices.len(), 0);
    assert_eq!(obj.lines.len(), 1);
    assert_eq!(obj.lines[0], vec![0, 1, 2, 3]);
}

#[test]
fn test_obj_with_face_to_line_conversion() {
    let obj_content = "o FaceToLineTest
v 0.0 0.0 0.0
v 1.0 0.0 0.0
f 1 2";

    let obj = Obj::<DVec3>::new_from_reader(Cursor::new(obj_content), None::<String>).unwrap();

    assert_eq!(obj.name, "FaceToLineTest");
    assert_eq!(obj.vertices.len(), 2);
    assert_eq!(obj.indices.len(), 0);
    assert_eq!(obj.lines.len(), 1);
    assert_eq!(obj.lines[0], vec![0, 1]);
}
