'Test matching nodes based on their index in their parent node.'

def tests_rel_indexed_children(self):

    tree = ParentedTree.fromstring(u'(S    (A    x)    (B    x)    (C    x))')
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >,    S', [tree])), [[(0,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >1    S', [tree])), [[(0,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >2    S', [tree])), [[(1,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >3    S', [tree])), [[(2,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u"*    >'    S", [tree])), [[(2,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >-1    S', [tree])), [[(2,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >-2    S', [tree])), [[(1,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    >-3    S', [tree])), [[(0,)]])
    tree = ParentedTree.fromstring(u'(S    (D    (A    x)    (B    x)    (C    x))    (E    (B    x)    (C    x)    (A    x))    (F    (C    x)    (A    x)    (B    x)))')
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <,    A', [tree])), [[(0,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <1    A', [tree])), [[(0,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <2    A', [tree])), [[(2,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <3    A', [tree])), [[(1,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u"*    <'    A", [tree])), [[(1,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <-1    A', [tree])), [[(1,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <-2    A', [tree])), [[(2,)]])
    self.assertEqual(list(tgrep.tgrep_positions(u'*    <-3    A', [tree])), [[(0,)]])
