[libcxx-commits] [libcxx] [libc++][test] Adjust expected hexfloat format (PR #95011)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 10 10:02:58 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Jake Egan (jakeegan)
<details>
<summary>Changes</summary>
The test expects a hex float format of `0x0p+0`, but AIX prints `0x0.0p+0`. This change adjusts the test to accept both.
---
Patch is 229.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95011.diff
2 Files Affected:
- (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp (+251-194)
- (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp (+251-194)
``````````diff
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
index 21efa978abdcc..caca4bf71d92b 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
@@ -17,12 +17,11 @@
// https://developercommunity.visualstudio.com/t/Printf-formatting-of-float-as-hex-prints/1660844
// XFAIL: msvc
-// XFAIL: LIBCXX-AIX-FIXME
-
#include <locale>
#include <ios>
#include <cassert>
#include <streambuf>
+#include <sstream>
#include <cmath>
#include "test_macros.h"
#include "test_iterators.h"
@@ -49,6 +48,13 @@ class my_numpunct
virtual std::string do_grouping() const {return std::string("\1\2\3");}
};
+const std::string hexfloat_fmt(const double& v, const std::ios& ios){
+ std::ostringstream oss;
+ oss.copyfmt(ios);
+ oss << std::noshowpos << std::hexfloat << v;
+ return oss.str();
+}
+
void test1()
{
char str[200];
@@ -60,6 +66,9 @@ void test1()
std::ios ios(0);
std::hexfloat(ios);
// %a
+
+ std::string hf(hexfloat_fmt(0., ios));
+ const std::string padding(25 - hf.length() - 1, '*');
{
ios.precision(0);
{
@@ -70,12 +79,13 @@ void test1()
std::noshowpoint(ios);
{
ios.imbue(lc);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -83,7 +93,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0******************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -91,7 +101,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "******************-0x0p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -99,17 +109,18 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-******************0x0p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
ios.imbue(lg);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -117,7 +128,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0******************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -125,7 +136,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "******************-0x0p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -133,7 +144,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-******************0x0p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
@@ -141,12 +152,13 @@ void test1()
std::showpoint(ios);
{
ios.imbue(lc);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0.p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -154,7 +166,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0.p+0*****************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -162,7 +174,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "*****************-0x0.p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -170,17 +182,18 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-*****************0x0.p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
ios.imbue(lg);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0;p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -188,7 +201,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0;p+0*****************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -196,7 +209,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "*****************-0x0;p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -204,7 +217,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-*****************0x0;p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
@@ -215,12 +228,13 @@ void test1()
std::noshowpoint(ios);
{
ios.imbue(lc);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -228,7 +242,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0******************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -236,7 +250,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "******************-0x0p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -244,17 +258,18 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-******************0x0p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
ios.imbue(lg);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -262,7 +277,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0p+0******************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -270,7 +285,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "******************-0x0p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -278,7 +293,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-******************0x0p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
@@ -286,12 +301,13 @@ void test1()
std::showpoint(ios);
{
ios.imbue(lc);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0.p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -299,7 +315,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0.p+0*****************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -307,7 +323,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "*****************-0x0.p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -315,17 +331,18 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-*****************0x0.p+0");
+ assert(ex == "-" + padding + hf);
assert(ios.width() == 0);
}
}
ios.imbue(lg);
+ hf = hexfloat_fmt(0., ios);
{
ios.width(0);
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0;p+0");
+ assert(ex == "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -333,7 +350,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "-0x0;p+0*****************");
+ assert(ex == "-" + hf + padding);
assert(ios.width() == 0);
}
ios.width(25);
@@ -341,7 +358,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
std::string ex(str, base(iter));
- assert(ex == "*****************-0x0;p+0");
+ assert(ex == padding + "-" + hf);
assert(ios.width() == 0);
}
ios.width(25);
@@ -349,7 +366,7 @@ void test1()
{
cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/95011
More information about the libcxx-commits
mailing list