MCPcopy
hub / github.com/vuejs/core / commonAssertions

Function commonAssertions

packages/compiler-core/__tests__/utils.spec.ts:49–83  ·  view source on GitHub ↗
(raw: (exp: ExpressionNode) => boolean)

Source from the content-addressed store, hash-verified

47
48describe('isMemberExpression', () => {
49 function commonAssertions(raw: (exp: ExpressionNode) => boolean) {
50 const fn = (str: string) => raw(createSimpleExpression(str))
51 // should work
52 expect(fn('obj.foo')).toBe(true)
53 expect(fn('obj[foo]')).toBe(true)
54 expect(fn('obj[arr[0]]')).toBe(true)
55 expect(fn('obj[arr[ret.bar]]')).toBe(true)
56 expect(fn('obj[arr[ret[bar]]]')).toBe(true)
57 expect(fn('obj[arr[ret[bar]]].baz')).toBe(true)
58 expect(fn('obj[1 + 1]')).toBe(true)
59 expect(fn(`obj[x[0]]`)).toBe(true)
60 expect(fn('obj[1][2]')).toBe(true)
61 expect(fn('obj[1][2].foo[3].bar.baz')).toBe(true)
62 expect(fn(`a[b[c.d]][0]`)).toBe(true)
63 expect(fn('obj?.foo')).toBe(true)
64 expect(fn('foo().test')).toBe(true)
65
66 // strings
67 expect(fn(`a['foo' + bar[baz]["qux"]]`)).toBe(true)
68
69 // multiline whitespaces
70 expect(fn('obj \n .foo \n [bar \n + baz]')).toBe(true)
71 expect(fn(`\n model\n.\nfoo \n`)).toBe(true)
72
73 // should fail
74 expect(fn('a \n b')).toBe(false)
75 expect(fn('obj[foo')).toBe(false)
76 expect(fn('objfoo]')).toBe(false)
77 expect(fn('obj[arr[0]')).toBe(false)
78 expect(fn('obj[arr0]]')).toBe(false)
79 expect(fn('a + b')).toBe(false)
80 expect(fn('foo()')).toBe(false)
81 expect(fn('a?b:c')).toBe(false)
82 expect(fn(`state['text'] = $event`)).toBe(false)
83 }
84
85 test('browser', () => {
86 commonAssertions(isMemberExpressionBrowser)

Callers 1

utils.spec.tsFile · 0.85

Calls 1

fnFunction · 0.70

Tested by

no test coverage detected