[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / TableGen / ParserEntryPointTest.cpp
bloba470cc0611cd7d6f4559eb831e0b31c7e2aeaa0e
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-exception
6 //
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"
18 using namespace llvm;
20 TEST(Parser, SanityTest) {
21 // Simple TableGen source file with a single record.
22 const char *SimpleTdSource = R"td(
23 def Foo {
24 string strField = "value";
26 )td";
28 SourceMgr SrcMgr;
29 SrcMgr.AddNewSourceBuffer(
30 MemoryBuffer::getMemBuffer(SimpleTdSource, "test_buffer"), SMLoc());
32 RecordKeeper Records;
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");