| 1 | import random |
| 2 | from rpython.translator.c.support import gen_assignments |
| 3 | |
| 4 | |
| 5 | def test_gen_simple_assignments(): |
| 6 | yield gen_check, [('int @', 'a', 'a')] |
| 7 | yield gen_check, [('int @', 'a', 'b')] |
| 8 | yield gen_check, [('int @', 'a', 'b'), |
| 9 | ('int @', 'c', 'b')] |
| 10 | yield gen_check, [('int @', 'a', 'b'), |
| 11 | ('int @', 'b', 'c')] |
| 12 | yield gen_check, [('int @', 'b', 'c'), |
| 13 | ('int @', 'a', 'b')] |
| 14 | yield gen_check, [('int @', 'a', 'b'), |
| 15 | ('int @', 'b', 'a')] |
| 16 | yield gen_check, [('int @', 'a', 'b'), |
| 17 | ('int @', 'b', 'c'), |
| 18 | ('int @', 'd', 'b')] |
| 19 | |
| 20 | def gen_check(input): |
| 21 | for _, dst, src in input: |
| 22 | print 'input:', dst, src |
| 23 | result = ' '.join(gen_assignments(input)) |
| 24 | print result |
| 25 | result = result.replace('{ int', '').replace('}', '').strip() |
| 26 | d = {} |
| 27 | for _, dst, src in input: |
| 28 | d[src] = '<value of %s>' % (src,) |
| 29 | exec(result, d) |
| 30 | for _, dst, src in input: |
| 31 | assert d[dst] == '<value of %s>' % (src,) |
| 32 | |
| 33 | def test_gen_check(): |
| 34 | varlist = list('abcdefg') |
| 35 | for i in range(100): |
| 36 | random.shuffle(varlist) |
| 37 | input = [('int @', varlist[n], random.choice(varlist)) |
| 38 | for n in range(random.randrange(1, 7))] |
| 39 | yield gen_check, input |