forked from sindresorhus/strip-final-newline
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mjs
20 lines (18 loc) · 826 Bytes
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import test from 'ava';
import stripFinalNewline from './esm/index.js';
test('string', t => {
t.is(stripFinalNewline('foo\n'), 'foo');
t.is(stripFinalNewline('foo\nbar\n'), 'foo\nbar');
t.is(stripFinalNewline('foo\n\n\n'), 'foo\n\n');
t.is(stripFinalNewline('foo\r\n'), 'foo');
t.is(stripFinalNewline('foo\r'), 'foo');
t.is(stripFinalNewline('foo\n\r\n'), 'foo\n');
});
test('buffer', t => {
t.is(stripFinalNewline(Buffer.from('foo\n')).toString(), 'foo');
t.is(stripFinalNewline(Buffer.from('foo\nbar\n')).toString(), 'foo\nbar');
t.is(stripFinalNewline(Buffer.from('foo\n\n\n').toString()), 'foo\n\n');
t.is(stripFinalNewline(Buffer.from('foo\r\n')).toString(), 'foo');
t.is(stripFinalNewline(Buffer.from('foo\r')).toString(), 'foo');
t.is(stripFinalNewline(Buffer.from('foo\n\r\n')).toString(), 'foo\n');
});