|
| 1 | +import { expect } from 'chai'; |
| 2 | +import escapeCell from './escapeCell'; |
| 3 | + |
| 4 | +describe('escapeCell', () => { |
| 5 | + it('escapes pipes outside backticks', () => { |
| 6 | + const input = 'true | false'; |
| 7 | + const result = escapeCell(input); |
| 8 | + expect(result).to.equal('true \\| false'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('does not escape pipes inside single backticks', () => { |
| 12 | + const input = '`true | false`'; |
| 13 | + const result = escapeCell(input); |
| 14 | + expect(result).to.equal('`true | false`'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('does not escape pipes inside multiple inline code spans', () => { |
| 18 | + const input = 'Use `a | b` and `x | y` here'; |
| 19 | + const result = escapeCell(input); |
| 20 | + expect(result).to.equal('Use `a | b` and `x | y` here'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('escapes pipes in normal text but not inside backticks', () => { |
| 24 | + const input = '`a | b` or c | d'; |
| 25 | + const result = escapeCell(input); |
| 26 | + expect(result).to.equal('`a | b` or c \\| d'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('handles strings without any pipes', () => { |
| 30 | + const input = 'no pipes here'; |
| 31 | + const result = escapeCell(input); |
| 32 | + expect(result).to.equal('no pipes here'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('keeps < inside code spans but escapes outside', () => { |
| 36 | + const input = 'Use <b>bold</b> and `<div>` tags'; |
| 37 | + const result = escapeCell(input); |
| 38 | + expect(result).to.equal('Use <b>bold</b> and `<div>` tags'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('does not escape pipe at string start or end inside backticks', () => { |
| 42 | + const input = '`| start and end |`'; |
| 43 | + const result = escapeCell(input); |
| 44 | + expect(result).to.equal('`| start and end |`'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('escapes pipe at string start or end outside backticks', () => { |
| 48 | + const input = '| start | and end |'; |
| 49 | + const result = escapeCell(input); |
| 50 | + expect(result).to.equal('\\| start \\| and end \\|'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments