86 lines
2.4 KiB
YAML
86 lines
2.4 KiB
YAML
desc: Tests conversion to and from the RQL object type
|
|
tests:
|
|
- cd:
|
|
- r({})
|
|
- r.expr({})
|
|
py: r.expr({})
|
|
ot: {}
|
|
- cd:
|
|
- r({a:1})
|
|
- r.expr({'a':1})
|
|
py: r.expr({'a':1})
|
|
ot: {'a':1}
|
|
- cd:
|
|
- r({a:1, b:'two', c:True})
|
|
- r.expr({'a':1, 'b':'two', 'c':True})
|
|
py: r.expr({'a':1, 'b':'two', 'c':True})
|
|
ot: {'a':1, 'b':'two', 'c':True}
|
|
|
|
# Nested expressions
|
|
- cd: r.expr({'a':r.expr(1)})
|
|
ot: {'a':1}
|
|
|
|
- cd: r.expr({'a':{'b':[{'c':2}, 'a', 4]}})
|
|
ot: {'a':{'b':[{'c':2}, 'a', 4]}}
|
|
|
|
- cd: r.expr({'a':1}).type_of()
|
|
ot: 'OBJECT'
|
|
|
|
# test coercions
|
|
- cd: r.expr({'a':1}).coerce_to('string')
|
|
ot:
|
|
cd: '{"a":1}'
|
|
|
|
- cd: r.expr({'a':1}).coerce_to('object')
|
|
ot: {'a':1}
|
|
|
|
- cd: r.expr({'a':1}).coerce_to('array')
|
|
ot: [['a',1]]
|
|
|
|
# Error cases
|
|
- cd: r.expr({12:'a'})
|
|
# JavaScript auto-converts keys for us
|
|
js:
|
|
ot: err_regex("ReqlCompileError", "Object keys must be strings.*")
|
|
|
|
- cd: r.expr({'a':{12:'b'}})
|
|
# JavaScript auto-converts keys for us
|
|
js:
|
|
ot: err_regex("ReqlCompileError", "Object keys must be strings.*")
|
|
|
|
- js: r({'a':undefined})
|
|
ot: err("ReqlCompileError", "Object field 'a' may not be undefined")
|
|
|
|
- js: r({'a':{'b':undefined}})
|
|
ot: err("ReqlCompileError", "Object field 'b' may not be undefined")
|
|
|
|
- cd: r.expr({}, "foo")
|
|
ot:
|
|
cd: err("ReqlCompileError", "Second argument to `r.expr` must be a number.")
|
|
js: err("ReqlCompileError", "Second argument to `r.expr` must be a number or undefined.")
|
|
|
|
- js: r.expr({}, NaN)
|
|
ot: err("ReqlCompileError", "Second argument to `r.expr` must be a number or undefined.")
|
|
|
|
# r.object
|
|
- cd: r.object()
|
|
ot: {}
|
|
|
|
- cd: r.object('a', 1, 'b', 2)
|
|
ot: {'a':1,'b':2}
|
|
|
|
- cd: r.object('c'+'d', 3)
|
|
ot: {'cd':3}
|
|
|
|
- cd: r.object('o','d','d')
|
|
ot: err("ReqlQueryLogicError", "OBJECT expects an even number of arguments (but found 3).", [])
|
|
|
|
- cd: r.object(1, 1)
|
|
ot: err("ReqlQueryLogicError","Expected type STRING but found NUMBER.",[])
|
|
|
|
- cd: r.object('e', 4, 'e', 5)
|
|
ot: err("ReqlQueryLogicError","Duplicate key \"e\" in object. (got 4 and 5 as values)",[])
|
|
|
|
- cd: r.object('g', r.db('test'))
|
|
ot: err("ReqlQueryLogicError","Expected type DATUM but found DATABASE:",[])
|