Skip to content
Browse files

add font-face tests

  • Loading branch information...
1 parent 1a51d11 commit 6320a0d5722757c64ae5cf777c9273a1d846e2ae @abicky abicky committed Jun 11, 2012
View
2 .gitignore
@@ -1,2 +1,4 @@
*~
*.elc
+\#*
+.\#*
View
14 Makefile
@@ -0,0 +1,14 @@
+TARGET=jsx-mode
+
+all: $(TARGET).elc
+
+clean:
+ @rm -f $(TARGET).elc $(TARGET).el~
+
+test:
+ @emacs --script test/font-face-test.el
+
+.el.elc:
+ @emacs -batch -f batch-byte-compile $<
+
+.PHONY: clean test
View
2 jsx-mode.el
@@ -208,7 +208,7 @@
(defconst jsx--regex-literal-re
(concat
"\\(?:^\\|[(,;:]\\)\\s-*"
- "\\(/[^/\\]*\\(?:\\\\.[^/\\]*\\)*/[gim]*\\)"))
+ "\\(/[^/\\\n]*\\(?:\\\\.[^/\\\n]*\\)*/[gim]*\\)"))
(defconst jsx--builtin-function-re
(concat
View
109 test/font-face-test.el
@@ -0,0 +1,109 @@
+;;; font-face-test.el --- run the test for font faces of a major mode
+
+;; Copyright (c) 2012 Takeshi Arabiki (abicky)
+
+;; Author: Takeshi Arabiki (abicky)
+
+;; Permission is hereby granted, free of charge, to any person obtaining a copy
+;; of this software and associated documentation files (the "Software"), to deal
+;; in the Software without restriction, including without limitation the rights
+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+;; copies of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be included in
+;; all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+;; THE SOFTWARE.
+
+;;; Code:
+
+(require 'cl)
+
+(cd (file-name-directory load-file-name))
+(load-file "../jsx-mode.el")
+(add-to-list 'auto-mode-alist '("\\.jsx\\'" . jsx-mode))
+
+(defvar jsx-dir "jsx/font-face")
+
+(defun get-test-suite ()
+ (when (string-match "^/\\*\\(?:.\\|\n\\)*\\*/" (buffer-string))
+ (let ((beg (match-beginning 0))
+ (end (match-end 0))
+ test-suite token)
+ (while (search-forward-regexp
+ "\\([^ \t\n:][^\n:]*\\)\\s-*:\\s-*\\([-a-z]+\\)" end t)
+ (setq token (match-string 1))
+ (put-text-property 0 (length token) 'face (intern (match-string 2)) token)
+ (setq test-suite (append test-suite (list token))))
+ (goto-char end)
+ (end-of-line)
+ test-suite)))
+
+(defun next-token ()
+ (let ((buf (current-buffer)))
+ (goto-char (or (next-property-change (point) buf) (point-max)))
+ (while (and
+ (not (get-text-property (point) 'face buf))
+ (not (eobp)))
+ (goto-char (or (next-property-change (point) buf) (point-max))))
+ (if (eobp)
+ nil
+ (replace-regexp-in-string
+ "[ \t\r\n]+$" ""
+ (buffer-substring (point) (next-property-change (point) buf))))))
+
+(defun run-test ()
+ (let* ((cnt 0)
+ (failed-cnt 0)
+ (msg "")
+ (start-time (current-time-string))
+ (files (directory-files jsx-dir nil "\\.jsx\\'"))
+ (total-cnt (length files)))
+ (setq font-lock-verbose nil)
+ (dolist (file files)
+ (setq cnt (1+ cnt))
+ (with-current-buffer (find-file-noselect (concat jsx-dir "/" file))
+ (font-lock-default-fontify-buffer)
+ (goto-char (point-min))
+ (let ((test-suite (get-test-suite))
+ (errors '())
+ expected)
+ (while (setq token (next-token))
+ (setq expected (or (pop test-suite) ""))
+ (condition-case ex
+ (assert (and (equal expected token) (equal-face expected token)))
+ (error
+ (setq errors (append errors (list (make-error-msg expected token)))))))
+ (when (> (length errors) 0)
+ (setq msg (format "%sF %s:\n%s\n\n" msg file (mapconcat 'identity errors "\n\n")))
+ (setq failed-cnt (1+ failed-cnt))))))
+ (message
+ (concat
+ "Passed: " (format "%d\n" (- cnt failed-cnt))
+ "Failed: " (format "%d\n" failed-cnt)
+ "Total: " (format "%d/%d\n" cnt total-cnt)
+ "\n"
+ "Started at: " start-time "\n"
+ "Finished at: " (current-time-string) "\n"
+ "\n"
+ msg))))
+
+(defun equal-face (a b)
+ (eq (get-text-property 0 'face a) (get-text-property 0 'face b)))
+
+(defun make-error-msg (expected actual)
+ (format
+ "\texpected: %s (%s)\n\tactual: %s (%s)"
+ (substring-no-properties expected)
+ (get-text-property 0 'face expected)
+ (substring-no-properties actual)
+ (get-text-property 0 'face actual)))
+
+(run-test)
View
30 test/jsx/font-face/000_classdef.jsx
@@ -0,0 +1,30 @@
+/*
+ abstract: font-lock-keyword-face
+ class: font-lock-keyword-face
+ Bar: font-lock-type-face
+ interface: font-lock-keyword-face
+ I_a: font-lock-type-face
+ mixin: font-lock-keyword-face
+ I_b: font-lock-type-face
+ class: font-lock-keyword-face
+ Foo: font-lock-type-face
+ extends: font-lock-keyword-face
+ Bar: font-lock-type-face
+ implements: font-lock-keyword-face
+ I_a: font-lock-type-face
+ I_b: font-lock-type-face
+*/
+
+abstract
+ class
+ Bar {
+}
+
+interface I_a {
+}
+
+mixin I_b {
+}
+
+class Foo extends Bar implements I_a, I_b {
+}
View
57 test/jsx/font-face/001_funcdef.jsx
@@ -0,0 +1,57 @@
+/*
+ function: font-lock-keyword-face
+ foo: font-lock-function-name-face
+ a: font-lock-variable-name-face
+ int: font-lock-type-face
+ b: font-lock-variable-name-face
+ Map: font-lock-type-face
+ string: font-lock-type-face
+ function: font-lock-keyword-face
+ int: font-lock-type-face
+ string: font-lock-type-face
+ void: font-lock-type-face
+
+ return: font-lock-keyword-face
+ function: font-lock-keyword-face
+ a: font-lock-variable-name-face
+ int: font-lock-type-face
+ b: font-lock-variable-name-face
+ string: font-lock-type-face
+ void: font-lock-type-face
+ log: font-lock-builtin-face
+ "foo": font-lock-string-face
+
+ override: font-lock-keyword-face
+ function: font-lock-keyword-face
+ bar: font-lock-function-name-face
+ a: font-lock-variable-name-face
+ int: font-lock-type-face
+ b: font-lock-variable-name-face
+ string: font-lock-type-face
+ function: font-lock-keyword-face
+ int: font-lock-type-face
+ string: font-lock-type-face
+ void: font-lock-type-face
+
+ return: font-lock-keyword-face
+ function: font-lock-keyword-face
+ a: font-lock-variable-name-face
+ int: font-lock-type-face
+ b: font-lock-variable-name-face
+ string: font-lock-type-face
+ void: font-lock-type-face
+ log: font-lock-builtin-face
+*/
+
+
+ function foo(a : int,
+ b : Map.<string>) : function(: int,
+ : string) : void {
+ return function(a : int, b : string) : void { log "foo"; };
+ }
+
+ override function bar(a : int, b : string) : function(:int, :string) : void {
+ return function(a : int, b : string) : void {
+ log b;
+ };
+ }
View
26 test/jsx/font-face/002_func_in_map.jsx
@@ -0,0 +1,26 @@
+/*
+ var: font-lock-keyword-face
+ obj: font-lock-variable-name-face
+
+ a: font-lock-function-name-face
+ function: font-lock-keyword-face
+ void: font-lock-type-face
+ log: font-lock-builtin-face
+ "a": font-lock-string-face
+
+ b: font-lock-function-name-face
+ function: font-lock-keyword-face
+ void: font-lock-type-face
+ log: font-lock-builtin-face
+ "}": font-lock-string-face
+
+ null: font-lock-constant-face
+*/
+
+ var obj = {
+ a: function() : void {
+ log "a";
+ },
+ b: function() : void { log "}"; }, c: func,
+ d: null
+ };
View
15 test/jsx/font-face/003_func_arg.jsx
@@ -0,0 +1,15 @@
+/*
+ function: font-lock-keyword-face
+ func: font-lock-function-name-face
+ str: font-lock-variable-name-face
+ string: font-lock-type-face
+ func: font-lock-variable-name-face
+ function: font-lock-keyword-face
+ string: font-lock-type-face
+ foo: font-lock-type-face
+ void: font-lock-type-face
+ Foo: font-lock-type-face
+*/
+
+function func(str : string, func : function(:string, :foo) : void) : Foo {
+}
View
16 test/jsx/font-face/004_with_underscore.jsx
@@ -0,0 +1,16 @@
+/*
+ var: font-lock-keyword-face
+ __date__: font-lock-variable-name-face
+
+ var: font-lock-keyword-face
+ str: font-lock-variable-name-face
+ as: font-lock-keyword-face
+ __noconvert__: font-lock-keyword-face
+ string: font-lock-type-face
+
+ __FILE__: font-lock-constant-face
+*/
+
+ var __date__ = Date.now();
+ var str = __date__ as __noconvert__ string;
+ __FILE__
View
37 test/jsx/font-face/005_vardef.jsx
@@ -0,0 +1,37 @@
+/*
+ var: font-lock-keyword-face
+ foo: font-lock-variable-name-face
+ Foo: font-lock-type-face
+
+ var: font-lock-keyword-face
+ array: font-lock-variable-name-face
+ string: font-lock-type-face
+
+ var: font-lock-keyword-face
+ func: font-lock-variable-name-face
+ function: font-lock-keyword-face
+ void: font-lock-type-face
+
+ var: font-lock-keyword-face
+ strMap: font-lock-variable-name-face
+ Map: font-lock-type-face
+ string: font-lock-type-face
+
+ var: font-lock-keyword-face
+ fooMap: font-lock-variable-name-face
+ Map: font-lock-type-face
+ Foo: font-lock-type-face
+
+ var: font-lock-keyword-face
+ funcMap: font-lock-variable-name-face
+ Map: font-lock-type-face
+ function: font-lock-keyword-face
+ void: font-lock-type-face
+*/
+
+ var foo: Foo;
+ var array = [] : string[];
+ var func = function() : void {};
+ var strMap = {} : Map.< string >;
+ var fooMap = {} : Map.<Foo>;
+ var funcMap = {} : Map.<function() : void>;
View
9 test/jsx/font-face/006_regex.jsx
@@ -0,0 +1,9 @@
+/*
+ //comment: font-lock-comment-face
+ /fo\/o/igm: font-lock-string-face
+*/
+
+ //comment
+ str.match(/fo\/o/igm);
+ str.match(/fo\\
+ o/igm);
View
7 test/jsx/font-face/007_quote.jsx
@@ -0,0 +1,7 @@
+/*
+ "double quoted": font-lock-string-face
+ 'single quoted': font-lock-string-face
+*/
+
+ "double quoted";
+ 'single quoted';
View
14 test/jsx/font-face/008_create_instance.jsx
@@ -0,0 +1,14 @@
+/*
+ var: font-lock-keyword-face
+ foo1: font-lock-variable-name-face
+ new: font-lock-keyword-face
+ Foo: font-lock-type-face
+
+ var: font-lock-keyword-face
+ foo2: font-lock-variable-name-face
+ new: font-lock-keyword-face
+ Foo: font-lock-type-face
+*/
+
+ var foo1 = new Foo();
+ var foo2 = new a.Foo();
View
20 test/jsx/font-face/009_return_type.jsx
@@ -0,0 +1,20 @@
+/*
+ function: font-lock-keyword-face
+ createFoo: font-lock-function-name-face
+ Foo: font-lock-type-face
+
+ function: font-lock-keyword-face
+ createBar: font-lock-function-name-face
+ Bar: font-lock-type-face
+
+ true: font-lock-constant-face
+*/
+
+ function createFoo() : Foo {
+ }
+
+ function createBar() : Bar
+ {
+ }
+
+ true ? str.substring(pos) : str.substring(0, pos)

0 comments on commit 6320a0d

Please sign in to comment.
Something went wrong with that request. Please try again.