You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-24 23:26:50 +02:00
Tools: Moved lib-specific tests under lib package
This commit is contained in:
56
packages/lib/StringUtils.test.js
Normal file
56
packages/lib/StringUtils.test.js
Normal file
@ -0,0 +1,56 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
const StringUtils = require('./string-utils');
|
||||
|
||||
describe('StringUtils', function() {
|
||||
|
||||
beforeEach(async (done) => {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should surround keywords with strings', (async () => {
|
||||
const testCases = [
|
||||
[[], 'test', 'a', 'b', 'test'],
|
||||
[['test'], 'test', 'a', 'b', 'atestb'],
|
||||
[['test'], 'Test', 'a', 'b', 'aTestb'],
|
||||
[['te[]st'], 'Te[]st', 'a', 'b', 'aTe[]stb'],
|
||||
// [['test1', 'test2'], 'bla test1 blabla test1 bla test2 not this one - test22', 'a', 'b', 'bla atest1b blabla atest1b bla atest2b not this one - test22'],
|
||||
[['test1', 'test2'], 'bla test1 test1 bla test2', '<span class="highlighted-keyword">', '</span>', 'bla <span class="highlighted-keyword">test1</span> <span class="highlighted-keyword">test1</span> bla <span class="highlighted-keyword">test2</span>'],
|
||||
// [[{ type:'regex', value:'test.*?'}], 'bla test1 test1 bla test2 test tttest', 'a', 'b', 'bla atest1b atest1b bla atest2b atestb tttest'],
|
||||
];
|
||||
|
||||
for (let i = 0; i < testCases.length; i++) {
|
||||
const t = testCases[i];
|
||||
|
||||
const keywords = t[0];
|
||||
const input = t[1];
|
||||
const prefix = t[2];
|
||||
const suffix = t[3];
|
||||
const expected = t[4];
|
||||
|
||||
const actual = StringUtils.surroundKeywords(keywords, input, prefix, suffix);
|
||||
|
||||
expect(actual).toBe(expected, `Test case ${i}`);
|
||||
}
|
||||
}));
|
||||
|
||||
it('should find the next whitespace character', (async () => {
|
||||
const testCases = [
|
||||
['', [[0, 0]]],
|
||||
['Joplin', [[0, 6], [3, 6], [6, 6]]],
|
||||
['Joplin is a free, open source\n note taking and *to-do* application', [[0, 6], [12, 17], [23, 29], [48, 54]]],
|
||||
];
|
||||
|
||||
testCases.forEach((t, i) => {
|
||||
const str = t[0];
|
||||
t[1].forEach((pair, j) => {
|
||||
const begin = pair[0];
|
||||
const expected = pair[1];
|
||||
|
||||
const actual = StringUtils.nextWhitespaceIndex(str, begin);
|
||||
expect(actual).toBe(expected, `Test string ${i} - case ${j}`);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
Reference in New Issue
Block a user