1 //===- unittest/Support/OptionMarshallingTest.cpp - OptParserEmitter 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 "gtest/gtest.h"
11 struct OptionWithMarshallingInfo
{
14 const char *ImpliedCheck
;
15 const char *ImpliedValue
;
18 static const OptionWithMarshallingInfo MarshallingTable
[] = {
19 #define OPTION_WITH_MARSHALLING( \
20 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
21 HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \
22 DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
23 MERGER, EXTRACTOR, TABLE_INDEX) \
24 {NAME, #KEYPATH, #IMPLIED_CHECK, #IMPLIED_VALUE},
26 #undef OPTION_WITH_MARSHALLING
29 TEST(OptionMarshalling
, EmittedOrderSameAsDefinitionOrder
) {
30 ASSERT_STREQ(MarshallingTable
[0].Name
, "marshalled-flag-d");
31 ASSERT_STREQ(MarshallingTable
[1].Name
, "marshalled-flag-c");
32 ASSERT_STREQ(MarshallingTable
[2].Name
, "marshalled-flag-b");
33 ASSERT_STREQ(MarshallingTable
[3].Name
, "marshalled-flag-a");
36 TEST(OptionMarshalling
, EmittedSpecifiedKeyPath
) {
37 ASSERT_STREQ(MarshallingTable
[0].KeyPath
, "X->MarshalledFlagD");
38 ASSERT_STREQ(MarshallingTable
[1].KeyPath
, "X->MarshalledFlagC");
39 ASSERT_STREQ(MarshallingTable
[2].KeyPath
, "X->MarshalledFlagB");
40 ASSERT_STREQ(MarshallingTable
[3].KeyPath
, "X->MarshalledFlagA");
43 TEST(OptionMarshalling
, ImpliedCheckContainsDisjunctionOfKeypaths
) {
44 ASSERT_STREQ(MarshallingTable
[0].ImpliedCheck
, "false");
46 ASSERT_STREQ(MarshallingTable
[1].ImpliedCheck
, "false || X->MarshalledFlagD");
47 ASSERT_STREQ(MarshallingTable
[1].ImpliedValue
, "true");
49 ASSERT_STREQ(MarshallingTable
[2].ImpliedCheck
, "false || X->MarshalledFlagD");
50 ASSERT_STREQ(MarshallingTable
[2].ImpliedValue
, "true");
52 ASSERT_STREQ(MarshallingTable
[3].ImpliedCheck
,
53 "false || X->MarshalledFlagC || X->MarshalledFlagB");
54 ASSERT_STREQ(MarshallingTable
[3].ImpliedValue
, "true");