def match(self, root_value: object, current_value: object) -> Generator[MatchData, None, None]: """Match the root value with the current value.""" # NOTE Depth-first return itertools.chain( self.next_node.match(root_value, current_value), SubscriptNode(self, [WildcardSubscript()]).match(root_value, current_value))
def exitSubscriptableBareword( self, ctx: JSONPathParser.SubscriptableBarewordContext): if bool(ctx.ID()): text = ctx.ID().getText() self._stack.append(ObjectIndexSubscript(text)) elif ctx.getToken(JSONPathParser.WILDCARD_SUBSCRIPT, 0) is not None: self._stack.append(WildcardSubscript()) else: # NOTE Unreachable when listener is used as tree walker. raise ValueError() # pragma: no cover
def exitSubscriptable(self, ctx: JSONPathParser.SubscriptableContext): if bool(ctx.STRING()): text = ctx.STRING().getText()[1:-1] self._stack.append(ObjectIndexSubscript(text)) elif bool(ctx.NUMBER()): if bool(ctx.sliceable()): func = self._stack.pop() start = int(ctx.NUMBER().getText()) if bool( ctx.NUMBER()) else None self._stack.append(func(start)) else: index = int(ctx.NUMBER().getText()) self._stack.append(ArrayIndexSubscript(index)) elif bool(ctx.sliceable()): func = self._stack.pop() start = None self._stack.append(func(start)) elif ctx.getToken(JSONPathParser.WILDCARD_SUBSCRIPT, 0) is not None: self._stack.append(WildcardSubscript()) elif ctx.getToken(JSONPathParser.QUESTION, 0) is not None: expression = self._stack.pop() self._stack.append(FilterSubscript(expression)) elif bool(ctx.jsonpath_()): next_node = self._stack.pop() self._stack.append(NodeSubscript(next_node)) elif bool(ctx.ID()): text = ctx.ID().getText() args = self._stack.pop() self._stack.append(_createCallableSubscript(text, *args)) else: # NOTE Unreachable when listener is used as tree walker. raise ValueError() # pragma: no cover
def setUp(self): """Setup the class.""" root_value = { 'hello': 'Hello, world!', 'languages': [ 'en-GB', 'en-US', ], } current_value = root_value['hello'] self._state = [ { '__jsonpath__': '', 'node': TerminalNode(), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '$', 'node': RootNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(RootNode(TerminalNode()), root_value, root_value), ], }, { '__jsonpath__': '@', 'node': CurrentNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(CurrentNode(TerminalNode()), root_value, current_value), ], }, { '__jsonpath__': '[]', 'node': SubscriptNode(TerminalNode(), []), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [], }, { '__jsonpath__': '[?(@)]', 'node': SubscriptNode(TerminalNode(), [ FilterSubscript(SomeExpression(CurrentNode( TerminalNode()))) ]), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '[?(@),?(@)]', 'node': SubscriptNode(TerminalNode(), [ FilterSubscript(SomeExpression(CurrentNode( TerminalNode()))), FilterSubscript(SomeExpression(CurrentNode( TerminalNode()))) ]), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '[*]', 'node': SubscriptNode(TerminalNode(), [WildcardSubscript()]), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [], }, { '__jsonpath__': '[*]', 'node': SubscriptNode(TerminalNode(), [WildcardSubscript()]), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('languages')]), root_value, root_value['languages']), ], }, { '__jsonpath__': '["languages"][*]', 'node': SubscriptNode( SubscriptNode(TerminalNode(), [WildcardSubscript()]), [ObjectIndexSubscript('languages')]), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][0]), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][1]), ], }, { '__jsonpath__': '["hello","languages"]', 'node': SubscriptNode(TerminalNode(), [ ObjectIndexSubscript('hello'), ObjectIndexSubscript('languages') ]), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('languages')]), root_value, root_value['languages']), ], }, { '__jsonpath__': '..', 'node': RecursiveDescentNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '..', 'node': RecursiveDescentNode(TerminalNode()), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, root_value), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('languages')]), root_value, root_value['languages']), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][0]), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][1]), ], }, { '__jsonpath__': '..[?(@)]', 'node': RecursiveDescentNode( SubscriptNode(TerminalNode(), [ FilterSubscript( SomeExpression(CurrentNode(TerminalNode()))) ])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, root_value), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('languages')]), root_value, root_value['languages']), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][0]), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][1]), ], }, { '__jsonpath__': '..[*]', 'node': RecursiveDescentNode( SubscriptNode(TerminalNode(), [WildcardSubscript()])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('languages')]), root_value, root_value['languages']), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][0]), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][1]), ], }, { '__jsonpath__': '..["hello"]', 'node': RecursiveDescentNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')]), root_value, root_value['hello']), ], }, { '__jsonpath__': '..[0]', 'node': RecursiveDescentNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript('languages')]), root_value, root_value['languages'][0]), ], }, ]
def setUp(self): """Setup the class.""" root_value = { 'hello': 'Hello, world!', 'languages': [ 'en-GB', 'en-US', ], 'preferences': { 'coffee': True, 'tea': False, }, } current_value = root_value['hello'] self._state = [ { '__jsonpath__': '', 'node': TerminalNode(), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '$', 'node': RootNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(RootNode(TerminalNode()), root_value, root_value), ], }, { '__jsonpath__': '@', 'node': CurrentNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(CurrentNode(TerminalNode()), root_value, current_value), ], }, { '__jsonpath__': '[]', 'node': SubscriptNode(TerminalNode(), []), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [], }, { '__jsonpath__': '[?(@)]', 'node': SubscriptNode(TerminalNode(), [FilterSubscript(SomeExpression(CurrentNode(TerminalNode())))]), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '[?(@),?(@)]', 'node': SubscriptNode( TerminalNode(), [ FilterSubscript(SomeExpression( CurrentNode(TerminalNode()))), FilterSubscript(SomeExpression( CurrentNode(TerminalNode()))) ] ), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '[*]', 'node': SubscriptNode(TerminalNode(), [WildcardSubscript()]), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [], }, { '__jsonpath__': '[*]', 'node': SubscriptNode(TerminalNode(), [WildcardSubscript()]), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'languages')]), root_value, root_value['languages']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'preferences')]), root_value, root_value['preferences']), ], }, { '__jsonpath__': '["languages"][*]', 'node': SubscriptNode( SubscriptNode(TerminalNode(), [WildcardSubscript()]), [ObjectIndexSubscript('languages')] ), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(0)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][0] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][1] ), ], }, { '__jsonpath__': '["hello","languages"]', 'node': SubscriptNode( TerminalNode(), [ObjectIndexSubscript('hello'), ObjectIndexSubscript('languages')] ), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'languages')]), root_value, root_value['languages']), ], }, { '__jsonpath__': '..', 'node': RecursiveDescentNode(TerminalNode()), 'root_value': root_value, 'current_value': current_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, current_value), ], }, { '__jsonpath__': '..', 'node': RecursiveDescentNode(TerminalNode()), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, root_value), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'languages')]), root_value, root_value['languages']), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(0)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][0] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(1)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][1] ), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'preferences')]), root_value, root_value['preferences']), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('coffee')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['coffee'] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('tea')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['tea'] ), ], }, { '__jsonpath__': '..[?(@)]', 'node': RecursiveDescentNode( SubscriptNode( TerminalNode(), [ FilterSubscript(SomeExpression( CurrentNode(TerminalNode()))) ] ) ), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(TerminalNode(), root_value, root_value), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'languages')]), root_value, root_value['languages']), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(0)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][0] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(1)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][1] ), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'preferences')]), root_value, root_value['preferences']), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('coffee')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['coffee'] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('tea')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['tea'] ), ], }, { '__jsonpath__': '..[*]', 'node': RecursiveDescentNode(SubscriptNode(TerminalNode(), [WildcardSubscript()])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'languages')]), root_value, root_value['languages']), MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'preferences')]), root_value, root_value['preferences']), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(0)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][0] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(1)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][1] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('coffee')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['coffee'] ), MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ObjectIndexSubscript('tea')] ), [ObjectIndexSubscript('preferences')] ), root_value, root_value['preferences']['tea'] ), ], }, { '__jsonpath__': '..["hello"]', 'node': RecursiveDescentNode(SubscriptNode(TerminalNode(), [ObjectIndexSubscript('hello')])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData(SubscriptNode(TerminalNode(), [ObjectIndexSubscript( 'hello')]), root_value, root_value['hello']), ], }, { '__jsonpath__': '..[0]', 'node': RecursiveDescentNode(SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)])), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ArrayIndexSubscript(0)] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'][0] ), ], }, { '__jsonpath__': '["hello"][length()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript('hello')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [LengthCallableSubscript()] ), [ObjectIndexSubscript('hello')] ), root_value, len(root_value['hello']) ), ], }, { '__jsonpath__': '["hello"][charAt(0)]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [CharAtCallableSubscript(0)]), [ObjectIndexSubscript('hello')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [CharAtCallableSubscript(MatchData(TerminalNode(), root_value, 0))] ), [ObjectIndexSubscript('hello')] ), root_value, root_value['hello'][0] ), ], }, { '__jsonpath__': '["hello"][charAt(1000)]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [CharAtCallableSubscript(1000)]), [ObjectIndexSubscript('hello')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [], }, { '__jsonpath__': '["hello"][charAt($["hello"][length()])]', 'node': SubscriptNode(SubscriptNode(TerminalNode(), [CharAtCallableSubscript( RootNode( SubscriptNode( SubscriptNode( TerminalNode(), [LengthCallableSubscript()] ), [ObjectIndexSubscript('hello')] ) ) )]), [ObjectIndexSubscript('hello')]), 'root_value': root_value, 'current_value': root_value, 'match_data_list': [], }, { '__jsonpath__': '["hello"][substring(1)]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [SubstringCallableSubscript(1)]), [ObjectIndexSubscript('hello')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [SubstringCallableSubscript(MatchData(TerminalNode(), root_value, 1))] ), [ObjectIndexSubscript('hello')] ), root_value, root_value['hello'][1:] ), ], }, { '__jsonpath__': '["hello"][substring(1,3)]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [SubstringCallableSubscript(1, 3)]), [ObjectIndexSubscript('hello')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [SubstringCallableSubscript(MatchData(TerminalNode(), root_value, 1), MatchData(TerminalNode(), root_value, 3))] ), [ObjectIndexSubscript('hello')] ), root_value, root_value['hello'][1:3] ), ], }, { '__jsonpath__': '["languages"][length()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript('languages')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [LengthCallableSubscript()] ), [ObjectIndexSubscript('languages')] ), root_value, len(root_value['languages']) ), ], }, { '__jsonpath__': '["languages"][entries()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript('languages')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [EntriesCallableSubscript()] ), [ObjectIndexSubscript('languages')] ), root_value, list(map(list, enumerate(root_value['languages']))) ), ], }, { '__jsonpath__': '["languages"][keys()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript('languages')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [KeysCallableSubscript()] ), [ObjectIndexSubscript('languages')] ), root_value, list(range(len(root_value['languages']))) ), ], }, { '__jsonpath__': '["languages"][values()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript('languages')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ValuesCallableSubscript()] ), [ObjectIndexSubscript('languages')] ), root_value, root_value['languages'] ), ], }, { '__jsonpath__': '["preferences"][entries()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript('preferences')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [EntriesCallableSubscript()] ), [ObjectIndexSubscript('preferences')] ), root_value, list(map(list, root_value['preferences'].items())) ), ], }, { '__jsonpath__': '["preferences"][keys()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript('preferences')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [KeysCallableSubscript()] ), [ObjectIndexSubscript('preferences')] ), root_value, list(root_value['preferences'].keys()) ), ], }, { '__jsonpath__': '["preferences"][values()]', # pylint: disable=line-too-long 'node': SubscriptNode(SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript('preferences')]), # noqa: E501 # pylint: enable=line-too-long 'root_value': root_value, 'current_value': root_value, 'match_data_list': [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ValuesCallableSubscript()] ), [ObjectIndexSubscript('preferences')] ), root_value, list(root_value['preferences'].values()) ), ], }, ]
def setUp(self): """Setup the class.""" root_value = { "hello": "Hello, world!", "languages": [ "en-GB", "en-US", ], "preferences": { "coffee": True, "tea": False, }, } current_value = root_value["hello"] self._state = [ { "__jsonpath__": "", "node": TerminalNode(), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(TerminalNode(), root_value, current_value), ], }, { "__jsonpath__": "$", "node": RootNode(TerminalNode()), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(RootNode(TerminalNode()), root_value, root_value), ], }, { "__jsonpath__": "@", "node": CurrentNode(TerminalNode()), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(CurrentNode(TerminalNode()), root_value, current_value), ], }, { "__jsonpath__": "[]", "node": SubscriptNode(TerminalNode(), []), "root_value": root_value, "current_value": current_value, "match_data_list": [], }, { "__jsonpath__": "[?(@)]", "node": SubscriptNode( TerminalNode(), [ FilterSubscript( SomeExpression(CurrentNode(TerminalNode()))) ], ), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(TerminalNode(), root_value, current_value), ], }, { "__jsonpath__": "[?(@),?(@)]", "node": SubscriptNode( TerminalNode(), [ FilterSubscript( SomeExpression(CurrentNode(TerminalNode()))), FilterSubscript( SomeExpression(CurrentNode(TerminalNode()))), ], ), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(TerminalNode(), root_value, current_value), MatchData(TerminalNode(), root_value, current_value), ], }, { "__jsonpath__": "[*]", "node": SubscriptNode(TerminalNode(), [WildcardSubscript()]), "root_value": root_value, "current_value": current_value, "match_data_list": [], }, { "__jsonpath__": "[*]", "node": SubscriptNode(TerminalNode(), [WildcardSubscript()]), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("languages")]), root_value, root_value["languages"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("preferences")]), root_value, root_value["preferences"], ), ], }, { "__jsonpath__": '["languages"][*]', "node": SubscriptNode( SubscriptNode(TerminalNode(), [WildcardSubscript()]), [ObjectIndexSubscript("languages")], ), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][0], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][1], ), ], }, { "__jsonpath__": '["hello","languages"]', "node": SubscriptNode( TerminalNode(), [ ObjectIndexSubscript("hello"), ObjectIndexSubscript("languages") ], ), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("languages")]), root_value, root_value["languages"], ), ], }, { "__jsonpath__": "..", "node": RecursiveDescentNode(TerminalNode()), "root_value": root_value, "current_value": current_value, "match_data_list": [ MatchData(TerminalNode(), root_value, current_value), ], }, { "__jsonpath__": "..", "node": RecursiveDescentNode(TerminalNode()), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData(TerminalNode(), root_value, root_value), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("languages")]), root_value, root_value["languages"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][0], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][1], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("preferences")]), root_value, root_value["preferences"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("coffee")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["coffee"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("tea")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["tea"], ), ], }, { "__jsonpath__": "..[?(@)]", "node": RecursiveDescentNode( SubscriptNode( TerminalNode(), [ FilterSubscript( SomeExpression(CurrentNode(TerminalNode()))) ], )), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData(TerminalNode(), root_value, root_value), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("languages")]), root_value, root_value["languages"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][0], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][1], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("preferences")]), root_value, root_value["preferences"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("coffee")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["coffee"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("tea")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["tea"], ), ], }, { "__jsonpath__": "..[*]", "node": RecursiveDescentNode( SubscriptNode(TerminalNode(), [WildcardSubscript()])), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("languages")]), root_value, root_value["languages"], ), MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("preferences")]), root_value, root_value["preferences"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][0], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(1)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][1], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("coffee")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["coffee"], ), MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("tea")]), [ObjectIndexSubscript("preferences")], ), root_value, root_value["preferences"]["tea"], ), ], }, { "__jsonpath__": '..["hello"]', "node": RecursiveDescentNode( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")])), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode(TerminalNode(), [ObjectIndexSubscript("hello")]), root_value, root_value["hello"], ), ], }, { "__jsonpath__": "..[0]", "node": RecursiveDescentNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)])), "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ArrayIndexSubscript(0)]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"][0], ), ], }, { "__jsonpath__": '["hello"][length()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript("hello")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript("hello")], ), root_value, len(root_value["hello"]), ), ], }, { "__jsonpath__": '["hello"][charAt(0)]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [CharAtCallableSubscript(0)]), [ObjectIndexSubscript("hello")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ CharAtCallableSubscript( MatchData(TerminalNode(), root_value, 0)) ], ), [ObjectIndexSubscript("hello")], ), root_value, root_value["hello"][0], ), ], }, { "__jsonpath__": '["hello"][charAt(1000)]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [CharAtCallableSubscript(1000)]), [ObjectIndexSubscript("hello")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [], }, { "__jsonpath__": '["hello"][charAt($["hello"][length()])]', "node": SubscriptNode( SubscriptNode( TerminalNode(), [ CharAtCallableSubscript( RootNode( SubscriptNode( SubscriptNode( TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript("hello")], ))) ], ), [ObjectIndexSubscript("hello")], ), "root_value": root_value, "current_value": root_value, "match_data_list": [], }, { "__jsonpath__": '["hello"][substring(1)]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [SubstringCallableSubscript(1)]), [ObjectIndexSubscript("hello")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ SubstringCallableSubscript( MatchData(TerminalNode(), root_value, 1)) ], ), [ObjectIndexSubscript("hello")], ), root_value, root_value["hello"][1:], ), ], }, { "__jsonpath__": '["hello"][substring(1,3)]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [SubstringCallableSubscript(1, 3)]), [ObjectIndexSubscript("hello")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode( TerminalNode(), [ SubstringCallableSubscript( MatchData(TerminalNode(), root_value, 1), MatchData(TerminalNode(), root_value, 3), ) ], ), [ObjectIndexSubscript("hello")], ), root_value, root_value["hello"][1:3], ), ], }, { "__jsonpath__": '["languages"][length()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript("languages")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [LengthCallableSubscript()]), [ObjectIndexSubscript("languages")], ), root_value, len(root_value["languages"]), ), ], }, { "__jsonpath__": '["languages"][entries()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript("languages")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript("languages")], ), root_value, list(map(list, enumerate(root_value["languages"]))), ), ], }, { "__jsonpath__": '["languages"][keys()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript("languages")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript("languages")], ), root_value, list(range(len(root_value["languages"]))), ), ], }, { "__jsonpath__": '["languages"][values()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript("languages")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript("languages")], ), root_value, root_value["languages"], ), ], }, { "__jsonpath__": '["preferences"][entries()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [EntriesCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), root_value, list(map(list, root_value["preferences"].items())), ), ], }, { "__jsonpath__": '["preferences"][keys()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [KeysCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), root_value, list(root_value["preferences"].keys()), ), ], }, { "__jsonpath__": '["preferences"][values()]', # pylint: disable=line-too-long "node": SubscriptNode( SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), # noqa: E501 # pylint: enable=line-too-long "root_value": root_value, "current_value": root_value, "match_data_list": [ MatchData( SubscriptNode( SubscriptNode(TerminalNode(), [ValuesCallableSubscript()]), [ObjectIndexSubscript("preferences")], ), root_value, list(root_value["preferences"].values()), ), ], }, ]