splitContent.test.ts 749 B

12345678910111213141516171819202122232425
  1. /**
  2. * @author: oldj
  3. * @homepage: https://oldj.net
  4. */
  5. import assert = require('assert')
  6. import { default as findInContent } from 'src/main/actions/find/findPositionsInContent'
  7. import { default as splitContent } from 'src/main/actions/find/splitContent'
  8. describe('split content test', () => {
  9. it('basic test 1', () => {
  10. let content = `abc12 abc123 abc44`
  11. let m = findInContent(content, /bc/ig)
  12. let sp = splitContent(content, m)
  13. assert(sp[0].before === 'a')
  14. assert(sp[0].after === '')
  15. assert(sp[1].before === '12 a')
  16. assert(sp[1].after === '')
  17. assert(sp[2].before === '123 a')
  18. assert(sp[2].after === '44')
  19. let r = sp.map(i => `${i.before}${i.match}${i.after}`).join('')
  20. assert(r === content)
  21. })
  22. })