def _token_nud_star(self, token): left = ast.Identity() if self._current_token() == 'rbracket': right = ast.Identity() else: right = self._parse_projection_rhs(self.BINDING_POWER['star']) return ast.ValueProjection(left, right)
def test_root_value_projection(self): # * projection = ast.ValueProjection(ast.Identity(), ast.Identity()) data = { 'a': 1, 'b': 2, 'c': 3, } result = list(sorted(projection.search(data))) self.assertEqual(result, [1, 2, 3])
def _token_led_dot(self, left): if not self._current_token() == 'star': right = self._parse_dot_rhs(self.BINDING_POWER['dot']) return ast.SubExpression(left, right) else: # We're creating a projection. self._advance() right = self._parse_projection_rhs( self.BINDING_POWER['dot']) return ast.ValueProjection(left, right)
def test_no_right_node_value_projection(self): # foo.* field_foo = ast.Field('foo') projection = ast.ValueProjection(field_foo, ast.Identity()) data = { 'foo': { 'a': 1, 'b': 2, 'c': 3, } } result = list(sorted(projection.search(data))) self.assertEqual(result, [1, 2, 3])
def test_no_left_node_value_projection(self): # *.bar field_bar = ast.Field('bar') projection = ast.ValueProjection(ast.Identity(), field_bar) data = { 'a': { 'bar': 1 }, 'b': { 'bar': 2 }, 'c': { 'bar': 3 }, } result = list(sorted(projection.search(data))) self.assertEqual(result, [1, 2, 3])
def test_values_projection(self): # foo.*.bar field_foo = ast.Field('foo') field_bar = ast.Field('bar') projection = ast.ValueProjection(field_foo, field_bar) data = { 'foo': { 'a': { 'bar': 1 }, 'b': { 'bar': 2 }, 'c': { 'bar': 3 }, } } result = list(sorted(projection.search(data))) self.assertEqual(result, [1, 2, 3])