From 7aa42e85c4eb511d89c828ddb905a52a0ba8ddef Mon Sep 17 00:00:00 2001 From: BLUELOVETH Date: Wed, 20 Sep 2023 10:51:44 +0800 Subject: [PATCH] ... --- src/pocketpy.cpp | 10 +++++----- tests/80_json.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 26dfe0fa..1174fcdd 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -683,7 +683,7 @@ void init_builtins(VM* _vm) { ss << '['; for(int i=0; ipy_repr(iterable[i])); - if(i != iterable.size()) ss << ','; + if(i != iterable.size()-1) ss << ", "; } ss << ']'; return VAR(ss.str()); @@ -695,7 +695,7 @@ void init_builtins(VM* _vm) { ss << '['; for(int i=0; ipy_json(iterable[i])); - if(i != iterable.size()) ss << ','; + if(i != iterable.size()-1) ss << ", "; } ss << ']'; return VAR(ss.str()); @@ -710,8 +710,8 @@ void init_builtins(VM* _vm) { ss << ','; }else{ for(int i=0; ipy_repr(iterable[i]); - if(i != iterable.size()) ss << ','; + ss << CAST(Str&, vm->py_repr(iterable[i])); + if(i != iterable.size()-1) ss << ", "; } } ss << ')'; @@ -724,7 +724,7 @@ void init_builtins(VM* _vm) { ss << '['; for(int i=0; ipy_json(iterable[i])); - if(i != iterable.size()) ss << ','; + if(i != iterable.size()-1) ss << ", "; } ss << ']'; return VAR(ss.str()); diff --git a/tests/80_json.py b/tests/80_json.py index 6a589c32..d821ab92 100644 --- a/tests/80_json.py +++ b/tests/80_json.py @@ -40,4 +40,19 @@ assert c == _c d = True _j = json.dumps(d) _d = json.loads(_j) -assert d == _d \ No newline at end of file +assert d == _d + + +assert repr((1,)) == '(1,)' +assert repr((1, 2, 3)) == '(1, 2, 3)' +assert repr(tuple()) == '()' +assert json.dumps((1,)) == '[1]' +assert json.dumps((1, 2, 3)) == '[1, 2, 3]' +assert json.dumps(tuple()) == '[]' + +assert repr([]) == '[]' +assert repr([1, 2, 3]) == '[1, 2, 3]' +assert repr([1]) == '[1]' +assert json.dumps([]) == '[]' +assert json.dumps([1, 2, 3]) == '[1, 2, 3]' +assert json.dumps([1]) == '[1]' \ No newline at end of file