use myc::ast::compiler::CompilationResult; use myc::ast::diagnostics::Diagnostics; use myc::ast::environment::Environment; // --- Diagnostics::format_errors() --- #[test] fn format_errors_empty() { let diag = Diagnostics::new(); assert_eq!(diag.format_errors(), ""); } #[test] fn format_errors_single() { let mut diag = Diagnostics::new(); diag.push_error("type mismatch", None); assert_eq!(diag.format_errors(), "type mismatch"); } #[test] fn format_errors_multiple_joined_with_newline() { let mut diag = Diagnostics::new(); diag.push_error("first error", None); diag.push_error("second error", None); assert_eq!(diag.format_errors(), "first error\nsecond error"); } #[test] fn format_errors_ignores_warnings_and_hints() { let mut diag = Diagnostics::new(); diag.push_warning("just a warning", None); diag.push_hint("a hint", None); diag.push_error("the real error", None); // Only the error should appear assert_eq!(diag.format_errors(), "the real error"); } // --- CompilationResult --- #[test] fn compilation_result_error_into_err() { let result = CompilationResult::error("something went wrong"); let err = result.into_result(); assert!(err.is_err()); assert_eq!(err.unwrap_err(), "something went wrong"); } #[test] fn compilation_result_success_into_ok() { // The success() constructor requires a TypedNode, which is produced by // the compiler. We verify the happy path via a minimal compile round-trip. let env = Environment::new(); let result = env.compile("(+ 1 2)"); assert!(!result.diagnostics.has_errors(), "unexpected errors: {}", result.diagnostics.format_errors()); assert!(result.into_result().is_ok()); }