source-line-processor
Version:
`source-line-processor script.js --dir $PWD/test --dry-run --pattern "*.js"`
54 lines (45 loc) • 1.18 kB
text/typescript
import File from '..';
const testFile = `
this is
a
test file
`.trim();
describe('files', () => {
describe('file', () => {
test('it should be able to create a file', () => {
const file = new File('location', testFile);
expect(file.location).toEqual('location');
expect(file.lines).toEqual({
0: 'this is',
1: 'a',
2: 'test file',
});
});
test('it should be able to recreate a file', () => {
const file = new File('location', testFile);
expect(file.toString()).toEqual(testFile);
});
test('it should not be able to add new keys', () => {
const file = new File('location', testFile);
expect(() => {
file.lines[100] = 'test';
}).toThrow();
});
test('it should be able to update state', () => {
const file = new File('location', testFile);
expect(file.changed).toBeFalsy();
file.lines[1] = 'foo';
expect(file.lines).toEqual({
0: 'this is',
1: 'foo',
2: 'test file',
});
expect(file.toString()).toEqual(`
this is
foo
test file
`.trim());
expect(file.changed).toBeTruthy();
});
});
});