blueloveTH hace 2 años
padre
commit
f41368afbb
Se han modificado 3 ficheros con 22 adiciones y 11 borrados
  1. 20 0
      include/pocketpy/str.h
  2. 2 2
      tests/80_json.py
  3. 0 9
      tests/99_builtin_func.py

+ 20 - 0
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;

+ 2 - 2
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],

+ 0 - 9
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