Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

vkazanov/ert-font-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WARNING: no longer developed separately from Emacs as of 29.03.2024

ERT Font Lock

ERT Font Lock, or ert-font-lock is an extension to standard Emacs Lisp Regression Test library (ERT) providing an intuitive way to check syntax highlighting provided by font-lock.

Syntax

ert-font-lock is inspired by Tree-sitter’s unit testing system. It makes it possbile to specify expected faces through formatted comments as follows:

var abc = function(d) {
// <- font-lock-keyword-face
//   ^ font-lock-variable-name-face
    //        ^ font-lock-keyword-face
    //             ^ font-lock-variable-name-face
};

Test assertions are specified by comment-only lines. Only whitespace is allowed in the beginning of the line.

The caret in such a line (^) means that a column in the first non-comment line above the current one should have the face specified by a symbol following the caret.

The arrow (<-) means that the first comment-starting character would be come the column to check.

Usage

ert-font-lock entry points are functions ert-font-lock-test-string and `ert-font-lock-test-file’ and covenience test-defining macros: ert-font-lock-deftest and ert-font-lock-deftest-file.

Examples

Tests defined through a string:

(ert-deftest test-syntax-highlight-string--correct ()
  (ert-font-lock-test-string
   "
var abc = function(d) {
// <- font-lock-keyword-face
//   ^ font-lock-variable-name-face
    //        ^ font-lock-keyword-face
    //             ^ font-lock-variable-name-face
};

"
   'javascript-mode))

Tests read from a file:

(ert-deftest test-syntax-highlight-file--correct ()
  (ert-font-lock-test-file
   (ert-resource-file "correct.js")
   'javascript-mode))

Example of an ERT test file using the provided convenience macros:

(require 'ert)
(require 'ert-font-lock)

(ert-font-lock-deftest test-macro-test--correct emacs-lisp-mode
  "An inline test"
  "
(defun fun ())
;; ^ font-lock-keyword-face
;;      ^ font-lock-function-name-face")

(ert-font-lock-deftest test-macro-test--docstring
    "An inline test with a docstring"
  emacs-lisp-mode
  "
(defun fun ())
;; ^ font-lock-keyword-face")

(ert-font-lock-deftest-file test-macro-test--file
    "A file test"
  javascript-mode
  "correct.js")

The macros define usual ERT tests that can be run through ert-run-tests-interactively, or from a command line using eacs / cask and ert-runner.

Releases

No releases published

Packages

No packages published