From f41368afbbdcbc31e9dd3cf5533d67118bc5c18b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 15 Oct 2023 22:08:41 +0800 Subject: [PATCH] ... --- include/pocketpy/str.h | 20 ++++++++++++++++++++ tests/80_json.py | 4 ++-- tests/99_builtin_func.py | 9 --------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/pocketpy/str.h b/include/pocketpy/str.h index b3be5cc4..a3905977 100644 --- a/include/pocketpy/str.h +++ b/include/pocketpy/str.h @@ -146,6 +146,26 @@ struct SStream{ return *this; } + SStream& operator<<(i64 val){ + // str(-2**64).__len__() == 21 + buffer.reserve(buffer.size() + 24); + if(val == 0){ + buffer.push_back('0'); + return *this; + } + if(val < 0){ + buffer.push_back('-'); + val = -val; + } + char* begin = buffer.end(); + while(val){ + buffer.push_back('0' + val % 10); + val /= 10; + } + std::reverse(begin, buffer.end()); + return *this; + } + SStream& operator<<(const std::string& s){ buffer.extend(s.data(), s.data() + s.size()); return *this; diff --git a/tests/80_json.py b/tests/80_json.py index e75afc42..b421ba3e 100644 --- a/tests/80_json.py +++ b/tests/80_json.py @@ -4,10 +4,10 @@ a = { 'c': None, 'd': [1, 2, 3], 'e': { - 'a': 1, + 'a': 100, 'b': 2.5, 'c': None, - 'd': [1, 2, 3], + 'd': [1425245, 278587578142, 397675452452452], }, "f": 'This is a string', 'g': [True, False, None], diff --git a/tests/99_builtin_func.py b/tests/99_builtin_func.py index 5b9a1650..1ee8cd1f 100644 --- a/tests/99_builtin_func.py +++ b/tests/99_builtin_func.py @@ -446,15 +446,6 @@ except: # 未完全测试准确性----------------------------------------------- -# 116: 721: _vm->bind_method<1>("list", "__rmul__", [](VM* vm, ArgsView args) { -# #####: 722: const List& self = _CAST(List&, args[0]); -# #####: 723: if(!is_int(args[1])) return vm->NotImplemented; -# #####: 724: int n = _CAST(int, args[1]); -# #####: 725: List result; -# #####: 726: result.reserve(self.size() * n); -# #####: 727: for(int i = 0; i < n; i++) result.extend(self); -# #####: 728: return VAR(std::move(result)); -# #####: 729: }); # test list.__rmul__: assert type(12 * [12]) is list