2018-12-29 19:24:02 +02:00
require ( 'app-module-path' ) . addPath ( _ _dirname ) ;
const { time } = require ( 'lib/time-utils.js' ) ;
const { fileContentEqual , setupDatabase , setupDatabaseAndSynchronizer , db , synchronizer , fileApi , sleep , clearDatabase , switchClient , syncTargetId , objectsEqual , checkThrowAsync } = require ( 'test-utils.js' ) ;
const StringUtils = require ( 'lib/string-utils' ) ;
process . on ( 'unhandledRejection' , ( reason , p ) => {
console . log ( 'Unhandled Rejection at: Promise' , p , 'reason:' , reason ) ;
} ) ;
describe ( 'StringUtils' , function ( ) {
beforeEach ( async ( done ) => {
done ( ) ;
} ) ;
it ( 'should surround keywords with strings' , async ( done ) => {
const testCases = [
2018-12-29 21:19:18 +02:00
[ [ ] , 'test' , 'a' , 'b' , 'test' ] ,
2018-12-29 19:24:02 +02:00
[ [ 'test' ] , 'test' , 'a' , 'b' , 'atestb' ] ,
[ [ 'test' ] , 'Test' , 'a' , 'b' , 'aTestb' ] ,
[ [ 'te[]st' ] , 'Te[]st' , 'a' , 'b' , 'aTe[]stb' ] ,
2019-01-31 11:48:48 +02:00
// [['test1', 'test2'], 'bla test1 blabla test1 bla test2 not this one - test22', 'a', 'b', 'bla atest1b blabla atest1b bla atest2b not this one - test22'],
2018-12-29 19:24:02 +02:00
[ [ '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>' ] ,
2019-01-31 11:48:48 +02:00
// [[{ type:'regex', value:'test.*?'}], 'bla test1 test1 bla test2 test tttest', 'a', 'b', 'bla atest1b atest1b bla atest2b atestb tttest'],
2018-12-29 19:24:02 +02:00
] ;
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 ) ;
2019-01-31 11:48:48 +02:00
expect ( actual ) . toBe ( expected , 'Test case ' + i ) ;
2018-12-29 19:24:02 +02:00
}
done ( ) ;
} ) ;
} ) ;