branch: elpa/jade-mode
commit ecc125319695b662725e6a03235306caefd973f2
Merge: efb86f6a36 ce2400711d
Author: Travis Jefferson <[email protected]>
Commit: Travis Jefferson <[email protected]>
Merge pull request #56 from MC-Escherichia/fix-regexes
Named regexes, cask integration, more tests
---
.gitignore | 1 +
Cask | 12 ++++++
Makefile | 2 +-
example.jade | 1 +
jade-mode.el | 15 +++++---
test/highlight-test.el | 25 ++++++++++++
tests/indentation.el => test/indentation-test.el | 0
test/test-helper.el | 49 ++++++++++++++++++++++++
tests/highlight.el | 33 ----------------
9 files changed, 98 insertions(+), 40 deletions(-)
diff --git a/.gitignore b/.gitignore
index c531d9867f..1304fa25e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*.elc
+/.cask/
diff --git a/Cask b/Cask
new file mode 100644
index 0000000000..21abb1ccf8
--- /dev/null
+++ b/Cask
@@ -0,0 +1,12 @@
+(source gnu)
+(source melpa)
+
+(package "jade-mode" "0.2.1" "Syntax hilighting and smart-tabs for jade html
language")
+
+;; (package-file "jade-mode.el")
+
+(development
+ (depends-on "f")
+ (depends-on "ecukes")
+ (depends-on "ert-runner")
+ (depends-on "el-mock"))
diff --git a/Makefile b/Makefile
index 6ba9019f9d..6d1c66ddc9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
test:
- emacs -batch -L . -l ./tests/highlight.el -l ./tests/indentation.el -f
ert-run-tests-batch-and-exit
+ cask exec ert-runner -l jade-mode.el
# Local Variables:
# indent-tabs-mode: t
diff --git a/example.jade b/example.jade
index a19782edd7..1795a304e0 100644
--- a/example.jade
+++ b/example.jade
@@ -28,6 +28,7 @@ html(lang="en", class = ['classOne', 'classTwo'].join(','))
span this one shouldn't higlight strings or... .other #things if else
| this one shouldn't highlight strings, and the same goes for
.keywords #ok ?
div#paren.content.example(style = 'float: left;') Content .here
#should be plain if for
+ +help("if this is .bolded #that's bad, we want a string","a second arg
or else");
div.examples#javascript
- var a = 1;
- var helperFunction = function (a) { return (a === 1 ? 'singular' :
'plural'); };
diff --git a/jade-mode.el b/jade-mode.el
index 16d6fbccc7..69505357fe 100644
--- a/jade-mode.el
+++ b/jade-mode.el
@@ -72,23 +72,26 @@
(defvar jade-class-re "[.][a-zA-Z][0-9a-zA-Z_\\-]*"
"Regexp used to match a class literal, e.g. .class, .class_name-123")
+(defvar jade-mixin-re "[+][a-zA-Z][0-9a-zA-Z_\\-]*"
+ "Regexp used to match a mixin name")
+
(defvar jade-double-quote-string-re "[\"]\\(\\\\.\\|[^\"\n]\\)*[\"]"
"Regexp used to match a double-quoted string literal")
(defvar jade-single-quote-string-re "[']\\(\\\\.\\|[^'\n]\\)*[']"
"Regexp used to match a single-quoted string literal")
-(defvar jade-tag-declaration-char-re "[-a-zA-Z0-9_.#]"
+(defvar jade-tag-declaration-char-re "[-a-zA-Z0-9_.#+]"
"Regexp used to match a character in a tag declaration")
(defvar jade-font-lock-keywords
`(
(,jade-keywords . font-lock-keyword-face) ;; keywords
- ("#\\(\\w\\|_\\|-\\)*" . font-lock-variable-name-face) ;; id
- ("\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(#[A-Za-z0-9\-\_]*[^ ]\\)" 1
font-lock-variable-name-face) ;; id
- ("\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(\\.[A-Za-z0-9\-\_]*\\)" 1
font-lock-type-face) ;; class name
- ("^[ \t]*\\([a-zA-Z0-9]+\\)" 1 font-lock-function-name-face) ;; tag name
- ("^[ \t]*\\(-?//.*\\)" 1 font-lock-comment-face t) ;; jade block comments
+ (,jade-id-re . font-lock-variable-name-face) ;; id
+ (,jade-class-re . font-lock-type-face) ;; class name
+ ("\\(-?//.*\\)" 1 font-lock-comment-face t) ;; jade block comments
+ (,jade-tag-re . font-lock-function-name-face)
+ ;; tag name
;; remove highlighting from literal content following tag/class/id
;; e.g. tag Inner text
diff --git a/test/highlight-test.el b/test/highlight-test.el
new file mode 100644
index 0000000000..397faddbc3
--- /dev/null
+++ b/test/highlight-test.el
@@ -0,0 +1,25 @@
+(ert-deftest jade-mode-command-should-be-bound ()
+ (with-temp-buffer
+ (should (fboundp 'jade-mode))
+ (should (null (jade-mode)))))
+
+(ert-deftest jade-mode-highlight-doctype ()
+ (jade-test-with-temp-buffer-pt-min
+ "doctype html\n\n"
+ (should (eq (get-text-property 1 'face)
+ 'font-lock-comment-face))
+ (should (eq
+ (next-single-property-change (point) 'face)
+ (point-at-eol)))))
+
+(ert-deftest jade-mode-highlights-in-isolation ()
+ (jade-test-highlight-one-word "mixin" 'font-lock-keyword-face 2)
+
+ (jade-test-highlight-one-word "#container" 'font-lock-variable-name-face 2)
+ (jade-test-highlight-one-word ".class" 'font-lock-type-face 2)
+ (jade-test-highlight-one-word "// this is a comment" 'font-lock-comment-face
2)
+ (jade-test-highlight-one-word "//- this is a comment"
'font-lock-comment-face 2)
+ (jade-test-highlight-one-word "-// this is a comment"
'font-lock-comment-face 2)
+ (jade-test-highlight-one-word "head" 'font-lock-function-name-face 0)
+ (jade-test-highlight-one-word "body" 'font-lock-function-name-face 2)
+ (jade-test-highlight-one-word "doctype html" 'font-lock-comment-face 0))
diff --git a/tests/indentation.el b/test/indentation-test.el
similarity index 100%
rename from tests/indentation.el
rename to test/indentation-test.el
diff --git a/test/test-helper.el b/test/test-helper.el
new file mode 100644
index 0000000000..34a6c3f7a8
--- /dev/null
+++ b/test/test-helper.el
@@ -0,0 +1,49 @@
+;;; test-helper.el --- macros and functions for testing jade-mode.el based on
python-mode.el ert test-suite
+
+;; Copyright (C) 2015
+
+;; Author: <matt@Akshobya>
+
+;; test highlighting based on python mode
https://github.com/jkitchin/jmax/blob/master/python-mode/test/py-ert-tests.el
+
+(defmacro jade-test-with-temp-buffer-pt-max (contents &rest body)
+ "Creates a temp buffer in `jade-mode' inserting CONTENTS. BODY is code to be
executed within temp buffer. Point is placed at end-of-buffer"
+ (declare (indent 0) (debug t))
+ `(with-temp-buffer
+ (jade-mode)
+ (insert ,contents)
+ (font-lock-fontify-buffer)
+ ,@body))
+
+(defmacro jade-test-with-temp-buffer-pt-min (contents &rest body)
+ "Creates a temp buffer in `jade-mode' inserting CONTENTS. BODY is code to be
executed within temp buffer. Point is placed at beginning-of-buffer"
+ (declare (indent 1))
+ `(jade-test-with-temp-buffer-pt-max
+ ,contents
+ ,@(cons '(goto-char (point-min)) body)))
+
+(defun jade-test-go-to (string)
+ (and (eq (point) (point-max)) (goto-char (point-min)))
+ (search-forward string nil t 1))
+
+(defun jade-test--show-tested-text (text form)
+ form)
+
+(defmacro jade-test-highlight-one-word (word face n)
+ `(jade-test-with-temp-buffer-pt-min
+ ,(concat (s-repeat n "\t") word "\n\n")
+ (print (buffer-string))
+ (should (eq (jade-test--show-tested-text
+ ,word
+ (get-text-property
+ ,(+ 1 n) 'face))
+ ,face))
+ (goto-char ,(+ 1 n))
+ (should (eq
+ (next-single-property-change (point) 'face)
+ (point-at-eol)))))
+
+
+
+
+(byte-to-string 108)
diff --git a/tests/highlight.el b/tests/highlight.el
deleted file mode 100644
index 868d24d953..0000000000
--- a/tests/highlight.el
+++ /dev/null
@@ -1,33 +0,0 @@
-(require 'ert)
-(require 'jade-mode)
-
-(ert-deftest jade-mode-command-should-be-bound ()
- (with-temp-buffer
- (should (fboundp 'jade-mode))
- (should (null (jade-mode)))))
-
-(ert-deftest jade-mode-highlight-doctype ()
- (with-temp-buffer
-
- ;; interesting - if you omit the trailing newline in the string,
- ;; `font-lock-fontify-buffer' will freak out and fail with
- ;; end-of-buffer
- (insert "doctype html\nhtml content\n\n")
- (jade-mode)
-
- ;; temp buffers require explict fontification
- (font-lock-fontify-buffer)
-
- ;; face at char 1 should be `font-lock-comment-face'
- (should (eq
- (get-text-property 1 'face)
- 'font-lock-comment-face))
- (goto-char 1)
-
- ;; face shouldn't change (from `font-lock-comment-face') b/t char
- ;; 1 and eol
- (should (=
- (next-single-property-change (point) 'face)
- (point-at-eol)))))
-
-