/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {migrateFile} from '../../src/migrate/migrate'; describe('migrateFile', () => { it('should migrate all of the legacy message IDs', () => { const source = ` Hello Bonjour Goodbye Au revoir `; const result = migrateFile(source, { '123hello-legacy': 'hello-migrated', '456goodbye-legacy': 'goodbye-migrated', }); expect(result).toContain(''); expect(result).toContain(''); }); it('should migrate messages whose ID contains special regex characters', () => { const source = ` Hello Bonjour `; const result = migrateFile(source, {'123hello(.*legacy': 'hello-migrated'}); expect(result).toContain(''); }); it('should not migrate messages that are not in the mapping', () => { const source = ` Hello Bonjour Goodbye Au revoir `; const result = migrateFile(source, {'123hello-legacy': 'hello-migrated'}); expect(result).toContain(''); expect(result).toContain(''); }); it('should not modify the file if none of the mappings match', () => { const source = ` Hello Bonjour Goodbye Au revoir `; const result = migrateFile(source, { 'does-not-match': 'migrated-does-not-match', 'also-does-not-match': 'migrated-also-does-not-match', }); expect(result).toBe(source); }); // Note: it shouldn't be possible for the ID to be repeated multiple times, but // this assertion is here to make sure that it behaves as expected if it does. it('should migrate if an ID appears in more than one place', () => { const source = ` Hello Bonjour Hello Bonjour `; const result = migrateFile(source, {'123hello-legacy': 'hello-migrated'}); expect(result).toContain(''); expect(result).toContain(''); expect(result).toContain(''); expect(result).toContain('Bonjour'); }); });