@@ -41,6 +41,9 @@ import {
41
41
} from '../../util/helpers' ;
42
42
43
43
describe ( 'Target Bounds' , ( ) => {
44
+ // TODO(indexing): Consider adding more test helpers to reduce the boilerplate
45
+ // in these tests.
46
+
44
47
it ( 'empty query' , ( ) => {
45
48
const target = queryToTarget ( query ( 'c' ) ) ;
46
49
const index = fieldIndex ( 'c' ) ;
@@ -52,7 +55,7 @@ describe('Target Bounds', () => {
52
55
verifyBound ( upperBound , true ) ;
53
56
} ) ;
54
57
55
- it ( 'equals query' , ( ) => {
58
+ it ( 'equals query with ascending index ' , ( ) => {
56
59
const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '==' , 'bar' ) ) ) ;
57
60
const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . ASCENDING ] ] } ) ;
58
61
@@ -63,18 +66,40 @@ describe('Target Bounds', () => {
63
66
verifyBound ( upperBound , true , 'bar' ) ;
64
67
} ) ;
65
68
66
- it ( 'less than query' , ( ) => {
67
- const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '< ' , 'bar' ) ) ) ;
69
+ it ( 'equals query with descending index ' , ( ) => {
70
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '== ' , 'bar' ) ) ) ;
68
71
const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . DESCENDING ] ] } ) ;
69
72
73
+ const lowerBound = targetGetLowerBound ( target , index ) ;
74
+ verifyBound ( lowerBound , true , 'bar' ) ;
75
+
76
+ const upperBound = targetGetUpperBound ( target , index ) ;
77
+ verifyBound ( upperBound , true , 'bar' ) ;
78
+ } ) ;
79
+
80
+ it ( 'less than query with ascending index' , ( ) => {
81
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '<' , 'bar' ) ) ) ;
82
+ const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . ASCENDING ] ] } ) ;
83
+
70
84
const lowerBound = targetGetLowerBound ( target , index ) ;
71
85
verifyBound ( lowerBound , true , '' ) ;
72
86
73
87
const upperBound = targetGetUpperBound ( target , index ) ;
74
88
verifyBound ( upperBound , false , 'bar' ) ;
75
89
} ) ;
76
90
77
- it ( 'less than or equals query' , ( ) => {
91
+ it ( 'less than query with descending index' , ( ) => {
92
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '<' , 'bar' ) ) ) ;
93
+ const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . DESCENDING ] ] } ) ;
94
+
95
+ const lowerBound = targetGetLowerBound ( target , index ) ;
96
+ verifyBound ( lowerBound , false , 'bar' ) ;
97
+
98
+ const upperBound = targetGetUpperBound ( target , index ) ;
99
+ verifyBound ( upperBound , true , '' ) ;
100
+ } ) ;
101
+
102
+ it ( 'less than or equals query with ascending index' , ( ) => {
78
103
const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '<=' , 'bar' ) ) ) ;
79
104
const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . ASCENDING ] ] } ) ;
80
105
@@ -85,7 +110,18 @@ describe('Target Bounds', () => {
85
110
verifyBound ( upperBound , true , 'bar' ) ;
86
111
} ) ;
87
112
88
- it ( 'greater than query' , ( ) => {
113
+ it ( 'less than or equals query with descending index' , ( ) => {
114
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '<=' , 'bar' ) ) ) ;
115
+ const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . DESCENDING ] ] } ) ;
116
+
117
+ const lowerBound = targetGetLowerBound ( target , index ) ;
118
+ verifyBound ( lowerBound , true , 'bar' ) ;
119
+
120
+ const upperBound = targetGetUpperBound ( target , index ) ;
121
+ verifyBound ( upperBound , true , '' ) ;
122
+ } ) ;
123
+
124
+ it ( 'greater than query with ascending index' , ( ) => {
89
125
const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '>' , 'bar' ) ) ) ;
90
126
const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . ASCENDING ] ] } ) ;
91
127
@@ -96,17 +132,39 @@ describe('Target Bounds', () => {
96
132
verifyBound ( upperBound , false , blob ( ) ) ;
97
133
} ) ;
98
134
99
- it ( 'greater than or equals query ' , ( ) => {
100
- const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '>= ' , 'bar' ) ) ) ;
135
+ it ( 'greater than query with descending index ' , ( ) => {
136
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '>' , 'bar' ) ) ) ;
101
137
const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . DESCENDING ] ] } ) ;
102
138
139
+ const lowerBound = targetGetLowerBound ( target , index ) ;
140
+ verifyBound ( lowerBound , false , blob ( ) ) ;
141
+
142
+ const upperBound = targetGetUpperBound ( target , index ) ;
143
+ verifyBound ( upperBound , false , 'bar' ) ;
144
+ } ) ;
145
+
146
+ it ( 'greater than or equals query with ascending index' , ( ) => {
147
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '>=' , 'bar' ) ) ) ;
148
+ const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . ASCENDING ] ] } ) ;
149
+
103
150
const lowerBound = targetGetLowerBound ( target , index ) ;
104
151
verifyBound ( lowerBound , true , 'bar' ) ;
105
152
106
153
const upperBound = targetGetUpperBound ( target , index ) ;
107
154
verifyBound ( upperBound , false , blob ( ) ) ;
108
155
} ) ;
109
156
157
+ it ( 'greater than or equals query with descending index' , ( ) => {
158
+ const target = queryToTarget ( query ( 'c' , filter ( 'foo' , '>=' , 'bar' ) ) ) ;
159
+ const index = fieldIndex ( 'c' , { fields : [ [ 'foo' , IndexKind . DESCENDING ] ] } ) ;
160
+
161
+ const lowerBound = targetGetLowerBound ( target , index ) ;
162
+ verifyBound ( lowerBound , false , blob ( ) ) ;
163
+
164
+ const upperBound = targetGetUpperBound ( target , index ) ;
165
+ verifyBound ( upperBound , true , 'bar' ) ;
166
+ } ) ;
167
+
110
168
it ( 'arrayContains query' , ( ) => {
111
169
const target = queryToTarget (
112
170
query ( 'c' , filter ( 'foo' , 'array-contains' , 'bar' ) )
0 commit comments