model-parse.spec.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { parseModel } from 'compiler/directives/model'
  2. describe('model expression parser', () => {
  3. it('parse single path', () => {
  4. const res = parseModel('foo')
  5. expect(res.exp).toBe('foo')
  6. expect(res.key).toBe(null)
  7. })
  8. it('parse object dot notation', () => {
  9. const res = parseModel('a.b.c')
  10. expect(res.exp).toBe('a.b')
  11. expect(res.key).toBe('"c"')
  12. })
  13. it('parse string in brackets', () => {
  14. const res = parseModel('a["b"][c]')
  15. expect(res.exp).toBe('a["b"]')
  16. expect(res.key).toBe('c')
  17. })
  18. it('parse brackets with object dot notation', () => {
  19. const res = parseModel('a["b"][c].xxx')
  20. expect(res.exp).toBe('a["b"][c]')
  21. expect(res.key).toBe('"xxx"')
  22. })
  23. it('parse nested brackets', () => {
  24. const res = parseModel('a[i[c]]')
  25. expect(res.exp).toBe('a')
  26. expect(res.key).toBe('i[c]')
  27. })
  28. it('combined', () => {
  29. const res = parseModel('test.xxx.a["asa"][test1[key]]')
  30. expect(res.exp).toBe('test.xxx.a["asa"]')
  31. expect(res.key).toBe('test1[key]')
  32. })
  33. })