import { WarningMessage } from 'types/compiler'
import { parseComponent } from '../src/parseComponent'
describe('Single File Component parser', () => {
it('should parse', () => {
const res = parseComponent(
`
hi
`
)
expect(res.template!.content.trim()).toBe('hi
')
expect(res.styles.length).toBe(4)
expect(res.styles[0].src).toBe('./test.css')
expect(res.styles[1].lang).toBe('stylus')
expect(res.styles[1].scoped).toBe(true)
expect(res.styles[1].content.trim()).toBe(
'h1\n color red\nh2\n color green'
)
expect(res.styles[2].module).toBe(true)
expect(res.styles[3].attrs['bool-attr']).toBe(true)
expect(res.styles[3].attrs['val-attr']).toBe('test')
expect(res.script!.content.trim()).toBe('export default {}')
})
it('should parse template with closed input', () => {
const res = parseComponent(`
`)
expect(res.template!.content.trim()).toBe('')
})
it('should handle nested template', () => {
const res = parseComponent(`
hi
`)
expect(res.template!.content.trim()).toBe(
'hi
'
)
})
it('deindent content', () => {
const content = `
`
const deindentDefault = parseComponent(content.trim(), {
pad: false
})
const deindentEnabled = parseComponent(content.trim(), {
pad: false,
deindent: true
})
const deindentDisabled = parseComponent(content.trim(), {
pad: false,
deindent: false
})
expect(deindentDefault.template!.content).toBe('\n\n')
expect(deindentDefault.script!.content).toBe(
'\n export default {}\n '
)
expect(deindentDefault.styles[0].content).toBe('\nh1 { color: red }\n')
expect(deindentEnabled.template!.content).toBe('\n\n')
expect(deindentEnabled.script!.content).toBe('\nexport default {}\n')
expect(deindentEnabled.styles[0].content).toBe('\nh1 { color: red }\n')
expect(deindentDisabled.template!.content).toBe(
'\n \n '
)
expect(deindentDisabled.script!.content).toBe(
'\n export default {}\n '
)
expect(deindentDisabled.styles[0].content).toBe(
'\n h1 { color: red }\n '
)
})
it('pad content', () => {
const content = `
`
const padDefault = parseComponent(content.trim(), {
pad: true,
deindent: true
})
const padLine = parseComponent(content.trim(), {
pad: 'line',
deindent: true
})
const padSpace = parseComponent(content.trim(), {
pad: 'space',
deindent: true
})
expect(padDefault.script!.content).toBe(
Array(3 + 1).join('//\n') + '\nexport default {}\n'
)
expect(padDefault.styles[0].content).toBe(
Array(6 + 1).join('\n') + '\nh1 { color: red }\n'
)
expect(padLine.script!.content).toBe(
Array(3 + 1).join('//\n') + '\nexport default {}\n'
)
expect(padLine.styles[0].content).toBe(
Array(6 + 1).join('\n') + '\nh1 { color: red }\n'
)
expect(padSpace.script!.content).toBe(
`