test-ein-worksheet.el 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. (require 'ert)
  2. (require 'ein-worksheet)
  3. (require 'ein-testing-cell)
  4. (defvar ein:testing-worksheet-example-data
  5. (list (ein:testing-codecell-data "code example input")
  6. (ein:testing-markdowncell-data "markdown example input")
  7. (ein:testing-rawcell-data "raw example input")
  8. (ein:testing-htmlcell-data "html example input")
  9. (ein:testing-headingcell-data "heading example input")))
  10. (defun ein:testing-worksheet-new ()
  11. (make-instance 'ein:worksheet
  12. :discard-output-p (cons #'ignore nil)))
  13. (defun ein:testing-worksheet-to-json (cells &optional metadata)
  14. (let* ((ws-0 (ein:worksheet-from-json (ein:testing-worksheet-new)
  15. (list :cells cells
  16. :metadata metadata)))
  17. (ws-1 (ein:testing-worksheet-new))
  18. (json-0 (ein:worksheet-to-json ws-0))
  19. (json-1 (ein:worksheet-to-json
  20. (ein:worksheet-from-json ws-1
  21. (ein:json-read-from-string
  22. (json-encode json-0))))))
  23. (let* ((found (assoc 'metadata json-0)))
  24. (when found
  25. (should (cdr found))))
  26. (should (equal json-0 json-1))))
  27. (ert-deftest ein:worksheet-to-json/empty ()
  28. (ein:testing-worksheet-to-json nil))
  29. (ert-deftest ein:worksheet-to-json/example-data ()
  30. (ein:testing-worksheet-to-json ein:testing-worksheet-example-data))
  31. (ert-deftest ein:worksheet-to-json/example-data-with-metadata ()
  32. (ein:testing-worksheet-to-json ein:testing-worksheet-example-data
  33. '(:name "Worksheet name")))