summaryrefslogtreecommitdiff
path: root/ext/librethinkdbxx/test/upstream/math_logic/add.yaml
blob: e956aaa7919878b87191314a55d5760369b297b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
desc: Tests for basic usage of the add operation
tests:
    - cd: r.add(1, 1)
      ot: 2
    
    - js: r(1).add(1)
      py:
        - r.expr(1) + 1
        - 1 + r.expr(1)
        - r.expr(1).add(1)
      rb:
        - r(1) + 1
        - r(1).add(1)
      ot: 2

    - py: r.expr(-1) + 1
      js: r(-1).add(1)
      rb: (r -1) + 1
      ot: 0

    - py: r.expr(1.75) + 8.5
      js: r(1.75).add(8.5)
      rb: (r 1.75) + 8.5
      ot: 10.25

    # Add is polymorphic on strings
    - py: r.expr('') + ''
      js: r('').add('')
      rb: (r '') + ''
      ot: ''

    - py: r.expr('abc') + 'def'
      js: r('abc').add('def')
      rb: (r 'abc') + 'def'
      ot: 'abcdef'

    # Add is polymorphic on arrays
    - cd: r.expr([1,2]) + [3] + [4,5] + [6,7,8]
      js: r([1,2]).add([3]).add([4,5]).add([6,7,8])
      ot: [1,2,3,4,5,6,7,8]

    # All arithmetic operations (except mod) actually support arbitrary arguments
    # but this feature can't be accessed in Python because it's operators are binary
    - js: r(1).add(2,3,4,5)
      ot: 15

    - js: r('a').add('b', 'c', 'd')
      ot: 'abcd'

    # Type errors
    - cd: r(1).add('a')
      py: r.expr(1) + 'a'
      rb: r(1) + 'a'
      ot: err("ReqlQueryLogicError", "Expected type NUMBER but found STRING.", [1])

    - cd: r('a').add(1)
      py: r.expr('a') + 1
      rb: r('a') + 1
      ot: err("ReqlQueryLogicError", "Expected type STRING but found NUMBER.", [1])

    - cd: r([]).add(1)
      py: r.expr([]) + 1
      rb: r([]) + 1
      ot: err("ReqlQueryLogicError", "Expected type ARRAY but found NUMBER.", [1])