From 58c4022d75c8de6896412a592be00812d16fdca2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 5 Mar 2015 23:01:31 -0500 Subject: Add tests --- test-snakemake-mode.el | 292 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 test-snakemake-mode.el (limited to 'test-snakemake-mode.el') diff --git a/test-snakemake-mode.el b/test-snakemake-mode.el new file mode 100644 index 0000000..a3afa7b --- /dev/null +++ b/test-snakemake-mode.el @@ -0,0 +1,292 @@ +;;; test-snakemake-mode.el --- Tests for snakemake-mode.el + +;; Copyright (C) 2015 Kyle Meyer + +;; Author: Kyle Meyer + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'snakemake-mode) +(require 'ert) + +;; This is modified from `org-tests.el' (55c0708). +(defmacro snakemake-with-temp-text (text &rest body) + "Run body in a temporary buffer with Snakemake mode as the +active mode holding TEXT. If the string \"\" appears in +TEXT then remove it and place the point there before running +BODY, otherwise place the point at the beginning of the inserted +text." + (declare (indent 1)) + `(let ((inside-text (if (stringp ,text) ,text (eval ,text)))) + (with-temp-buffer + (snakemake-mode) + (let ((point (string-match "" inside-text))) + (if point + (progn + (insert (replace-match "" nil nil inside-text)) + (goto-char (1+ (match-beginning 0)))) + (insert inside-text) + (goto-char (point-min)))) + ,@body))) +(def-edebug-spec org-test-with-temp-text (form body)) + + +(ert-deftest test-snakemake-mode/indentation () + "Test `snakemake-indent-line'." + + ;; At top of rule block + (should + (string= + "rule abc:" + (snakemake-with-temp-text + "rule abc:" + (snakemake-indent-line) + (buffer-string)))) + + ;; At top of rule block, repeated + (should + (string= + "rule abc:" + (snakemake-with-temp-text + "rule abc:" + (snakemake-indent-line) + (snakemake-indent-line) + (buffer-string)))) + + ;; Below a rule block + (should + (string= + " +rule abc: + " + (snakemake-with-temp-text + " +rule abc: +" + (snakemake-indent-line) + (buffer-string)))) + + ;; Below a rule block, repeated + (should + (string= + " +rule abc: +" + (snakemake-with-temp-text + " +rule abc: +" + (snakemake-indent-line) + (snakemake-indent-line) + (buffer-string)))) + + ;; At rule field key. + (should + (string= + " +rule abc: + output:" + (snakemake-with-temp-text + " +rule abc: +output:" + (snakemake-indent-line) + (buffer-string)))) + + ;; At rule field key, repeated + (should + (string= + " +rule abc: + output:" + (snakemake-with-temp-text + " +rule abc: +output:" + (snakemake-indent-line) + (snakemake-indent-line) + (buffer-string)))) + + ;; Below a filled rule field key + (should + (string= + " +rule abc: + output: 'file' + " + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (snakemake-indent-line) + (buffer-string)))) + + ;; Below a filled rule field key, repeated once + (should + (string= + " +rule abc: + output: 'file' + " + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (snakemake-indent-line) + (snakemake-indent-line) + (buffer-string)))) + + ;; Below a filled rule field key, repeated twice + (should + (string= + " +rule abc: + output: 'file' +" + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (snakemake-indent-line) + (snakemake-indent-line) + (snakemake-indent-line) + (buffer-string)))) + + ;; Body of a run field + (should + (string= + " +rule abc: + run: + with this: + " + (snakemake-with-temp-text + " +rule abc: + run: + with this: +" + (snakemake-indent-line) + (buffer-string)))) + + ;; Outside a rule block + (should + (string= + " +def ok(): + " + (snakemake-with-temp-text + " +def ok(): +" + (snakemake-indent-line) + (buffer-string))))) + +(ert-deftest test-snakemake-mode/in-rule-block () + "Test `snakemake-in-rule-or-subworkflow-block-p'" + + ;; At top of block + (snakemake-with-temp-text + " +rule abc: + output: 'file'" + (should (snakemake-in-rule-or-subworkflow-block-p))) + + ;; Body of block + (snakemake-with-temp-text + " +rule abc: + output: 'file'" + (should (snakemake-in-rule-or-subworkflow-block-p))) + + ;; First blank line after + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (should (snakemake-in-rule-or-subworkflow-block-p))) + + ;; Second blank line after + (snakemake-with-temp-text + " +rule abc: + output: 'file' + +" + (should-not (snakemake-in-rule-or-subworkflow-block-p))) + + ;; Before + (snakemake-with-temp-text + " +rule abc: + output: 'file'" + (should-not (snakemake-in-rule-or-subworkflow-block-p))) + + ;; Subworkflow + (snakemake-with-temp-text + " +subworkflow otherworkflow: + workdir: '../path/to/otherworkflow' + snakefile: '../path/to/otherworkflow/Snakefile'" + (should (snakemake-in-rule-or-subworkflow-block-p)))) + +(ert-deftest test-snakemake-mode/run-field-line-p () + "Test `snakemake-run-field-line-p'." + (snakemake-with-temp-text + " +rule abc: + run: +" + (should (snakemake-run-field-line-p))) + (snakemake-with-temp-text + " +rule abc: + run: + with file: +" + (should (snakemake-run-field-line-p))) + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (should-not (snakemake-run-field-line-p)))) + +(ert-deftest test-snakemake-mode/previous-field-value-column () + "Test `snakemake-previous-field-value-column'." + (should (= 12 + (snakemake-with-temp-text + " +rule abc: + output: 'file' +" + (snakemake-previous-field-value-column)))) + (should (= 12 + (snakemake-with-temp-text + " +rule abc: + output: 'file', + 'another' +" + (snakemake-previous-field-value-column))))) + + +(provide 'test-snakemake-mode) +;;; test-snakemake-mode.el ends here -- cgit v1.2.3