llvm/llvm/unittests/Support/YAMLIOTest.cpp

//===- unittest/Support/YAMLIOTest.cpp ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/YAMLTraits.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

Hex16;
Hex32;
Hex64;
Hex8;
Input;
isNumeric;
MappingNormalization;
MappingTraits;
Output;
ScalarTraits;
StartsWith;




static void suppressErrorMessages(const llvm::SMDiagnostic &, void *) {}



//===----------------------------------------------------------------------===//
//  Test MappingTraits
//===----------------------------------------------------------------------===//

struct FooBar {};
FooBarSequence;

LLVM_YAML_IS_SEQUENCE_VECTOR(FooBar)

struct FooBarContainer {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FooBar> {};

  template <> struct MappingTraits<FooBarContainer> {};
}
}


//
// Test the reading of a yaml mapping
//
TEST(YAMLIO, TestMapRead) {}

TEST(YAMLIO, TestMalformedMapRead) {}

TEST(YAMLIO, TestMapDuplicatedKeysRead) {}

//
// Test the reading of a yaml sequence of mappings
//
TEST(YAMLIO, TestSequenceMapRead) {}

//
// Test the reading of a map containing a yaml sequence of mappings
//
TEST(YAMLIO, TestContainerSequenceMapRead) {}

//
// Test the reading of a map containing a malformed yaml sequence
//
TEST(YAMLIO, TestMalformedContainerSequenceMapRead) {}

//
// Test writing then reading back a sequence of mappings
//
TEST(YAMLIO, TestSequenceMapWriteAndRead) {}

//
// Test reading the entire struct as an enum.
//

struct FooBarEnum {};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<FooBarEnum> {};
} // namespace yaml
} // namespace llvm

TEST(YAMLIO, TestMapEnumRead) {}

//
// Test YAML filename handling.
//
static void testErrorFilename(const llvm::SMDiagnostic &Error, void *) {}

TEST(YAMLIO, TestGivenFilename) {}

struct WithStringField {};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<WithStringField> {};
} // namespace yaml
} // namespace llvm

TEST(YAMLIO, MultilineStrings) {}

TEST(YAMLIO, NoQuotesForTab) {}

//===----------------------------------------------------------------------===//
//  Test built-in types
//===----------------------------------------------------------------------===//

struct BuiltInTypes {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<BuiltInTypes> {};
}
}


//
// Test the reading of all built-in scalar conversions
//
TEST(YAMLIO, TestReadBuiltInTypes) {}


//
// Test writing then reading back all built-in scalar types
//
TEST(YAMLIO, TestReadWriteBuiltInTypes) {}

//===----------------------------------------------------------------------===//
//  Test endian-aware types
//===----------------------------------------------------------------------===//

struct EndianTypes {};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<EndianTypes> {};
}
}

//
// Test the reading of all endian scalar conversions
//
TEST(YAMLIO, TestReadEndianTypes) {}

//
// Test writing then reading back all endian-aware scalar types
//
TEST(YAMLIO, TestReadWriteEndianTypes) {}

enum class Enum : uint16_t {};
enum class BitsetEnum : uint16_t {};
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
struct EndianEnums {};
namespace llvm {
namespace yaml {
template <> struct ScalarEnumerationTraits<Enum> {};

template <> struct ScalarBitSetTraits<BitsetEnum> {};

template <> struct MappingTraits<EndianEnums> {};
} // namespace yaml
} // namespace llvm

TEST(YAMLIO, TestReadEndianEnums) {}

TEST(YAMLIO, TestReadWriteEndianEnums) {}

struct StringTypes {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<StringTypes> {};
}
}

TEST(YAMLIO, TestReadWriteStringTypes) {}

//===----------------------------------------------------------------------===//
//  Test ScalarEnumerationTraits
//===----------------------------------------------------------------------===//

enum Colors {};

struct ColorMap {};

namespace llvm {
namespace yaml {
  template <>
  struct ScalarEnumerationTraits<Colors> {};
  template <>
  struct MappingTraits<ColorMap> {};
}
}


//
// Test reading enumerated scalars
//
TEST(YAMLIO, TestEnumRead) {}



//===----------------------------------------------------------------------===//
//  Test ScalarBitSetTraits
//===----------------------------------------------------------------------===//

enum MyFlags {};
inline MyFlags operator|(MyFlags a, MyFlags b) {}

struct FlagsMap {};


namespace llvm {
namespace yaml {
  template <>
  struct ScalarBitSetTraits<MyFlags> {};
  template <>
  struct MappingTraits<FlagsMap> {};
}
}


//
// Test reading flow sequence representing bit-mask values
//
TEST(YAMLIO, TestFlagsRead) {}


//
// Test writing then reading back bit-mask values
//
TEST(YAMLIO, TestReadWriteFlags) {}



//===----------------------------------------------------------------------===//
//  Test ScalarTraits
//===----------------------------------------------------------------------===//

struct MyCustomType {};

struct MyCustomTypeMap {};


namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<MyCustomTypeMap> {};
  // MyCustomType is formatted as a yaml scalar.  A value of
  // {length=3, width=4} would be represented in yaml as "3 by 4".
  template<>
  struct ScalarTraits<MyCustomType> {};
}
}


//
// Test writing then reading back custom values
//
TEST(YAMLIO, TestReadWriteMyCustomType) {}


//===----------------------------------------------------------------------===//
//  Test BlockScalarTraits
//===----------------------------------------------------------------------===//

struct MultilineStringType {};

struct MultilineStringTypeMap {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<MultilineStringTypeMap> {};

  // MultilineStringType is formatted as a yaml block literal scalar. A value of
  // "Hello\nWorld" would be represented in yaml as
  //  |
  //    Hello
  //    World
  template <>
  struct BlockScalarTraits<MultilineStringType> {};
}
}

LLVM_YAML_IS_DOCUMENT_LIST_VECTOR()

//
// Test writing then reading back custom values
//
TEST(YAMLIO, TestReadWriteMultilineStringType) {}

//
// Test writing then reading back custom values
//
TEST(YAMLIO, TestReadWriteBlockScalarDocuments) {}

TEST(YAMLIO, TestReadWriteBlockScalarValue) {}

//===----------------------------------------------------------------------===//
//  Test flow sequences
//===----------------------------------------------------------------------===//

LLVM_YAML_STRONG_TYPEDEF(int, MyNumber)
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyNumber)
LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, MyString)
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(MyString)

namespace llvm {
namespace yaml {
  template<>
  struct ScalarTraits<MyNumber> {};

  template <> struct ScalarTraits<MyString> {};
}
}

struct NameAndNumbers {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<NameAndNumbers> {};
}
}

MyNumberFlowSequence;

LLVM_YAML_IS_SEQUENCE_VECTOR(MyNumberFlowSequence)

struct NameAndNumbersFlow {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<NameAndNumbersFlow> {};
}
}

//
// Test writing then reading back custom values
//
TEST(YAMLIO, TestReadWriteMyFlowSequence) {}


//
// Test writing then reading back a sequence of flow sequences.
//
TEST(YAMLIO, TestReadWriteSequenceOfMyFlowSequence) {}

//===----------------------------------------------------------------------===//
//  Test normalizing/denormalizing
//===----------------------------------------------------------------------===//

LLVM_YAML_STRONG_TYPEDEF()

SecondsSequence;

LLVM_YAML_IS_SEQUENCE_VECTOR(TotalSeconds)


namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<TotalSeconds> {};
}
}


//
// Test the reading of a yaml sequence of mappings
//
TEST(YAMLIO, TestReadMySecondsSequence) {}


//
// Test writing then reading back custom values
//
TEST(YAMLIO, TestReadWriteMySecondsSequence) {}


//===----------------------------------------------------------------------===//
//  Test dynamic typing
//===----------------------------------------------------------------------===//

enum AFlags {};

enum BFlags {};

enum Kind {};

struct KindAndFlags {};

KindAndFlagsSequence;

LLVM_YAML_IS_SEQUENCE_VECTOR(KindAndFlags)

namespace llvm {
namespace yaml {
  template <>
  struct ScalarEnumerationTraits<AFlags> {};
  template <>
  struct ScalarEnumerationTraits<BFlags> {};
  template <>
  struct ScalarEnumerationTraits<Kind> {};
  template <>
  struct MappingTraits<KindAndFlags> {};
}
}


//
// Test the reading of a yaml sequence dynamic types
//
TEST(YAMLIO, TestReadKindAndFlagsSequence) {}

//
// Test writing then reading back dynamic types
//
TEST(YAMLIO, TestReadWriteKindAndFlagsSequence) {}


//===----------------------------------------------------------------------===//
//  Test document list
//===----------------------------------------------------------------------===//

struct FooBarMap {};
FooBarMapDocumentList;

LLVM_YAML_IS_DOCUMENT_LIST_VECTOR()


namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FooBarMap> {};
}
}


//
// Test the reading of a yaml mapping
//
TEST(YAMLIO, TestDocRead) {}



//
// Test writing then reading back a sequence of mappings
//
TEST(YAMLIO, TestSequenceDocListWriteAndRead) {}

//===----------------------------------------------------------------------===//
//  Test document tags
//===----------------------------------------------------------------------===//

struct MyDouble {};

LLVM_YAML_IS_DOCUMENT_LIST_VECTOR()


namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<MyDouble> {};
 }
}


//
// Test the reading of two different tagged yaml documents.
//
TEST(YAMLIO, TestTaggedDocuments) {}



//
// Test writing then reading back tagged documents
//
TEST(YAMLIO, TestTaggedDocumentsWriteAndRead) {}


//===----------------------------------------------------------------------===//
//  Test mapping validation
//===----------------------------------------------------------------------===//

struct MyValidation {};

LLVM_YAML_IS_DOCUMENT_LIST_VECTOR()

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<MyValidation> {};
 }
}


//
// Test that validate() is called and complains about the negative value.
//
TEST(YAMLIO, TestValidatingInput) {}

//===----------------------------------------------------------------------===//
//  Test flow mapping
//===----------------------------------------------------------------------===//

struct FlowFooBar {};

FlowFooBarSequence;

LLVM_YAML_IS_SEQUENCE_VECTOR(FlowFooBar)

struct FlowFooBarDoc {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FlowFooBar> {};

  template <>
  struct MappingTraits<FlowFooBarDoc> {};
}
}

//
// Test writing then reading back custom mappings
//
TEST(YAMLIO, TestReadWriteMyFlowMapping) {}

//===----------------------------------------------------------------------===//
//  Test error handling
//===----------------------------------------------------------------------===//

//
// Test error handling of unknown enumerated scalar
//
TEST(YAMLIO, TestColorsReadError) {}


//
// Test error handling of flow sequence with unknown value
//
TEST(YAMLIO, TestFlagsReadError) {}


//
// Test error handling reading built-in uint8_t type
//
TEST(YAMLIO, TestReadBuiltInTypesUint8Error) {}


//
// Test error handling reading built-in uint16_t type
//
TEST(YAMLIO, TestReadBuiltInTypesUint16Error) {}


//
// Test error handling reading built-in uint32_t type
//
TEST(YAMLIO, TestReadBuiltInTypesUint32Error) {}


//
// Test error handling reading built-in uint64_t type
//
TEST(YAMLIO, TestReadBuiltInTypesUint64Error) {}


//
// Test error handling reading built-in int8_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint8OverError) {}

//
// Test error handling reading built-in int8_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) {}


//
// Test error handling reading built-in int16_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) {}


//
// Test error handling reading built-in int16_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint16OverError) {}


//
// Test error handling reading built-in int32_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) {}

//
// Test error handling reading built-in int32_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint32OverError) {}


//
// Test error handling reading built-in int64_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) {}

//
// Test error handling reading built-in int64_t type
//
TEST(YAMLIO, TestReadBuiltInTypesint64OverError) {}

//
// Test error handling reading built-in float type
//
TEST(YAMLIO, TestReadBuiltInTypesFloatError) {}

//
// Test error handling reading built-in float type
//
TEST(YAMLIO, TestReadBuiltInTypesDoubleError) {}

//
// Test error handling reading built-in Hex8 type
//
TEST(YAMLIO, TestReadBuiltInTypesHex8Error) {}


//
// Test error handling reading built-in Hex16 type
//
TEST(YAMLIO, TestReadBuiltInTypesHex16Error) {}

//
// Test error handling reading built-in Hex32 type
//
TEST(YAMLIO, TestReadBuiltInTypesHex32Error) {}

//
// Test error handling reading built-in Hex64 type
//
TEST(YAMLIO, TestReadBuiltInTypesHex64Error) {}

TEST(YAMLIO, TestMalformedMapFailsGracefully) {}

struct OptionalTest {};

struct OptionalTestSeq {};

LLVM_YAML_IS_SEQUENCE_VECTOR(OptionalTest)
namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<OptionalTest> {};

  template <>
  struct MappingTraits<OptionalTestSeq> {};
}
}

TEST(YAMLIO, SequenceElideTest) {}

TEST(YAMLIO, TestEmptyStringFailsForMapWithRequiredFields) {}

TEST(YAMLIO, TestEmptyStringSucceedsForMapWithOptionalFields) {}

TEST(YAMLIO, TestEmptyStringSucceedsForSequence) {}

struct FlowMap {};

struct FlowSeq {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FlowMap> {};

template <>
struct ScalarTraits<FlowSeq> {};
}
}

LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FlowSeq)

TEST(YAMLIO, TestWrapFlow) {}

struct MappingContext {};
struct SimpleMap {};

struct NestedMap {};

namespace llvm {
namespace yaml {
template <> struct MappingContextTraits<SimpleMap, MappingContext> {};

template <> struct MappingTraits<NestedMap> {};
}
}

TEST(YAMLIO, TestMapWithContext) {}

LLVM_YAML_IS_STRING_MAP()

TEST(YAMLIO, TestCustomMapping) {}

LLVM_YAML_IS_STRING_MAP()

TEST(YAMLIO, TestCustomMappingStruct) {}

struct FooBarMapMap {};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<FooBarMapMap> {};
}
}

TEST(YAMLIO, TestEmptyMapWrite) {}

TEST(YAMLIO, TestEmptySequenceWrite) {}

static void TestEscaped(llvm::StringRef Input, llvm::StringRef Expected) {}

TEST(YAMLIO, TestEscaped) {}

TEST(YAMLIO, Numeric) {}

//===----------------------------------------------------------------------===//
//  Test writing and reading escaped keys
//===----------------------------------------------------------------------===//

// Struct with dynamic string key
struct QuotedKeyStruct {};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<QuotedKeyStruct> {};
} // namespace yaml
} // namespace llvm

TEST(YAMLIO, TestQuotedKeyRead) {}

TEST(YAMLIO, TestQuotedKeyWriteRead) {}

//===----------------------------------------------------------------------===//
//  Test PolymorphicTraits and TaggedScalarTraits
//===----------------------------------------------------------------------===//

struct Poly {};

struct Scalar : Poly {};

struct Seq : Poly, std::vector<std::unique_ptr<Poly>> {};

struct Map : Poly, llvm::StringMap<std::unique_ptr<Poly>> {};

namespace llvm {
namespace yaml {

template <> struct PolymorphicTraits<std::unique_ptr<Poly>> {};

template <> struct TaggedScalarTraits<Scalar> {};

template <> struct CustomMappingTraits<Map> {};

template <> struct SequenceTraits<Seq> {};

} // namespace yaml
} // namespace llvm

TEST(YAMLIO, TestReadWritePolymorphicScalar) {}

TEST(YAMLIO, TestReadWritePolymorphicSeq) {}

TEST(YAMLIO, TestReadWritePolymorphicMap) {}

TEST(YAMLIO, TestAnchorMapError) {}

TEST(YAMLIO, TestFlowSequenceTokenErrors) {}

TEST(YAMLIO, TestDirectiveMappingNoValue) {}

TEST(YAMLIO, TestUnescapeInfiniteLoop) {}

TEST(YAMLIO, TestScannerUnexpectedCharacter) {}

TEST(YAMLIO, TestUnknownDirective) {}

TEST(YAMLIO, TestEmptyAlias) {}

TEST(YAMLIO, TestEmptyAnchor) {}

TEST(YAMLIO, TestScannerNoNullEmpty) {}

TEST(YAMLIO, TestScannerNoNullSequenceOfNull) {}

TEST(YAMLIO, TestScannerNoNullSimpleSequence) {}

TEST(YAMLIO, TestScannerNoNullUnbalancedMap) {}

TEST(YAMLIO, TestScannerNoNullEmptyMap) {}

TEST(YAMLIO, TestScannerNoNullUnbalancedSequence) {}

TEST(YAMLIO, TestScannerNoNullEmptySequence) {}

TEST(YAMLIO, TestScannerNoNullScalarUnbalancedDoubleQuote) {}

TEST(YAMLIO, TestScannerNoNullScalarUnbalancedSingleQuote) {}

TEST(YAMLIO, TestScannerNoNullEmptyAlias) {}

TEST(YAMLIO, TestScannerNoNullEmptyAnchor) {}

TEST(YAMLIO, TestScannerNoNullDecodeInvalidUTF8) {}

TEST(YAMLIO, TestScannerNoNullScanPlainScalarInFlow) {}

struct FixedArray {};

namespace llvm {
namespace yaml {
  template <>
  struct MappingTraits<FixedArray> {};
}
}

TEST(YAMLIO, FixedSizeArray) {}

TEST(YAMLIO, FixedSizeArrayMismatch) {}