|
| 1 | +import { describe, expect, test } from 'bun:test'; |
| 2 | +import { normalizeDisassemblyLine } from '../src/utils/hermes-base'; |
| 3 | + |
| 4 | +const normalize = (line: string) => |
| 5 | + normalizeDisassemblyLine(line, new Map<number, string>()); |
| 6 | + |
| 7 | +describe('Hermes switch jump-table normalization', () => { |
| 8 | + test('normalizes only the StringSwitchImm jump-table offset', () => { |
| 9 | + const baseline = normalize(' StringSwitchImm r13, 2, 4024, L146, 150'); |
| 10 | + expect(baseline).toBe(' StringSwitchImm r13, 2, <jt>, L146, 150'); |
| 11 | + expect(normalize(' StringSwitchImm r13, 2, 4025, L146, 150')).toBe( |
| 12 | + baseline, |
| 13 | + ); |
| 14 | + expect(normalize(' StringSwitchImm r13, 3, 4024, L146, 150')).not.toBe( |
| 15 | + baseline, |
| 16 | + ); |
| 17 | + expect(normalize(' StringSwitchImm r13, 2, 4024, L147, 150')).not.toBe( |
| 18 | + baseline, |
| 19 | + ); |
| 20 | + expect(normalize(' StringSwitchImm r13, 2, 4024, L146, 151')).not.toBe( |
| 21 | + baseline, |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + test('normalizes only the UIntSwitchImm jump-table offset', () => { |
| 26 | + const baseline = normalize(' UIntSwitchImm r40, 5937, L3, 0, 31'); |
| 27 | + expect(baseline).toBe(' UIntSwitchImm r40, <jt>, L3, 0, 31'); |
| 28 | + expect(normalize(' UIntSwitchImm r40, 5938, L3, 0, 31')).toBe(baseline); |
| 29 | + expect(normalize(' UIntSwitchImm r40, 5937, L4, 0, 31')).not.toBe( |
| 30 | + baseline, |
| 31 | + ); |
| 32 | + expect(normalize(' UIntSwitchImm r40, 5937, L3, 1, 31')).not.toBe( |
| 33 | + baseline, |
| 34 | + ); |
| 35 | + expect(normalize(' UIntSwitchImm r40, 5937, L3, 0, 32')).not.toBe( |
| 36 | + baseline, |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + test('does not fold unsupported or malformed switch shapes', () => { |
| 41 | + expect(normalize(' SwitchImm r1, 2, 3, L4, 5')).toBe( |
| 42 | + ' SwitchImm r1, 2, 3, L4, 5', |
| 43 | + ); |
| 44 | + expect(normalize(' UIntSwitchImm r40, 5937, 3, 0, 31')).toBe( |
| 45 | + ' UIntSwitchImm r40, 5937, 3, 0, 31', |
| 46 | + ); |
| 47 | + }); |
| 48 | +}); |
0 commit comments