================ @@ -0,0 +1,192 @@ +//===-- DILLexerTests.cpp --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/ValueObject/DILLexer.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Testing/Support/Error.h" +#include "gtest/gtest.h" +#include <string> + +using llvm::StringRef; + +std::vector<std::pair<lldb_private::dil::Token::Kind, std::string>> +ExtractTokenData(lldb_private::dil::DILLexer &lexer) { + std::vector<std::pair<lldb_private::dil::Token::Kind, std::string>> data; + if (lexer.NumLexedTokens() == 0) + return data; + + lexer.ResetTokenIdx(UINT_MAX); + do { + lexer.Advance(); + lldb_private::dil::Token tok = lexer.GetCurrentToken(); + data.push_back(std::make_pair(tok.GetKind(), tok.GetSpelling())); + } while (data.back().first != lldb_private::dil::Token::eof); + return data; +} + +TEST(DILLexerTests, SimpleTest) { + StringRef input_expr("simple_var"); + uint32_t tok_len = 10; + llvm::Expected<lldb_private::dil::DILLexer> maybe_lexer = + lldb_private::dil::DILLexer::Create(input_expr); + ASSERT_THAT_EXPECTED(maybe_lexer, llvm::Succeeded()); + lldb_private::dil::DILLexer lexer(*maybe_lexer); + lldb_private::dil::Token token = + lldb_private::dil::Token(lldb_private::dil::Token::unknown, "", 0); + EXPECT_EQ(token.GetKind(), lldb_private::dil::Token::unknown); + + lexer.Advance(); + token = lexer.GetCurrentToken(); + EXPECT_EQ(token.GetKind(), lldb_private::dil::Token::identifier); + EXPECT_EQ(token.GetSpelling(), "simple_var"); + EXPECT_EQ(token.GetSpelling().size(), tok_len); + lexer.Advance(); + token = lexer.GetCurrentToken(); + EXPECT_EQ(token.GetKind(), lldb_private::dil::Token::eof); +} + +TEST(DILLexerTests, TokenKindTest) { + StringRef input_expr("namespace"); + llvm::Expected<lldb_private::dil::DILLexer> maybe_lexer = + lldb_private::dil::DILLexer::Create(input_expr); + ASSERT_THAT_EXPECTED(maybe_lexer, llvm::Succeeded()); + lldb_private::dil::DILLexer lexer(*maybe_lexer); + lldb_private::dil::Token token = + lldb_private::dil::Token(lldb_private::dil::Token::unknown, "", 0); + lexer.Advance(); + token = lexer.GetCurrentToken(); ---------------- labath wrote:
```suggestion lldb_private::dil::Token token = lldb_private::dil::Token(lldb_private::dil::Token::identifier, "ident", 0); ``` (The reason is that this looks like a test for the token kind testing functions. You don't actually need the token to come out of the lexer for that. And we already have tests that check that producing a sequence of characters produces an "identifier" token.) https://github.com/llvm/llvm-project/pull/123521 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits