line.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef CARBON_TESTING_FILE_TEST_LINE_H_
  5. #define CARBON_TESTING_FILE_TEST_LINE_H_
  6. #include "common/ostream.h"
  7. #include "llvm/ADT/StringRef.h"
  8. namespace Carbon::Testing {
  9. // Interface for lines.
  10. class FileTestLineBase {
  11. public:
  12. explicit FileTestLineBase(int line_number) : line_number_(line_number) {}
  13. virtual ~FileTestLineBase() {}
  14. // Prints the autoupdated line.
  15. virtual auto Print(llvm::raw_ostream& out) const -> void = 0;
  16. virtual auto is_blank() const -> bool = 0;
  17. auto line_number() const -> int { return line_number_; }
  18. private:
  19. int line_number_;
  20. };
  21. // A line in the original file test.
  22. class FileTestLine : public FileTestLineBase {
  23. public:
  24. explicit FileTestLine(int line_number, llvm::StringRef line)
  25. : FileTestLineBase(line_number), line_(line) {}
  26. auto Print(llvm::raw_ostream& out) const -> void override { out << line_; }
  27. auto is_blank() const -> bool override { return line_.empty(); }
  28. auto indent() const -> llvm::StringRef {
  29. return line_.substr(0, line_.find_first_not_of(" \n"));
  30. }
  31. private:
  32. llvm::StringRef line_;
  33. };
  34. } // namespace Carbon::Testing
  35. #endif // CARBON_TESTING_FILE_TEST_LINE_H_