Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38079cc278 |
@@ -324,7 +324,9 @@ class SchemagenIntegerBoundaryTest(unittest.TestCase):
|
|||||||
self.assertEqual(run.returncode, 0, msg=run.stdout + run.stderr)
|
self.assertEqual(run.returncode, 0, msg=run.stdout + run.stderr)
|
||||||
|
|
||||||
def _build_cases_array(self, name, entries):
|
def _build_cases_array(self, name, entries):
|
||||||
lines = [f" struct {name}Case {{ const char *s; WeaselJsonStatus expected; long long v; }};"]
|
lines = [
|
||||||
|
f" struct {name}Case {{ const char *s; WeaselJsonStatus expected; long long v; }};"
|
||||||
|
]
|
||||||
lines.append(f" {name}Case {name}_cases[] = {{")
|
lines.append(f" {name}Case {name}_cases[] = {{")
|
||||||
for s, exp, v in entries:
|
for s, exp, v in entries:
|
||||||
val = f"{v}LL" if isinstance(v, int) else v
|
val = f"{v}LL" if isinstance(v, int) else v
|
||||||
@@ -393,7 +395,11 @@ class SchemagenIntegerBoundaryTest(unittest.TestCase):
|
|||||||
('{"age":1e3}', "WeaselJson_OK", 1000),
|
('{"age":1e3}', "WeaselJson_OK", 1000),
|
||||||
('{"age":2.0}', "WeaselJson_OK", 2),
|
('{"age":2.0}', "WeaselJson_OK", 2),
|
||||||
('{"age":0.001}', "WeaselJson_REJECT", 0),
|
('{"age":0.001}', "WeaselJson_REJECT", 0),
|
||||||
('{"age":-9223372036854775808.0}', "WeaselJson_OK", "-9223372036854775807LL - 1"),
|
(
|
||||||
|
'{"age":-9223372036854775808.0}',
|
||||||
|
"WeaselJson_OK",
|
||||||
|
"-9223372036854775807LL - 1",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
cases_src = self._build_cases_array("object", cases)
|
cases_src = self._build_cases_array("object", cases)
|
||||||
harness = textwrap.dedent(
|
harness = textwrap.dedent(
|
||||||
|
|||||||
@@ -1001,9 +1001,15 @@ private:
|
|||||||
mag *= 10;
|
mag *= 10;
|
||||||
}}
|
}}
|
||||||
if (mag > limit) return false;
|
if (mag > limit) return false;
|
||||||
__int128 signedMag = static_cast<__int128>(mag);
|
if (neg) {{
|
||||||
if (neg) signedMag = -signedMag;
|
if (mag == kMaxNeg) {{
|
||||||
out = static_cast<int64_t>(signedMag);
|
out = INT64_MIN;
|
||||||
|
}} else {{
|
||||||
|
out = -static_cast<int64_t>(mag);
|
||||||
|
}}
|
||||||
|
}} else {{
|
||||||
|
out = static_cast<int64_t>(mag);
|
||||||
|
}}
|
||||||
return true;
|
return true;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user