1 //===- unittest/TableGen/ParserEntryPointTest.cpp - Parser tests ----------===//
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-exception
7 //===----------------------------------------------------------------------===//
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"
20 TEST(Parser
, SanityTest
) {
21 // Simple TableGen source file with a single record.
22 const char *SimpleTdSource
= R
"td(
24 string strField = "value
";
29 SrcMgr
.AddNewSourceBuffer(
30 MemoryBuffer::getMemBuffer(SimpleTdSource
, "test_buffer"), SMLoc());
33 bool ProcessResult
= TableGenParseFile(SrcMgr
, Records
);
34 EXPECT_FALSE(ProcessResult
);
36 Record
*Foo
= Records
.getDef("Foo");
37 Optional
<StringRef
> Field
= Foo
->getValueAsOptionalString("strField");
38 EXPECT_TRUE(Field
.has_value());
39 EXPECT_EQ(Field
.value(), "value");