| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- desc: Tests of converstion to and from the RQL binary type
- tests:
- # Short binary data from 0 to 12 characters
- # Not fully implemented for JS as comparing Buffer objects is non-trivial
- - def:
- rb: s = "".force_encoding('BINARY')
- py: s = b''
- js: s = Buffer("", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 0
- - def:
- rb: s = "\x00".force_encoding('BINARY')
- py: s = b'\x00'
- js: s = Buffer("\x00", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 1
- - def:
- rb: s = "\x00\x42".force_encoding('BINARY')
- py: s = b'\x00\x42'
- js: s = Buffer("\x00\x42", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 2
- - def:
- rb: s = "\x00\xfe\x7a".force_encoding('BINARY')
- py: s = b'\x00\xfe\x7a'
- js: s = Buffer("\x00\xfe\x7a", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 3
- - def:
- rb: s = "\xed\xfe\x00\xba".force_encoding('BINARY')
- py: s = b'\xed\xfe\x00\xba'
- js: s = Buffer("\xed\xfe\x00\xba", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 4
- - def:
- rb: s = "\x50\xf9\x00\x77\xf9".force_encoding('BINARY')
- py: s = b'\x50\xf9\x00\x77\xf9'
- js: s = Buffer("\x50\xf9\x00\x77\xf9", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 5
- - def:
- rb: s = "\x2f\xe3\xb5\x57\x00\x92".force_encoding('BINARY')
- py: s = b'\x2f\xe3\xb5\x57\x00\x92'
- js: s = Buffer("\x2f\xe3\xb5\x57\x00\x92", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 6
- - def:
- rb: s = "\xa9\x43\x54\xe9\x00\xf8\xfb".force_encoding('BINARY')
- py: s = b'\xa9\x43\x54\xe9\x00\xf8\xfb'
- js: s = Buffer("\xa9\x43\x54\xe9\x00\xf8\xfb", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 7
- - def:
- rb: s = "\x57\xbb\xe5\x82\x8b\xd3\x00\xf9".force_encoding('BINARY')
- py: s = b'\x57\xbb\xe5\x82\x8b\xd3\x00\xf9'
- js: s = Buffer("\x57\xbb\xe5\x82\x8b\xd3\x00\xf9", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 8
- - def:
- rb: s = "\x44\x1b\x3e\x00\x13\x19\x29\x2a\xbf".force_encoding('BINARY')
- py: s = b'\x44\x1b\x3e\x00\x13\x19\x29\x2a\xbf'
- js: s = Buffer("\x44\x1b\x3e\x00\x13\x19\x29\x2a\xbf", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 9
- - def:
- rb: s = "\x8a\x1d\x09\x00\x5d\x60\x6b\x2e\x70\xd9".force_encoding('BINARY')
- py: s = b'\x8a\x1d\x09\x00\x5d\x60\x6b\x2e\x70\xd9'
- js: s = Buffer("\x8a\x1d\x09\x00\x5d\x60\x6b\x2e\x70\xd9", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 10
- - def:
- rb: s = "\x00\xaf\x47\x4b\x38\x99\x14\x8d\x8f\x10\x51".force_encoding('BINARY')
- py: s = b'\x00\xaf\x47\x4b\x38\x99\x14\x8d\x8f\x10\x51'
- js: s = Buffer("\x00\xaf\x47\x4b\x38\x99\x14\x8d\x8f\x10\x51", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 11
- - def:
- cd: s = "\x45\x39\x00\xf7\xc2\x37\xfd\xe0\x38\x82\x40\xa9".force_encoding('BINARY')
- py: s = b'\x45\x39\x00\xf7\xc2\x37\xfd\xe0\x38\x82\x40\xa9'
- js: s = Buffer("\x45\x39\x00\xf7\xc2\x37\xfd\xe0\x38\x82\x40\xa9", 'binary')
- - cd: r.binary(s)
- ot: s
- - cd: r.binary(s).count()
- ot: 12
- # Test comparisons
- # Binary objects to use, in order of increasing value
- - def:
- js: a = Buffer("\x00", 'binary')
- rb: a = "\x00".force_encoding('BINARY')
- py: a = b'\x00'
- - def:
- js: b = Buffer("\x00\x01", 'binary')
- rb: b = "\x00\x01".force_encoding('BINARY')
- py: b = b'\x00\x01'
- - def:
- js: c = Buffer("\x01", 'binary')
- rb: c = "\x01".force_encoding('BINARY')
- py: c = b'\x01'
- - def:
- js: d = Buffer("\x70\x22", 'binary')
- rb: d = "\x70\x22".force_encoding('BINARY')
- py: d = b'\x70\x22'
- - def:
- js: e = Buffer("\x80", 'binary')
- rb: e = "\x80".force_encoding('BINARY')
- py: e = b'\x80'
- - def:
- js: f = Buffer("\xFE", 'binary')
- rb: f = "\xFE".force_encoding('BINARY')
- py: f = b'\xFE'
- # a -> a
- - cd: r.binary(a).eq(r.binary(a))
- ot: true
- - cd: r.binary(a).le(r.binary(a))
- ot: true
- - cd: r.binary(a).ge(r.binary(a))
- ot: true
- - cd: r.binary(a).ne(r.binary(a))
- ot: false
- - cd: r.binary(a).lt(r.binary(a))
- ot: false
- - cd: r.binary(a).gt(r.binary(a))
- ot: false
- # a -> b
- - cd: r.binary(a).ne(r.binary(b))
- ot: true
- - cd: r.binary(a).lt(r.binary(b))
- ot: true
- - cd: r.binary(a).le(r.binary(b))
- ot: true
- - cd: r.binary(a).ge(r.binary(b))
- ot: false
- - cd: r.binary(a).gt(r.binary(b))
- ot: false
- - cd: r.binary(a).eq(r.binary(b))
- ot: false
- # b -> c
- - cd: r.binary(b).ne(r.binary(c))
- ot: true
- - cd: r.binary(b).lt(r.binary(c))
- ot: true
- - cd: r.binary(b).le(r.binary(c))
- ot: true
- - cd: r.binary(b).ge(r.binary(c))
- ot: false
- - cd: r.binary(b).gt(r.binary(c))
- ot: false
- - cd: r.binary(b).eq(r.binary(c))
- ot: false
- # c -> d
- - cd: r.binary(c).ne(r.binary(d))
- ot: true
- - cd: r.binary(c).lt(r.binary(d))
- ot: true
- - cd: r.binary(c).le(r.binary(d))
- ot: true
- - cd: r.binary(c).ge(r.binary(d))
- ot: false
- - cd: r.binary(c).gt(r.binary(d))
- ot: false
- - cd: r.binary(c).eq(r.binary(d))
- ot: false
- # d -> e
- - cd: r.binary(d).ne(r.binary(e))
- ot: true
- - cd: r.binary(d).lt(r.binary(e))
- ot: true
- - cd: r.binary(d).le(r.binary(e))
- ot: true
- - cd: r.binary(d).ge(r.binary(e))
- ot: false
- - cd: r.binary(d).gt(r.binary(e))
- ot: false
- - cd: r.binary(d).eq(r.binary(e))
- ot: false
- # e -> f
- - cd: r.binary(e).ne(r.binary(f))
- ot: true
- - cd: r.binary(e).lt(r.binary(f))
- ot: true
- - cd: r.binary(e).le(r.binary(f))
- ot: true
- - cd: r.binary(e).ge(r.binary(f))
- ot: false
- - cd: r.binary(e).gt(r.binary(f))
- ot: false
- - cd: r.binary(e).eq(r.binary(f))
- ot: false
- # f -> f
- - cd: r.binary(f).eq(r.binary(f))
- ot: true
- - cd: r.binary(f).le(r.binary(f))
- ot: true
- - cd: r.binary(f).ge(r.binary(f))
- ot: true
- - cd: r.binary(f).ne(r.binary(f))
- ot: false
- - cd: r.binary(f).lt(r.binary(f))
- ot: false
- - cd: r.binary(f).gt(r.binary(f))
- ot: false
- # Test encodings
- - py:
- cd: r.binary(u'イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム'.encode('utf-8'))
- ot: u'イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム'.encode('utf-8')
- py3:
- cd: r.binary(str('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム').encode('utf-8'))
- ot: str('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム').encode('utf-8')
- - py:
- cd: r.binary(u'ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏ'.encode('utf-16'))
- ot: u'ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏ'.encode('utf-16')
- py3:
- cd: r.binary(str('ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏ').encode('utf-16'))
- ot: str('ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏ').encode('utf-16')
- - py:
- cd: r.binary(u'lorem ipsum'.encode('ascii'))
- ot: u'lorem ipsum'.encode('ascii')
- py3:
- cd: r.binary(str('lorem ipsum').encode('ascii'))
- ot: str('lorem ipsum').encode('ascii')
- # Test coercions
- - py: r.binary(b'foo').coerce_to('string')
- ot: 'foo'
- - py:
- cd: r.binary(u'イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム'.encode('utf-8')).coerce_to('string')
- ot: u'イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム'
- py3:
- cd: r.binary(str('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム').encode('utf-8')).coerce_to('string')
- ot: str('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム')
- - py:
- cd: r.binary(u'lorem ipsum'.encode('ascii')).coerce_to('string')
- ot: u'lorem ipsum'
- py3:
- cd: r.binary(str('lorem ipsum').encode('ascii')).coerce_to('string')
- ot: str('lorem ipsum')
- - py: r.expr('foo').coerce_to('binary')
- ot: b'foo'
- - cd: r.binary(a).coerce_to('bool')
- ot: True
- - py: r.binary(b'foo').coerce_to('binary')
- ot: b'foo'
- # Test slice
- - py: r.binary(b'abcdefg').slice(-3,-1)
- ot: b'ef'
- - py: r.binary(b'abcdefg').slice(0, 2)
- ot: b'ab'
- - py: r.binary(b'abcdefg').slice(3, -1)
- ot: b'def'
- - py: r.binary(b'abcdefg').slice(-5, 5)
- ot: b'cde'
- - py: r.binary(b'abcdefg').slice(-8, 2)
- ot: b'ab'
- - py: r.binary(b'abcdefg').slice(5, 7)
- ot: b'fg'
- # Left side out-of-bound should clamp to index 0
- - py: r.binary(b'abcdefg').slice(-9, 2)
- ot: b'ab'
- # Right side out-of-bound should return the valid subset of the range
- - py: r.binary(b'abcdefg').slice(5, 9)
- ot: b'fg'
- # Test binary_format optarg
- - cd: r.binary(b)
- runopts:
- binary_format: "native"
- ot: b
- - cd: r.binary(b)
- runopts:
- binary_format: "raw"
- ot: {'$reql_type$':'BINARY','data':'AAE='}
- # Test r.binary of nested terms
- - cd: r.binary(r.expr("data"))
- ot:
- js: Buffer("data", "binary")
- rb: "data"
- py: b"data"
- - cd: r.binary(r.expr({}))
- ot: err('ReqlQueryLogicError', 'Expected type STRING but found OBJECT.', [])
- - cd: r.binary(r.expr([]))
- ot: err('ReqlQueryLogicError', 'Expected type STRING but found ARRAY.', [])
- # Test errors
- # Missing 'data' field
- - py: r.expr({'$reql_type$':'BINARY'})
- rb: r.expr({'$reql_type$':'BINARY'})
- ot: err('ReqlQueryLogicError','Invalid binary pseudotype:'+' lacking `data` key.',[])
- # Invalid base64 format
- - py: r.expr({'$reql_type$':'BINARY','data':'ABCDEFGH==AA'})
- ot: err('ReqlQueryLogicError','Invalid base64 format, data found after padding character \'=\'.',[])
- - py: r.expr({'$reql_type$':'BINARY','data':'ABCDEF==$'})
- ot: err('ReqlQueryLogicError','Invalid base64 format, data found after padding character \'=\'.',[])
- - py: r.expr({'$reql_type$':'BINARY','data':'A^CDEFGH'})
- ot: err('ReqlQueryLogicError','Invalid base64 character found:'+' \'^\'.',[])
- - py: r.expr({'$reql_type$':'BINARY','data':'ABCDE'})
- ot: err('ReqlQueryLogicError','Invalid base64 length:'+' 1 character remaining, cannot decode a full byte.',[])
- # Invalid coercions
- - cd: r.binary(a).coerce_to('array')
- ot: err('ReqlQueryLogicError','Cannot coerce BINARY to ARRAY.',[])
- - cd: r.binary(a).coerce_to('object')
- ot: err('ReqlQueryLogicError','Cannot coerce BINARY to OBJECT.',[])
- - cd: r.binary(a).coerce_to('number')
- ot: err('ReqlQueryLogicError','Cannot coerce BINARY to NUMBER.',[])
- - cd: r.binary(a).coerce_to('nu'+'ll')
- ot: err('ReqlQueryLogicError','Cannot coerce BINARY to NULL.',[])
|