test-ein-worksheet-notebook.el 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (eval-when-compile (require 'cl))
  2. (require 'ert)
  3. (require 'ein-notebook)
  4. (require 'ein-testing-notebook)
  5. ;;; Event handler
  6. (defun ein:testing-worksheet-set-dirty
  7. (pre-dirty value post-dirty fired-in)
  8. (with-current-buffer (ein:testing-make-notebook-with-outputs '(nil))
  9. (when pre-dirty
  10. (ein:cell-goto (ein:worksheet-get-current-cell))
  11. (insert "something"))
  12. (should (equal (ein:worksheet-modified-p ein:%worksheet%) pre-dirty))
  13. (with-current-buffer (funcall fired-in)
  14. (let ((events (oref ein:%worksheet% :events))
  15. (cell (ein:worksheet-get-current-cell)))
  16. (ein:events-trigger events 'set_dirty.Worksheet
  17. (list :cell cell :value value))))
  18. (should (equal (ein:worksheet-modified-p ein:%worksheet%) post-dirty))))
  19. (defun ein:testing-scratchsheet-buffer ()
  20. (ein:worksheet-buffer (ein:notebook-scratchsheet-open ein:%notebook%)))
  21. (defmacro ein:testing-worksheet-set-dirty-deftest
  22. (pre-dirty value post-dirty &optional fired-in)
  23. (let ((name (intern (format "ein:worksheet-set-dirty/%s-to-%s-fired-in-%s"
  24. pre-dirty value
  25. (or fired-in "current-buffer"))))
  26. (fired-in-defun
  27. (case fired-in
  28. (scratchsheet 'ein:testing-scratchsheet-buffer)
  29. (t 'current-buffer))))
  30. `(ert-deftest ,name ()
  31. (ein:testing-worksheet-set-dirty ,pre-dirty ,value ,post-dirty
  32. #',fired-in-defun))))
  33. (ein:testing-worksheet-set-dirty-deftest t nil nil)
  34. (ein:testing-worksheet-set-dirty-deftest t t t )
  35. (ein:testing-worksheet-set-dirty-deftest nil nil nil)
  36. (ein:testing-worksheet-set-dirty-deftest nil t t )
  37. (ein:testing-worksheet-set-dirty-deftest t nil t scratchsheet)
  38. (ein:testing-worksheet-set-dirty-deftest t t t scratchsheet)
  39. (ein:testing-worksheet-set-dirty-deftest nil nil nil scratchsheet)
  40. (ein:testing-worksheet-set-dirty-deftest nil t nil scratchsheet)