diff --git a/empty_name_triangle.obj b/empty_name_triangle.obj new file mode 100644 index 0000000..fd65609 --- /dev/null +++ b/empty_name_triangle.obj @@ -0,0 +1,6 @@ +# A simple triangle object for testing +v 0 0 0 +v 1 0 0 +v 0 1 0 + +f -3 -2 -1 diff --git a/tests/lib.rs b/tests/lib.rs index 378c94a..b5939d9 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -33,6 +33,30 @@ fn simple_triangle() { assert_eq!(mesh.indices, expect_idx); } +#[test] +fn empty_name_triangle() { + let m = tobj::load_obj(&Path::new("empty_name_triangle.obj")); + assert!(m.is_ok()); + let (models, mats) = m.unwrap(); + // We expect a single model with no materials + assert_eq!(models.len(), 1); + assert!(mats.is_empty()); + // Confirm our triangle is loaded correctly + assert_eq!(models[0].name, "unnamed_object"); + let mesh = &models[0].mesh; + assert!(mesh.normals.is_empty()); + assert!(mesh.texcoords.is_empty()); + assert_eq!(mesh.material_id, None); + + // Verify each position is loaded properly + let expect_pos = vec![0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]; + assert_eq!(mesh.positions, expect_pos); + // Verify the indices are loaded properly + let expect_idx = vec![0, 1, 2]; + assert_eq!(mesh.indices, expect_idx); +} + + #[test] fn multiple_face_formats() { let m = tobj::load_obj(&Path::new("quad.obj"));