|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +import { normalize } from '@angular-devkit/core'; |
| 9 | +import { SimpleFileEntry } from './entry'; |
| 10 | +import { UpdateRecorderBase, UpdateRecorderBom } from './recorder'; |
| 11 | + |
| 12 | + |
| 13 | +describe('UpdateRecorderBase', () => { |
| 14 | + it('works for simple files', () => { |
| 15 | + const buffer = new Buffer('Hello World'); |
| 16 | + const entry = new SimpleFileEntry(normalize('/some/path'), buffer); |
| 17 | + |
| 18 | + const recorder = new UpdateRecorderBase(entry); |
| 19 | + recorder.insertLeft(5, ' beautiful'); |
| 20 | + const result = recorder.apply(buffer); |
| 21 | + expect(result.toString()).toBe('Hello beautiful World'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('works for simple files (2)', () => { |
| 25 | + const buffer = new Buffer('Hello World'); |
| 26 | + const entry = new SimpleFileEntry(normalize('/some/path'), buffer); |
| 27 | + |
| 28 | + const recorder = new UpdateRecorderBase(entry); |
| 29 | + recorder.insertRight(5, ' beautiful'); |
| 30 | + const result = recorder.apply(buffer); |
| 31 | + expect(result.toString()).toBe('Hello beautiful World'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('can create the proper recorder', () => { |
| 35 | + const p = normalize('/path'); |
| 36 | + expect(new SimpleFileEntry(p, new Buffer('hello')) instanceof UpdateRecorderBase) |
| 37 | + .toBe(true); |
| 38 | + expect(new SimpleFileEntry(p, new Buffer('hello')) instanceof UpdateRecorderBom) |
| 39 | + .toBe(false); |
| 40 | + expect(new SimpleFileEntry(p, new Buffer('\uFEFFhello')) instanceof UpdateRecorderBase) |
| 41 | + .toBe(true); |
| 42 | + expect(new SimpleFileEntry(p, new Buffer('\uFEFFhello')) instanceof UpdateRecorderBom) |
| 43 | + .toBe(true); |
| 44 | + }); |
| 45 | + |
| 46 | + it('supports empty files', () => { |
| 47 | + const p = normalize('/path'); |
| 48 | + expect(new SimpleFileEntry(p, new Buffer('')) instanceof UpdateRecorderBase) |
| 49 | + .toBe(true); |
| 50 | + expect(new SimpleFileEntry(p, new Buffer('')) instanceof UpdateRecorderBom) |
| 51 | + .toBe(false); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +describe('UpdateRecorderBom', () => { |
| 56 | + it('works for simple files', () => { |
| 57 | + const buffer = new Buffer('\uFEFFHello World'); |
| 58 | + const entry = new SimpleFileEntry(normalize('/some/path'), buffer); |
| 59 | + |
| 60 | + const recorder = new UpdateRecorderBom(entry); |
| 61 | + recorder.insertLeft(5, ' beautiful'); |
| 62 | + const result = recorder.apply(buffer); |
| 63 | + expect(result.toString()).toBe('\uFEFFHello beautiful World'); |
| 64 | + }); |
| 65 | +}); |
0 commit comments