41 lines · cpp
1//===- unittest/TableGen/ParserEntryPointTest.cpp - Parser tests ----------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ADT/ArrayRef.h"10#include "llvm/ADT/STLExtras.h"11#include "llvm/Support/MemoryBuffer.h"12#include "llvm/Support/SourceMgr.h"13#include "llvm/TableGen/Parser.h"14#include "llvm/TableGen/Record.h"15#include "gmock/gmock.h"16#include "gtest/gtest.h"17 18using namespace llvm;19 20TEST(Parser, SanityTest) {21 // Simple TableGen source file with a single record.22 const char *SimpleTdSource = R"td(23 def Foo {24 string strField = "value";25 }26 )td";27 28 SourceMgr SrcMgr;29 SrcMgr.AddNewSourceBuffer(30 MemoryBuffer::getMemBuffer(SimpleTdSource, "test_buffer"), SMLoc());31 32 RecordKeeper Records;33 bool ProcessResult = TableGenParseFile(SrcMgr, Records);34 EXPECT_FALSE(ProcessResult);35 36 const Record *Foo = Records.getDef("Foo");37 std::optional<StringRef> Field = Foo->getValueAsOptionalString("strField");38 EXPECT_TRUE(Field.has_value());39 EXPECT_EQ(*Field, "value");40}41