Esempio n. 1
0
    def match(self, root_value: object,
              current_value: object) -> Generator[MatchData, None, None]:
        """Match the root value against the current value."""
        if isinstance(current_value,
                      Sequence) and not isinstance(current_value, str):
            if self.index < 0:
                new_index = self.index + len(current_value)

                if 0 <= new_index < len(current_value):
                    return [
                        MatchData(
                            SubscriptNode(TerminalNode(), [self]),
                            root_value,
                            current_value[new_index],
                        )
                    ]
            elif self.index < len(current_value):
                return [
                    MatchData(
                        SubscriptNode(TerminalNode(), [self]),
                        root_value,
                        current_value[self.index],
                    )
                ]
        return []
Esempio n. 2
0
    def __call__(self, root_value: object, current_value: object) -> Generator[MatchData, None, None]:
        """Perform entries() call."""
        if isinstance(current_value, Mapping):
            if not self.args:
                value = list(map(list, current_value.items()))

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
        elif isinstance(current_value, Sequence) and not isinstance(current_value, str):
            if not self.args:
                value = list(map(list, enumerate(current_value)))

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
Esempio n. 3
0
    def __call__(self, root_value: object, current_value: object) -> Generator[MatchData, None, None]:
        """Perform length() call."""
        if isinstance(current_value, Sequence) and not isinstance(current_value, str):
            if not self.args:
                value = len(current_value)

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
        elif isinstance(current_value, str):
            if not self.args:
                value = len(current_value)

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
 def test_variadic_operator(self):
     """Test a variadic operator."""
     expr = AndVariadicOperatorExpression([])
     self.assertEqual('', expr.tojsonpath())
     expr = AndVariadicOperatorExpression(
         [SomeExpression(CurrentNode(TerminalNode()))])
     self.assertEqual('@', expr.tojsonpath())
Esempio n. 5
0
    def __call__(self, root_value: object, current_value: object) -> Generator[MatchData, None, None]:
        """Perform substring(number[, number]) call."""
        if isinstance(current_value, str):
            if (len(self.args) == 1) \
                    and isinstance(self.args[0].current_value, int):
                value = current_value[self.args[0].current_value:]

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
            elif (len(self.args) == 2) \
                    and isinstance(self.args[0].current_value, int) \
                    and isinstance(self.args[1].current_value, int):
                value = current_value[self.args[0].current_value:self.args[1].current_value]

                yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                root_value, value)
Esempio n. 6
0
 def match(self, root_value: object,
           current_value: object) -> Generator[MatchData, None, None]:
     """Match the current value against the root value."""
     if isinstance(current_value, dict) and (self.index in current_value):
         return [
             MatchData(SubscriptNode(TerminalNode(), [self]), root_value,
                       current_value[self.index])
         ]
     return []
Esempio n. 7
0
 def exitJsonpath(self, ctx: JSONPathParser.JsonpathContext):
     if ctx.getToken(JSONPathParser.ROOT_VALUE, 0) is not None:
         if bool(ctx.subscript()):
             next_node = self._stack.pop()
         else:
             next_node = TerminalNode()
         self._stack.append(RootNode(next_node))
     else:
         # NOTE Unreachable when listener is used as tree walker.
         raise ValueError()  # pragma: no cover
Esempio n. 8
0
 def match(self, root_value: object,
           current_value: object) -> Generator[MatchData, None, None]:
     """Match the root value against the current value."""
     for args in itertools.product(*map(
             lambda arg: [arg] if isinstance(arg, MatchData) else arg.match(
                 root_value, current_value) if isinstance(arg, Node) else
         [MatchData(TerminalNode(), root_value, arg)],
             self.args,
     )):  # noqa: E501
         for callable_subscript_match_data in self.__class__(*args)(
                 root_value, current_value):
             yield callable_subscript_match_data
Esempio n. 9
0
 def __call__(self, root_value: object, current_value: object) -> Generator[MatchData, None, None]:
     """Perform charAt(number) call."""
     if isinstance(current_value, str):
         if (len(self.args) == 1) \
                 and isinstance(self.args[0].current_value, int):
             try:
                 value = current_value[self.args[0].current_value]
             except IndexError:
                 pass
             else:
                 yield MatchData(SubscriptNode(TerminalNode(), [self]),
                                 root_value, value)
Esempio n. 10
0
 def exitSubscript(self, ctx: JSONPathParser.SubscriptContext):
     if ctx.getToken(JSONPathParser.RECURSIVE_DESCENT, 0) is not None:
         if bool(ctx.subscript()):
             next_node = self._stack.pop()
         else:
             next_node = TerminalNode()
         if bool(ctx.subscriptableBareword()):
             subscriptable_nodes = [self._stack.pop()]
         elif bool(ctx.subscriptables()):
             subscriptable_nodes = self._stack.pop()
         else:
             # NOTE Unreachable when listener is used as tree walker.
             raise ValueError()  # pragma: no cover
         self._stack.append(
             RecursiveDescentNode(
                 SubscriptNode(next_node, subscriptable_nodes)))
     elif ctx.getToken(JSONPathParser.SUBSCRIPT, 0) is not None:
         if bool(ctx.subscript()):
             next_node = self._stack.pop()
         else:
             next_node = TerminalNode()
         if bool(ctx.subscriptableBareword()):
             subscriptable_nodes = [self._stack.pop()]
         else:
             # NOTE Unreachable when listener is used as tree walker.
             raise ValueError()  # pragma: no cover
         self._stack.append(SubscriptNode(next_node, subscriptable_nodes))
     else:
         if bool(ctx.subscript()):
             next_node = self._stack.pop()
         else:
             next_node = TerminalNode()
         if bool(ctx.subscriptables()):
             subscriptable_nodes = self._stack.pop()
         else:
             # NOTE Unreachable when listener is used as tree walker.
             raise ValueError()  # pragma: no cover
         self._stack.append(SubscriptNode(next_node, subscriptable_nodes))
Esempio n. 11
0
    def test_badsubscript2(self):
        """Test subscript that provides other subscript but not subscripted-terminal."""
        class BadSubscript2(Subscript):
            """Subscript that provides other subscript but not subscripted-terminal."""
            def __jsonpath__(self):
                """Empty."""
                return []

            def match(self, root_value, current_value):
                """One."""
                yield MatchData(SubscriptNode(None), root_value, current_value)

        self.assertEqual('', BadSubscript2().tojsonpath())

        with self.assertRaises(ValueError):
            # NOTE Use 'list' to force the computation to occur, raising any exceptions.
            list(
                SubscriptNode(TerminalNode(),
                              [BadSubscript2()]).match(None, None))
Esempio n. 12
0
 def match(self, root_value: object,
           current_value: object) -> Generator[MatchData, None, None]:
     """Match the filter subscript against the current value."""
     if self.expression.evaluate(root_value, current_value):
         return [MatchData(TerminalNode(), root_value, current_value)]
     return []
    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]),
                ],
            },
        ]
Esempio n. 14
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())
                    ),
                ],
            },
        ]
Esempio n. 15
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()),
                    ),
                ],
            },
        ]