deps-parser.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * NOTE
  3. *
  4. * this suite only tests two utility methods used in the
  5. * Dependency Parser, but does not test the main .parse()
  6. * method. .parse() is covered in integration tests because
  7. * it has to work with multiple compilers.
  8. */
  9. var DepsParser = require('seed/src/deps-parser')
  10. describe('UNIT: Dependency Parser', function () {
  11. describe('.parseContextDependency()', function () {
  12. var binding = {
  13. rawGet: function (ctx) {
  14. return ctx.vm.a + ctx.vm.a + ctx.vm.b.c
  15. },
  16. compiler: {
  17. contextBindings: []
  18. }
  19. }
  20. DepsParser.pcd(binding)
  21. it('should not contain duplicate entries', function () {
  22. assert.strictEqual(binding.contextDeps.length, 2)
  23. })
  24. it('should extract correct context dependencies from a getter', function () {
  25. assert.strictEqual(binding.contextDeps[0], 'b.c')
  26. assert.strictEqual(binding.contextDeps[1], 'a')
  27. })
  28. it('should add the binding to its compiler\'s contextBindings', function () {
  29. assert.ok(binding.compiler.contextBindings.indexOf(binding) !== -1)
  30. })
  31. })
  32. describe('.createDummyVM()', function () {
  33. var createDummyVM = DepsParser.cdvm,
  34. binding = {
  35. contextDeps: ['a.b', 'a.b.c', 'b']
  36. }
  37. it('should create a dummy VM that has all context dep paths', function () {
  38. var vm = createDummyVM(binding)
  39. assert.ok('a' in vm)
  40. assert.ok('b' in vm)
  41. assert.ok('b' in vm.a)
  42. assert.ok('c' in vm.a.b)
  43. })
  44. })
  45. })