Files
carbon-lang/testing/file_test/line.h
T
Jon Ross-Perkins c832d523be Update files and clang-tidy config to pass with clang-tidy-20 (#4691)
Disables three new warnings because they lean more towards style
conflicts than fixes. I've brought these up on #style.

Other than that, mostly fixing basic issues, and things that
clang-tidy-20 seems to fire where clang-tiday-16 didn't. One particular
curious case is `llvm::StringLiteral::data()` uses, which are flagged as
not strictly null-terminated; I'm switching to `const char*` in those
spots which matches `llvm::formatv`'s format argument, but feels worse.

I'm removing `run_clang_tidy.py` here because I'm observing it give
fewer warnings than `bazel build --config=clang-tidy -k
//toolchain/...`. The latter matches how we enforce in GitHub actions
(and also caches results, and suppresses output for files that have no
issues), so I'm dropping the bespoke script.
2024-12-17 01:25:53 +00:00

56 lines
1.6 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TESTING_FILE_TEST_LINE_H_
#define CARBON_TESTING_FILE_TEST_LINE_H_
#include "common/ostream.h"
#include "llvm/ADT/StringRef.h"
namespace Carbon::Testing {
// Interface for lines.
class FileTestLineBase : public Printable<FileTestLineBase> {
public:
explicit FileTestLineBase(int file_number, int line_number)
: file_number_(file_number), line_number_(line_number) {}
virtual ~FileTestLineBase() = default;
// Prints the autoupdated line.
virtual auto Print(llvm::raw_ostream& out) const -> void = 0;
virtual auto is_blank() const -> bool = 0;
auto file_number() const -> int { return file_number_; }
auto line_number() const -> int { return line_number_; }
private:
int file_number_;
int line_number_;
};
// A line in the original file test.
//
// `final` because we use pointer arithmetic on this type.
class FileTestLine final : public FileTestLineBase {
public:
explicit FileTestLine(int file_number, int line_number, llvm::StringRef line)
: FileTestLineBase(file_number, line_number), line_(line) {}
auto Print(llvm::raw_ostream& out) const -> void override { out << line_; }
auto is_blank() const -> bool override { return line_.empty(); }
auto indent() const -> llvm::StringRef {
return line_.substr(0, line_.find_first_not_of(" \n"));
}
private:
llvm::StringRef line_;
};
} // namespace Carbon::Testing
#endif // CARBON_TESTING_FILE_TEST_LINE_H_