示例#1
0
 def test_incremental(self):
     r = b'{ "foo": "bar" }'
     ctx = _ffi.new('struct split_context *')
     for i in range(len(r) - 1):
         set_buffer(ctx, r[i:i + 1])
         error = _lib.json_split(ctx)
         self.assertEqual(error, ctx.error) == _lib.INCOMPLETE
         self.assertEqual(ctx.offset, 1)
     set_buffer(ctx, r[-1:])
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == 0
     self.assertEqual(ctx.offset, 1)
示例#2
0
 def test_incremental(self):
     r = b'{ "foo": "bar" }'
     ctx = _ffi.new('struct split_context *')
     for i in range(len(r)-1):
         set_buffer(ctx, r[i:i+1])
         error = _lib.json_split(ctx)
         self.assertEqual(error, ctx.error) == _lib.INCOMPLETE
         self.assertEqual(ctx.offset, 1)
     set_buffer(ctx, r[-1:])
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == 0
     self.assertEqual(ctx.offset, 1)
示例#3
0
 def test_multiple(self):
     r = b'{ "foo": "bar" } { "baz": "qux" }'
     ctx = split_string(r)
     self.assertEqual(ctx.error, 0)
     self.assertEqual(ctx.offset, 16)
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == 0
     self.assertEqual(ctx.offset, len(r))
示例#4
0
 def test_trailing_whitespace(self):
     r = b'{ "foo": "bar" } '
     ctx = split_string(r)
     self.assertEqual(ctx.error, 0)
     self.assertEqual(ctx.offset, len(r) - 1)
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == _lib.INCOMPLETE
     self.assertEqual(ctx.offset, len(r))
示例#5
0
 def test_multiple(self):
     r = b'{ "foo": "bar" } { "baz": "qux" }'
     ctx = split_string(r)
     self.assertEqual(ctx.error, 0)
     self.assertEqual(ctx.offset, 16)
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == 0
     self.assertEqual(ctx.offset, len(r))
示例#6
0
 def test_trailing_whitespace(self):
     r = b'{ "foo": "bar" } '
     ctx = split_string(r)
     self.assertEqual(ctx.error, 0)
     self.assertEqual(ctx.offset, len(r)-1)
     error = _lib.json_split(ctx)
     self.assertEqual(error, ctx.error) == _lib.INCOMPLETE
     self.assertEqual(ctx.offset, len(r))
示例#7
0
def split_string(s):
    ctx = _ffi.new('struct split_context *')
    set_buffer(ctx, s)
    _lib.json_split(ctx)
    return ctx
示例#8
0
def split_string(s):
    ctx = _ffi.new('struct split_context *')
    set_buffer(ctx, s)
    _lib.json_split(ctx)
    return ctx