llvm.org GIT mirror llvm / 845e196
Make BinaryRef output correctly in case of empty data. Previously, it would simply output nothing, but it should output an empty string `""`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185894 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
6 changed file(s) with 68 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4848 }
4949
5050 void BinaryRef::writeAsHex(raw_ostream &OS) const {
51 if (binary_size() == 0) {
52 OS << "\"\"";
53 return;
54 }
5155 if (DataIsHexString) {
5256 OS.write((const char *)Data.data(), Data.size());
5357 return;
1313 add_subdirectory(Transforms)
1414 add_subdirectory(IR)
1515 add_subdirectory(DebugInfo)
16 add_subdirectory(Object)
99 LEVEL = ..
1010
1111 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode \
12 DebugInfo
12 DebugInfo Object
1313
1414 include $(LEVEL)/Makefile.common
1515
0 set(LLVM_LINK_COMPONENTS
1 object
2 )
3
4 add_llvm_unittest(ObjectTests
5 YAMLTest.cpp
6 )
0 ##===- unittests/IR/Makefile -------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 TESTNAME = Object
11 LINK_COMPONENTS := object
12
13 include $(LEVEL)/Makefile.config
14 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
0 //===- llvm/unittest/Object/YAMLTest.cpp - Tests for Object YAML ----------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Object/YAML.h"
10 #include "llvm/Support/YAMLTraits.h"
11 #include "gtest/gtest.h"
12
13 using namespace llvm;
14
15 namespace {
16 struct BinaryHolder {
17 object::yaml::BinaryRef Binary;
18 };
19 } // end anonymous namespace
20
21 namespace llvm {
22 namespace yaml {
23 template <>
24 struct MappingTraits {
25 static void mapping(IO &IO, BinaryHolder &BH) {
26 IO.mapRequired("Binary", BH.Binary);
27 }
28 };
29 } // end namespace yaml
30 } // end namespace llvm
31
32 TEST(ObjectYAML, BinaryRef) {
33 BinaryHolder BH;
34 SmallVector Buf;
35 llvm::raw_svector_ostream OS(Buf);
36 yaml::Output YOut(OS);
37 YOut << BH;
38 EXPECT_NE(OS.str().find("\"\""), StringRef::npos);
39 }