1 //===-- PrintfMatcher.cpp ---------------------------------------*- C++ -*-===//
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 "PrintfMatcher.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/stdio/printf_core/core_structs.h"
14 #include "test/UnitTest/StringUtils.h"
15 #include "test/UnitTest/Test.h"
19 namespace LIBC_NAMESPACE
{
22 using printf_core::FormatFlags
;
23 using printf_core::FormatSection
;
24 using printf_core::LengthModifier
;
26 bool FormatSectionMatcher::match(FormatSection actualValue
) {
28 return expected
== actual
;
33 #define IF_FLAG_SHOW_FLAG(flag_name) \
35 if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name) \
36 tlog << "\n\t\t" << #flag_name; \
39 case (LengthModifier::lm): \
43 static void display(FormatSection form
) {
44 tlog
<< "Raw String (len " << form
.raw_string
.size() << "): \"";
45 for (size_t i
= 0; i
< form
.raw_string
.size(); ++i
) {
46 tlog
<< form
.raw_string
[i
];
50 tlog
<< "\n\tHas Conv\n\tFlags:";
51 IF_FLAG_SHOW_FLAG(LEFT_JUSTIFIED
);
52 IF_FLAG_SHOW_FLAG(FORCE_SIGN
);
53 IF_FLAG_SHOW_FLAG(SPACE_PREFIX
);
54 IF_FLAG_SHOW_FLAG(ALTERNATE_FORM
);
55 IF_FLAG_SHOW_FLAG(LEADING_ZEROES
);
57 tlog
<< "\tmin width: " << form
.min_width
<< "\n";
58 tlog
<< "\tprecision: " << form
.precision
<< "\n";
59 tlog
<< "\tlength modifier: ";
60 switch (form
.length_modifier
) {
72 tlog
<< "\tconversion name: " << form
.conv_name
<< "\n";
73 if (form
.conv_name
== 'p' || form
.conv_name
== 'n' || form
.conv_name
== 's')
74 tlog
<< "\tpointer value: "
75 << int_to_hex
<uintptr_t>(
76 reinterpret_cast<uintptr_t>(form
.conv_val_ptr
))
78 else if (form
.conv_name
!= '%')
80 << int_to_hex
<fputil::FPBits
<long double>::UIntType
>(
85 } // anonymous namespace
87 void FormatSectionMatcher::explainError() {
88 tlog
<< "expected format section: ";
91 tlog
<< "actual format section : ";
96 } // namespace testing
97 } // namespace LIBC_NAMESPACE