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/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 | |
18 | using namespace llvm; |
19 | |
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"; |
25 | } |
26 | )td"; |
27 | |
28 | SourceMgr SrcMgr; |
29 | SrcMgr.AddNewSourceBuffer( |
30 | F: MemoryBuffer::getMemBuffer(InputData: SimpleTdSource, BufferName: "test_buffer"), IncludeLoc: SMLoc()); |
31 | |
32 | RecordKeeper Records; |
33 | bool ProcessResult = TableGenParseFile(InputSrcMgr&: SrcMgr, Records); |
34 | EXPECT_FALSE(ProcessResult); |
35 | |
36 | Record *Foo = Records.getDef(Name: "Foo"); |
37 | std::optional<StringRef> Field = Foo->getValueAsOptionalString(FieldName: "strField"); |
38 | EXPECT_TRUE(Field.has_value()); |
39 | EXPECT_EQ(*Field, "value"); |
40 | } |
41 |