Sha256: 370542ed242d0eede64baf54cedf00050b010a0350a2894e3bcd7cf7bf64efd9

Contents?: true

Size: 1.77 KB

Versions: 23

Compression:

Stored size: 1.77 KB

Contents

;;; gyp-tests.el - unit tests for gyp-mode.

;; Copyright (c) 2012 Google Inc. All rights reserved.
;; Use of this source code is governed by a BSD-style license that can be
;; found in the LICENSE file.

;; The recommended way to run these tests is to run them from the command-line,
;; with the run-unit-tests.sh script.

(require 'cl)
(require 'ert)
(require 'gyp)

(defconst samples (directory-files "testdata" t ".gyp$")
  "List of golden samples to check")

(defun fontify (filename)
  (with-temp-buffer
    (insert-file-contents-literally filename)
    (gyp-mode)
    (font-lock-fontify-buffer)
    (buffer-string)))

(defun read-golden-sample (filename)
  (with-temp-buffer
    (insert-file-contents-literally (concat filename ".fontified"))
    (read (current-buffer))))

(defun text-face-properties (s)
  "Extract the text properties from s"
  (let ((result (list t)))
    (dotimes (i (length s))
      (setq result (cons (get-text-property i 'face s) result)))
    (nreverse result)))

(ert-deftest test-golden-samples ()
  "Check that fontification produces the same results as the golden samples"
  (dolist (sample samples)
    (let ((golden (read-golden-sample sample))
          (fontified (fontify sample)))
      (should (equal golden fontified))
      (should (equal (text-face-properties golden)
                     (text-face-properties fontified))))))

(defun create-golden-sample (filename)
  "Create a golden sample by fontifying filename and writing out the printable
   representation of the fontified buffer (with text properties) to the
   FILENAME.fontified"
  (with-temp-file (concat filename ".fontified")
    (print (fontify filename) (current-buffer))))

(defun create-golden-samples ()
  "Recreate the golden samples"
  (dolist (sample samples) (create-golden-sample sample)))

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
libv8-3.16.14.19.1 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.19 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.18 vendor/gyp/tools/emacs/gyp-tests.el
arcabouco-0.2.13 vendor/bundle/gems/libv8-3.16.14.17/vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.17 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.16 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.15 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.14 vendor/gyp/tools/emacs/gyp-tests.el
libv8-tmpfork-3.16.14.13 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.13 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.12 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.11 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.10 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.8 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.8.rc1 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.7 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.6 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.5 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.4 vendor/gyp/tools/emacs/gyp-tests.el
libv8-3.16.14.3 vendor/gyp/tools/emacs/gyp-tests.el