Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
27d9740a
Commit
27d9740a
authored
Dec 07, 2016
by
Alex Astashyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaks to unit-test for issue #379
parent
0a4a6a83
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+16
-14
No files found.
test/src/unit-regression.cpp
View file @
27d9740a
...
...
@@ -409,19 +409,24 @@ TEST_CASE("regression tests")
// of this block, then setLocale(LC_NUMERIC, "de_DE")
// does not actually make snprintf use "," as decimal separator
// on some compilers. I have no idea...
//
//const std::string orig_locale_name(setlocale(LC_ALL, NULL));
setlocale
(
LC_NUMERIC
,
"de_DE"
);
// Still, just setting some comma-using locale does not
// make snprintf output commas on all platforms, so instead
// will change dot to comma in the current locale below
//setlocale(LC_NUMERIC, "de_DE");
auto
loc
=
localeconv
();
auto
orig_decimal_point
=
loc
->
decimal_point
;
char
comma
[]
=
","
;
loc
->
decimal_point
=
comma
;
std
::
array
<
char
,
64
>
buf
;
{
// verify that snprintf now uses commas as decimal-separator
std
::
snprintf
(
buf
.
data
(),
buf
.
size
(),
"%.2f"
,
3.14
);
CHECK
(
std
::
strcmp
(
buf
.
data
(),
"3,14"
)
==
0
);
// verify that strtod now uses commas as decimal-separator
const
double
d1
=
std
::
strtod
(
buf
.
data
()
,
nullptr
);
const
double
d1
=
std
::
strtod
(
"3,14"
,
nullptr
);
CHECK
(
d1
==
3.14
);
// verify that strtod does not understand dots as decimal separator
...
...
@@ -429,18 +434,15 @@ TEST_CASE("regression tests")
CHECK
(
d2
==
3
);
}
const
json
j1
=
json
::
parse
(
"3.14"
);
// verify that parsed correctly despite using strtod internally
const
json
j1
=
json
::
parse
(
"3.14"
);
CHECK
(
j1
.
get
<
double
>
()
==
3.14
);
// verify that dumped correctly despite using snprintf internally
CHECK
(
j1
.
dump
()
==
"3.14"
);
// check a different code path
const
json
j2
=
json
::
parse
(
"1.000000000000000000000000000000000000000000000000000000000000000000000000"
);
CHECK
(
j2
.
get
<
double
>
()
==
1.0
);
loc
->
decimal_point
=
orig_decimal_point
;
// restore original locale
// setlocale(LC_ALL, orig_locale_name.c_str());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment