'Check that the tokens have the expected matching bracket.
Arguments:
uwlines: list of UnwrappedLine.
list_of_expected: list of (index, index) pairs. The matching brackets at
the indexes need to match. Non-semantic tokens are filtered out from the
expected values.'

def _CheckMatchingBrackets(self, uwlines, list_of_expected):

    actual = []
    for uwl in uwlines:
        filtered_values = [(ft, ft.matching_bracket) for ft in uwl.tokens if (ft.name not in pytree_utils.NONSEMANTIC_TOKENS)]
        if filtered_values:
            actual.append(filtered_values)
    for (index, bracket_list) in enumerate(list_of_expected):
        uwline = actual[index]
        if (not bracket_list):
            for value in uwline:
                self.assertIsNone(value[1])
        else:
            for (open_bracket, close_bracket) in bracket_list:
                self.assertEqual(uwline[open_bracket][0], uwline[close_bracket][1])
                self.assertEqual(uwline[close_bracket][0], uwline[open_bracket][1])
