'Test parsing of Range header'

def test_range_parsing(self):

    from calibre.srv.http_response import get_ranges
    def test(val, *args):
        pval = get_ranges(val, 100)
        if ((len(args) == 1) and (args[0] is None)):
            self.assertIsNone(pval, val)
        else:
            self.assertListEqual([tuple(x) for x in pval], list(args), val)
    test(u'crap', None)
    test(u'crap=', None)
    test(u'crap=1', None)
    test(u'crap=1-2', None)
    test(u'bytes=a-2')
    test(u'bytes=0-99', (0, 99, 100))
    test(u'bytes=0-0,-1', (0, 0, 1), (99, 99, 1))
    test(u'bytes=-5', (95, 99, 5))
    test(u'bytes=95-', (95, 99, 5))
    test(u'bytes=-200', (0, 99, 100))
