chore: nest v-for tests
This commit is contained in:
parent
5f49018601
commit
1f96d2348f
@ -5,6 +5,7 @@ import { ForNode, NodeTypes } from '../../src/ast'
|
|||||||
import { ErrorCodes } from '../../src/errors'
|
import { ErrorCodes } from '../../src/errors'
|
||||||
|
|
||||||
describe('v-for', () => {
|
describe('v-for', () => {
|
||||||
|
describe('transform', () => {
|
||||||
test('number expression', () => {
|
test('number expression', () => {
|
||||||
const node = parse('<span v-for="index in 5" />')
|
const node = parse('<span v-for="index in 5" />')
|
||||||
|
|
||||||
@ -305,14 +306,18 @@ describe('v-for', () => {
|
|||||||
source.indexOf('item') - 1
|
source.indexOf('item') - 1
|
||||||
)
|
)
|
||||||
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.start.column).toBe(source.indexOf('item'))
|
expect(forNode.valueAlias!.loc.start.column).toBe(
|
||||||
|
source.indexOf('item')
|
||||||
|
)
|
||||||
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.end.column).toBe(
|
expect(forNode.valueAlias!.loc.end.column).toBe(
|
||||||
source.indexOf('item') + 4
|
source.indexOf('item') + 4
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.source.content).toBe('items')
|
expect(forNode.source.content).toBe('items')
|
||||||
expect(forNode.source.loc.start.offset).toBe(source.indexOf('items') - 1)
|
expect(forNode.source.loc.start.offset).toBe(
|
||||||
|
source.indexOf('items') - 1
|
||||||
|
)
|
||||||
expect(forNode.source.loc.start.line).toBe(1)
|
expect(forNode.source.loc.start.line).toBe(1)
|
||||||
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
||||||
expect(forNode.source.loc.end.line).toBe(1)
|
expect(forNode.source.loc.end.line).toBe(1)
|
||||||
@ -336,14 +341,18 @@ describe('v-for', () => {
|
|||||||
source.indexOf('item') - 1
|
source.indexOf('item') - 1
|
||||||
)
|
)
|
||||||
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.start.column).toBe(source.indexOf('item'))
|
expect(forNode.valueAlias!.loc.start.column).toBe(
|
||||||
|
source.indexOf('item')
|
||||||
|
)
|
||||||
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.end.column).toBe(
|
expect(forNode.valueAlias!.loc.end.column).toBe(
|
||||||
source.indexOf('item') + 4
|
source.indexOf('item') + 4
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.source.content).toBe('items')
|
expect(forNode.source.content).toBe('items')
|
||||||
expect(forNode.source.loc.start.offset).toBe(source.indexOf('items') - 1)
|
expect(forNode.source.loc.start.offset).toBe(
|
||||||
|
source.indexOf('items') - 1
|
||||||
|
)
|
||||||
expect(forNode.source.loc.start.line).toBe(1)
|
expect(forNode.source.loc.start.line).toBe(1)
|
||||||
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
||||||
expect(forNode.source.loc.end.line).toBe(1)
|
expect(forNode.source.loc.end.line).toBe(1)
|
||||||
@ -376,7 +385,9 @@ describe('v-for', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.source.content).toBe('items')
|
expect(forNode.source.content).toBe('items')
|
||||||
expect(forNode.source.loc.start.offset).toBe(source.indexOf('items') - 1)
|
expect(forNode.source.loc.start.offset).toBe(
|
||||||
|
source.indexOf('items') - 1
|
||||||
|
)
|
||||||
expect(forNode.source.loc.start.line).toBe(1)
|
expect(forNode.source.loc.start.line).toBe(1)
|
||||||
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
||||||
expect(forNode.source.loc.end.line).toBe(1)
|
expect(forNode.source.loc.end.line).toBe(1)
|
||||||
@ -400,14 +411,18 @@ describe('v-for', () => {
|
|||||||
source.indexOf('item') - 1
|
source.indexOf('item') - 1
|
||||||
)
|
)
|
||||||
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.start.column).toBe(source.indexOf('item'))
|
expect(forNode.valueAlias!.loc.start.column).toBe(
|
||||||
|
source.indexOf('item')
|
||||||
|
)
|
||||||
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.end.column).toBe(
|
expect(forNode.valueAlias!.loc.end.column).toBe(
|
||||||
source.indexOf('item') + 4
|
source.indexOf('item') + 4
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.keyAlias!.content).toBe('key')
|
expect(forNode.keyAlias!.content).toBe('key')
|
||||||
expect(forNode.keyAlias!.loc.start.offset).toBe(source.indexOf('key') - 1)
|
expect(forNode.keyAlias!.loc.start.offset).toBe(
|
||||||
|
source.indexOf('key') - 1
|
||||||
|
)
|
||||||
expect(forNode.keyAlias!.loc.start.line).toBe(1)
|
expect(forNode.keyAlias!.loc.start.line).toBe(1)
|
||||||
expect(forNode.keyAlias!.loc.start.column).toBe(source.indexOf('key'))
|
expect(forNode.keyAlias!.loc.start.column).toBe(source.indexOf('key'))
|
||||||
expect(forNode.keyAlias!.loc.end.line).toBe(1)
|
expect(forNode.keyAlias!.loc.end.line).toBe(1)
|
||||||
@ -427,12 +442,15 @@ describe('v-for', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.source.content).toBe('items')
|
expect(forNode.source.content).toBe('items')
|
||||||
expect(forNode.source.loc.start.offset).toBe(source.indexOf('items') - 1)
|
expect(forNode.source.loc.start.offset).toBe(
|
||||||
|
source.indexOf('items') - 1
|
||||||
|
)
|
||||||
expect(forNode.source.loc.start.line).toBe(1)
|
expect(forNode.source.loc.start.line).toBe(1)
|
||||||
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
||||||
expect(forNode.source.loc.end.line).toBe(1)
|
expect(forNode.source.loc.end.line).toBe(1)
|
||||||
expect(forNode.source.loc.end.column).toBe(source.indexOf('items') + 5)
|
expect(forNode.source.loc.end.column).toBe(source.indexOf('items') + 5)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('skipped key', () => {
|
test('skipped key', () => {
|
||||||
const source = '<span v-for="( item,, index ) in items" />'
|
const source = '<span v-for="( item,, index ) in items" />'
|
||||||
const node = parse(source)
|
const node = parse(source)
|
||||||
@ -450,7 +468,9 @@ describe('v-for', () => {
|
|||||||
source.indexOf('item') - 1
|
source.indexOf('item') - 1
|
||||||
)
|
)
|
||||||
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
expect(forNode.valueAlias!.loc.start.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.start.column).toBe(source.indexOf('item'))
|
expect(forNode.valueAlias!.loc.start.column).toBe(
|
||||||
|
source.indexOf('item')
|
||||||
|
)
|
||||||
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
expect(forNode.valueAlias!.loc.end.line).toBe(1)
|
||||||
expect(forNode.valueAlias!.loc.end.column).toBe(
|
expect(forNode.valueAlias!.loc.end.column).toBe(
|
||||||
source.indexOf('item') + 4
|
source.indexOf('item') + 4
|
||||||
@ -470,11 +490,14 @@ describe('v-for', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(forNode.source.content).toBe('items')
|
expect(forNode.source.content).toBe('items')
|
||||||
expect(forNode.source.loc.start.offset).toBe(source.indexOf('items') - 1)
|
expect(forNode.source.loc.start.offset).toBe(
|
||||||
|
source.indexOf('items') - 1
|
||||||
|
)
|
||||||
expect(forNode.source.loc.start.line).toBe(1)
|
expect(forNode.source.loc.start.line).toBe(1)
|
||||||
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
expect(forNode.source.loc.start.column).toBe(source.indexOf('items'))
|
||||||
expect(forNode.source.loc.end.line).toBe(1)
|
expect(forNode.source.loc.end.line).toBe(1)
|
||||||
expect(forNode.source.loc.end.column).toBe(source.indexOf('items') + 5)
|
expect(forNode.source.loc.end.column).toBe(source.indexOf('items') + 5)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user