================
@@ -0,0 +1,218 @@
+//===-- 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 "gtest/gtest.h"
+#include <string>
+
+using llvm::StringRef;
+
+bool VerifyExpectedTokens(
+    lldb_private::dil::DILLexer &lexer,
+    std::vector<std::pair<lldb_private::dil::Token::Kind, std::string>>
+        exp_tokens,
+    uint32_t start_pos) {
+  if (lexer.NumLexedTokens() - start_pos < exp_tokens.size())
+    return false;
+
+  if (start_pos > 0)
+    lexer.ResetTokenIdx(start_pos -
+                        1); // GetNextToken increments the idx first.
+  for (const auto &pair : exp_tokens) {
+    lldb_private::dil::Token token = lexer.GetNextToken();
+    if (token.GetKind() != pair.first || token.GetSpelling() != pair.second)
+      return false;
+  }
+
+  return true;
+}
+
+TEST(DILLexerTests, SimpleTest) {
+  StringRef input_expr("simple_var");
+  uint32_t tok_len = 10;
+  lldb_private::dil::DILLexer lexer(input_expr);
+  lldb_private::dil::Token token;
+  token.SetKind(lldb_private::dil::Token::unknown);
+  EXPECT_EQ(token.GetKind(), lldb_private::dil::Token::unknown);
+  auto success = lexer.LexAll();
+
+  if (!success) {
+    EXPECT_TRUE(false);
+  }
+  token = lexer.GetNextToken();
+  EXPECT_EQ(token.GetKind(), lldb_private::dil::Token::identifier);
+  EXPECT_EQ(token.GetSpelling(), "simple_var");
+  EXPECT_EQ(token.GetLength(), tok_len);
----------------
labath wrote:

I'm wondering if the GetLength function is really necessary. How often is it 
going to be called? Because if it's not very often, we might as well use 
`GetSpelling().size()`.

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

Reply via email to