forked from sindresorhus/atom-editorconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixe sindresorhus#121 by making insert_final_newline more lazy
- Loading branch information
Florian Breisch
committed
Oct 27, 2016
1 parent
8231a7d
commit 3aaf29e
Showing
2 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** @babel */ | ||
/* eslint-env jasmine, atomtest */ | ||
|
||
/* | ||
This file contains verifying specs for: | ||
https://github.com/sindresorhus/atom-editorconfig/issues/121 | ||
Due to a bad implementation of the `insert_final_newline`-logic the final newline | ||
is unecessarily stripped and appended even if a single final newline already exists. | ||
This messes the undo-history up. | ||
*/ | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const projectRoot = path.join(__dirname, 'fixtures'); | ||
const filePath = path.join( | ||
projectRoot, | ||
`test.${path.basename(__filename).split('-').shift()}` | ||
); | ||
|
||
describe('editorconfig', () => { | ||
let textEditor; | ||
const textWithOneFinalNewline = ` | ||
This is a text | ||
with a lot of lines, | ||
which have a lot of | ||
trailing spaces.\n`; | ||
|
||
beforeEach(() => { | ||
waitsForPromise(() => | ||
Promise.all([ | ||
atom.packages.activatePackage('editorconfig'), | ||
atom.workspace.open(filePath) | ||
]).then(results => { | ||
textEditor = results[1]; | ||
}) | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
// remove the created fixture, if it exists | ||
runs(() => { | ||
fs.stat(filePath, (err, stats) => { | ||
if (!err && stats.isFile()) { | ||
fs.unlink(filePath); | ||
} | ||
}); | ||
}); | ||
|
||
waitsFor(() => { | ||
try { | ||
return fs.statSync(filePath).isFile() === false; | ||
} catch (err) { | ||
return true; | ||
} | ||
}, 5000, `removed ${filePath}`); | ||
}); | ||
|
||
describe('Atom being set to insert a final newline', () => { | ||
beforeEach(() => { | ||
Object.assign(textEditor.getBuffer().editorconfig.settings, { | ||
trim_trailing_whitespace: true, // eslint-disable-line camelcase | ||
insert_final_newline: true // eslint-disable-line camelcase | ||
}); | ||
}); | ||
|
||
it('should strip not extend the undo-history if a final newline already exists', () => { | ||
const buffer = textEditor.getBuffer(); | ||
|
||
textEditor.setText(textWithOneFinalNewline); | ||
|
||
const checkpoint = buffer.createCheckpoint(); | ||
textEditor.save(); | ||
expect(buffer.getChangesSinceCheckpoint(checkpoint).length).toEqual(0); | ||
}); | ||
}); | ||
}); |