'Test sample LIKE-queries'

def testSamples(self):

    s3db = current.s3db
    assertTrue = self.assertTrue
    assertEqual = self.assertEqual
    samples = (('%en%', ('TEST0', 'TEST1')), ('%oc%', ()), ('%\xe1\xba\xb7y%', ('TEST3',)), ('%luk%', ('TEST9',)), ('%\xc3\xa6lod%', ('TEST6',)), ('Gone%', ('TEST4',)), ('Gon%', ('TEST4', 'TEST5')), ('M\xc3\xa3n%', ('TEST2',)), ('%\xc3\xaelu%', ('TEST8',)), ('%\xc3\xaflu%', ('TEST8',)), (u'%\u0110\u1eafk%', ('TEST10',)), (u'ih\u1e31v%', ('TEST11',)), (u'%\u0130hk%', ('TEST11',)), ('', ()), (1, ()))
    for (index, sample) in enumerate(samples):
        (search_string, expected) = sample
        query = FS('name').like(search_string)
        resource = s3db.resource('airegex_test', filter=query)
        rows = resource.select(['uuid', 'name'], as_rows=True)
        uuids = [row.uuid for row in rows]
        msg = ('Sample    %s    failed:    expected    %s    matches    %s,    but    found    %s    %s' % (index, len(expected), expected, len(rows), uuids))
        assertEqual(len(rows), len(expected), msg=msg)
        if len(expected):
            for row in rows:
                uuid = row.uuid
                msg = ('Sample    %s    failed:    %s    not    in    %s' % (index, uuid, expected))
                assertTrue((row.uuid in expected), msg=msg)
