1 //===- YAMLTest.cpp - Tests for Object YAML -------------------------------===//
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 "llvm/ObjectYAML/YAML.h"
10 #include "llvm/Support/YAMLTraits.h"
11 #include "gtest/gtest.h"
16 yaml::BinaryRef Binary
;
22 struct MappingTraits
<BinaryHolder
> {
23 static void mapping(IO
&IO
, BinaryHolder
&BH
) {
24 IO
.mapRequired("Binary", BH
.Binary
);
27 } // end namespace yaml
28 } // end namespace llvm
30 TEST(ObjectYAML
, BinaryRef
) {
32 SmallVector
<char, 32> Buf
;
33 llvm::raw_svector_ostream
OS(Buf
);
34 yaml::Output
YOut(OS
);
36 EXPECT_NE(OS
.str().find("''"), StringRef::npos
);
39 TEST(ObjectYAML
, UnknownOption
) {
40 StringRef InputYAML
= "InvalidKey: InvalidValue\n"
43 yaml::Input
Input(InputYAML
);
44 // test 1: default in trying to parse invalid key is an error case.
46 EXPECT_EQ(Input
.error().value(), 22);
48 // test 2: only warn about invalid key if actively set.
49 yaml::Input
Input2(InputYAML
);
51 Input2
.setAllowUnknownKeys(true);
53 EXPECT_EQ(BH2
.Binary
, yaml::BinaryRef("AAAA"));
54 EXPECT_EQ(Input2
.error().value(), 0);