mocks.cpp 936 B

12345678910111213141516171819202122232425262728293031323334
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/diagnostics/mocks.h"
  5. namespace Carbon {
  6. void PrintTo(const Diagnostic& diagnostic, std::ostream* os) {
  7. *os << "Diagnostic{";
  8. PrintTo(diagnostic.level, os);
  9. for (const auto& message : diagnostic.messages) {
  10. *os << ", {" << message.loc.filename << ":" << message.loc.line_number
  11. << ":" << message.loc.column_number << ", \""
  12. << message.format_fn(message) << "}";
  13. }
  14. *os << "\"}";
  15. }
  16. void PrintTo(DiagnosticLevel level, std::ostream* os) {
  17. switch (level) {
  18. case DiagnosticLevel::Note:
  19. *os << "Note";
  20. break;
  21. case DiagnosticLevel::Warning:
  22. *os << "Warning";
  23. break;
  24. case DiagnosticLevel::Error:
  25. *os << "Error";
  26. break;
  27. }
  28. }
  29. } // namespace Carbon