import unittest

from audit_red_suite import parse_log


class AuditRedSuiteTests(unittest.TestCase):
    def test_parses_result_split_by_captured_output(self) -> None:
        audit = parse_log(
            """
test noisy ... diagnostic output
more diagnostic output
ok
test expected_panic ...
thread 'expected_panic' panicked at test.rs:1:1:
expected panic
ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
"""
        )
        self.assertEqual(audit.passed_names, ("noisy", "expected_panic"))

    def test_associates_standardized_boundaries_with_failed_tests(self) -> None:
        audit = parse_log(
            """
thread 'direct' panicked at generated.rs:1:1:
unimplemented C# API member: M:Example.Direct
test direct ... FAILED
thread 'typed' panicked at test.rs:1:1:
assertion failed: left == right
  left: Some(NotImplemented { csharp_member: "M:Example.Typed" })
 right: Some(ArgumentNull)
test typed ... FAILED
test support ... ok
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
"""
        )
        self.assertEqual(audit.members["M:Example.Direct"], 1)
        self.assertEqual(audit.members["M:Example.Typed"], 1)
        self.assertEqual(audit.nonstandard_failures, ())

    def test_reports_nonstandard_failure(self) -> None:
        audit = parse_log(
            """
thread 'broken' panicked at test.rs:1:1:
assertion failed
test broken ... FAILED
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
"""
        )
        self.assertEqual(audit.nonstandard_failures, ("broken",))


if __name__ == "__main__":
    unittest.main()
