xref: /llvm-project/llvm/unittests/TableGen/ParserEntryPointTest.cpp (revision e865fa75308aa8dc103ed2ac559e678b5531fa30)
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 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/ArrayRef.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/Support/MemoryBuffer.h"
12 #include "llvm/TableGen/Parser.h"
13 #include "llvm/TableGen/Record.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
16 
17 using namespace llvm;
18 
19 TEST(Parser, SanityTest) {
20   // Simple TableGen source file with a single record.
21   const char *SimpleTdSource = R"td(
22     def Foo {
23       string strField = "value";
24     }
25   )td";
26 
27   auto ProcessFn = [&](const RecordKeeper &Records) {
28     Record *Foo = Records.getDef("Foo");
29     Optional<StringRef> Field = Foo->getValueAsOptionalString("strField");
30     EXPECT_TRUE(Field.hasValue());
31     EXPECT_EQ(Field.getValue(), "value");
32     return false;
33   };
34 
35   bool ProcessResult = TableGenParseFile(
36       MemoryBuffer::getMemBuffer(SimpleTdSource, "test_buffer"),
37       /*IncludeDirs=*/{}, ProcessFn);
38   EXPECT_FALSE(ProcessResult);
39 }
40