import { generateCodeFrame } from 'compiler/codeframe'
describe('codeframe', () => {
const source = `
`.trim()
it('line near top', () => {
const keyStart = source.indexOf(`key="one"`)
const keyEnd = keyStart + `key="one"`.length
expect(generateCodeFrame(source, keyStart, keyEnd)).toBe(
`
1 |
2 |
| ^^^^^^^^^
3 |
4 | - hi
`.trim()
)
})
it('line in middle', () => {
// should cover 5 lines
const forStart = source.indexOf(`v-for=`)
const forEnd = forStart + `v-for="foobar"`.length
expect(generateCodeFrame(source, forStart, forEnd)).toBe(
`
2 |
3 |
4 | - hi
| ^^^^^^^^^^^^^^
5 |
6 |
`.trim()
)
})
it('line near bottom', () => {
const keyStart = source.indexOf(`key="two"`)
const keyEnd = keyStart + `key="two"`.length
expect(generateCodeFrame(source, keyStart, keyEnd)).toBe(
`
4 | - hi
5 |
6 |
| ^^^^^^^^^
7 |
`.trim()
)
})
it('multi-line highlights', () => {
const source = `
`.trim()
const attrStart = source.indexOf(`attr=`)
const attrEnd = source.indexOf(`">`) + 1
expect(generateCodeFrame(source, attrStart, attrEnd)).toBe(
`
1 |
| ^
`.trim()
)
})
})