//===- unittest/Support/YAMLIOTest.cpp ------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/YAMLTraits.h"
#include "gtest/gtest.h"
using llvm::yaml::Input;
using llvm::yaml::Output;
using llvm::yaml::IO;
using llvm::yaml::MappingTraits;
using llvm::yaml::MappingNormalization;
using llvm::yaml::ScalarTraits;
using llvm::yaml::Hex8;
using llvm::yaml::Hex16;
using llvm::yaml::Hex32;
using llvm::yaml::Hex64;
//===----------------------------------------------------------------------===//
// Test MappingTraits
//===----------------------------------------------------------------------===//
struct FooBar {
int foo;
int bar;
};
typedef std::vector<FooBar> FooBarSequence;
LLVM_YAML_IS_SEQUENCE_VECTOR(FooBar)
namespace llvm {
namespace yaml {
template <>
struct MappingTraits<FooBar> {
static void mapping(IO &io, FooBar& fb) {
io.mapRequired("foo", fb.foo);
io.mapRequired("bar", fb.bar);
}
};
}
}
//
// Test the reading of a yaml mapping
//
TEST(YAMLIO, TestMapRead) {
FooBar doc;
Input yin("---\nfoo: 3\nbar: 5\n...\n");
yin >> doc;
EXPECT_FALSE(yin.error());
EXPECT_EQ(doc.foo, 3);
EXPECT_EQ(doc.bar,5);
}
//
// Test the reading of a yaml sequence of mappings
//
TEST(YAMLIO, TestSequenceMapRead) {
FooBarSequence seq;
Input yin("---\n - foo: 3\n bar: 5\n - foo: 7\n bar: 9\n...\n");
yin >> seq;
EXPECT_FALSE(yin.error());
EXPECT_EQ(seq.size(), 2UL);
FooBar& map1 = seq[0];
FooBar& map2 = seq[1];
EXPECT_EQ(map1.foo, 3);
EXPECT_EQ(map1.bar, 5);
EXPECT_EQ(map2.foo, 7);
EXPECT_EQ(