splitContent.test.ts 825 B

1234567891011121314151617181920212223
  1. /**
  2. * @author: oldj
  3. * @homepage: https://oldj.net
  4. */
  5. import { describe, expect, it } from 'vitest'
  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. const content = `abc12 abc123 abc44`
  11. const matches = findInContent(content, /bc/ig)
  12. const parts = splitContent(content, matches)
  13. expect(parts[0]).toMatchObject({ before: 'a', after: '' })
  14. expect(parts[1]).toMatchObject({ before: '12 a', after: '' })
  15. expect(parts[2]).toMatchObject({ before: '123 a', after: '44' })
  16. const rebuilt = parts.map((item) => `${item.before}${item.match}${item.after}`).join('')
  17. expect(rebuilt).toBe(content)
  18. })
  19. })