Files
carbon-lang/toolchain/lex/lex_file_test.cpp
T
Jon Ross-PerkinsandChandler Carruth ec182fb00d Rename lexer dir to lex (#3179)
Continuing with #3070. Just a dir and file rename (only prefix change is
lexer_file_test). Everything in the lex dir should be marked as a move.

Note, I think this closes #3070. There may still be further cleanup
later, but the organizational changes suggested there are being
completed.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-09-01 02:39:04 +00:00

47 lines
1.4 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
#include <string>
#include "llvm/ADT/SmallVector.h"
#include "re2/re2.h"
#include "toolchain/driver/driver_file_test_base.h"
namespace Carbon::Testing {
namespace {
class LexerFileTest : public DriverFileTestBase {
public:
explicit LexerFileTest(std::filesystem::path path)
: DriverFileTestBase(std::move(path)),
end_of_file_re_((R"((EndOfFile.*column: )( *\d+))")) {}
auto GetDefaultArgs() -> llvm::SmallVector<std::string> override {
return {"compile", "--phase=lex", "--dump-tokens", "%s"};
}
auto GetLineNumberReplacement(llvm::ArrayRef<llvm::StringRef> /*filenames*/)
-> LineNumberReplacement override {
return {.has_file = false,
.pattern = R"(line: (\s*\d+))",
// The `{{{{` becomes `{{`.
.line_formatv = "{{{{ *}}{0}"};
}
auto DoExtraCheckReplacements(std::string& check_line) -> void override {
// Ignore the resulting column of EndOfFile because it's often the end of
// the CHECK comment.
RE2::Replace(&check_line, end_of_file_re_, R"(\1{{ *\\d+}})");
}
private:
RE2 end_of_file_re_;
};
} // namespace
CARBON_FILE_TEST_FACTORY(LexerFileTest);
} // namespace Carbon::Testing