Skip to content

Commit

Permalink
Merge pull request #166 from josteink/rework
Browse files Browse the repository at this point in the history
Rework
  • Loading branch information
theothornhill committed Sep 30, 2020
2 parents 7cb8d05 + 919dd65 commit f6314e5
Show file tree
Hide file tree
Showing 5 changed files with 423 additions and 3,142 deletions.
259 changes: 58 additions & 201 deletions csharp-mode-tests.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(require 'ert)
(require 'cl-lib)
(require 'csharp-mode)
(require 'cl)
(require 'package)

;; development only packages, not declared as a package-dependency
Expand Down Expand Up @@ -94,35 +93,35 @@
19 'font-lock-string-face
)))

(ert-deftest fontification-of-compiler-directives ()
;; this replaces the manual test of
;; test-files/fontification-test-compiler-directives.cs, but file
;; has been kept around to assist manual testing/verification.
(assess-face-in-file= "test-files/fontification-test-compiler-directives.cs"
"strReference" 'font-lock-string-face
"strVerification" 'font-lock-string-face
"singleQuote" 'font-lock-string-face
"doubleQuote" 'font-lock-string-face)

(assess-face-in-text=
"#region test\nbool bar = true;"
;; should not be interpreted as string because of trailing \!
"bool" 'font-lock-type-face
"bar" 'font-lock-variable-name-face
"true" 'font-lock-constant-face
)
(should (assess-face-at=
"#region test'\nx = true;"
'csharp-mode
;; should not be interpreted as string because of trailing \!
"true" 'font-lock-constant-face
))
(should (assess-face-at=
"#region test\"\nx = true;"
'csharp-mode
;; should not be interpreted as string because of trailing \!
"true" 'font-lock-constant-face
)))
;; (ert-deftest fontification-of-compiler-directives ()
;; ;; this replaces the manual test of
;; ;; test-files/fontification-test-compiler-directives.cs, but file
;; ;; has been kept around to assist manual testing/verification.
;; (assess-face-in-file= "test-files/fontification-test-compiler-directives.cs"
;; "strReference" 'font-lock-string-face
;; "strVerification" 'font-lock-string-face
;; "singleQuote" 'font-lock-string-face
;; "doubleQuote" 'font-lock-string-face)

;; (assess-face-in-text=
;; "#region test\nbool bar = true;"
;; ;; should not be interpreted as string because of trailing \!
;; "bool" 'font-lock-type-face
;; "bar" 'font-lock-variable-name-face
;; "true" 'font-lock-constant-face
;; )
;; (should (assess-face-at=
;; "#region test'\nx = true;"
;; 'csharp-mode
;; ;; should not be interpreted as string because of trailing \!
;; "true" 'font-lock-constant-face
;; ))
;; (should (assess-face-at=
;; "#region test\"\nx = true;"
;; 'csharp-mode
;; ;; should not be interpreted as string because of trailing \!
;; "true" 'font-lock-constant-face
;; )))

(ert-deftest fontification-of-compiler-directives-after-comments ()
(assess-face-in-file= "./test-files/fontification-test-compiler-directives-with-comments.cs"
Expand All @@ -143,19 +142,23 @@
(ert-deftest fontification-of-using-statements ()
(assess-face-in-file= "./test-files/using-fontification.cs"
"using" 'font-lock-keyword-face
"Reference" 'font-lock-constant-face
"Under_scored" 'font-lock-constant-face
"WithNumbers09.Ok" 'font-lock-constant-face
"WithNumbers09.OkV2" 'font-lock-constant-face
"Reference" 'font-lock-type-face
"Under_scored" 'font-lock-type-face
"WithNumbers09" 'font-lock-constant-face
"Ok" 'font-lock-type-face
"WithNumbers09" 'font-lock-constant-face
"OkV2" 'font-lock-type-face
))

(ert-deftest fontification-of-namespace-statements ()
(assess-face-in-file= "./test-files/namespace-fontification.cs"
"namespace" 'font-lock-keyword-face
"Reference" 'font-lock-constant-face
"Under_scored" 'font-lock-constant-face
"WithNumbers09.Ok" 'font-lock-constant-face
"WithNumbers09.OkV2" 'font-lock-constant-face
"Reference" 'font-lock-type-face
"Under_scored" 'font-lock-type-face
"WithNumbers09" 'font-lock-constant-face
"Ok" 'font-lock-type-face
"WithNumbers09" 'font-lock-constant-face
"Ok" 'font-lock-type-face
))

(defun list-repeat-once (mylist)
Expand Down Expand Up @@ -225,152 +228,6 @@
(equal expected (match-string 1)))))
(kill-buffer buffer))))

(defun imenu-get-item (index haystack)
(let ((result))
(dolist (item index)
(when (not result)
(let ((name (car item))
(value (cdr item)))
(if (string-prefix-p haystack name)
(setq result item)
(when (listp value)
(setq result (imenu-get-item value haystack)))))))
result))

(defmacro def-imenutest (testname filename &rest items)
`(ert-deftest ,testname ()
(let* ((find-file-hook nil) ;; avoid vc-mode file-hooks when opening!
(buffer (find-file-read-only ,filename))
(index (csharp--imenu-create-index-function)))
(dolist (item ',items)
(should (imenu-get-item index item)))
(kill-buffer buffer))))

(def-imenutest imenu-parsing-supports-generic-parameters
"./test-files/imenu-generics-test.cs"
"(method) NoGeneric(" "(method) OneGeneric<T>(" "(method) TwoGeneric<T1,T2>(")

(def-imenutest imenu-parsing-supports-comments
"./test-files/imenu-comment-test.cs"
"(method) HasNoComment(" "(method) HasComment(" "(method) CommentedToo(")

(def-imenutest imenu-parsing-supports-explicit-interface-properties
"./test-files/imenu-interface-property-test.cs"
"(prop) IImenuTest.InterfaceString")

(def-imenutest imenu-parsing-supports-explicit-interface-methods
"./test-files/imenu-interface-property-test.cs"
"(method) IImenuTest.MethodName")

(def-imenutest imenu-parsing-provides-types-with-namespace-names
"./test-files/imenu-namespace-test.cs"
"class ImenuTest.ImenuTestClass"
"interface ImenuTest.ImenuTestInterface"
"enum ImenuTest.ImenuTestEnum")

(def-imenutest imenu-parsing-supports-fields-keywords
"./test-files/imenu-field-keyword-test.cs"
"(field) TestBool"
"(field) CommentedField"
"(field) _MultiLineComment"
"(field) VolatileTest"
"(field) m_Member")

(def-imenutest imenu-parsing-supports-method-keywords
"./test-files/imenu-method-test.cs"
"(method) GetTickCount64("
"(method) OpenWebServiceAsync("
"(method) ToString("
"(method) AbstractMethod("
"(method) UnsafeCopy("
"(method) GenericMethod1<T>"
"(method) GenericMethod2<T1,T2>"
"(method) NestedGeneric")

(def-imenutest imenu-parsing-supports-delegates
"./test-files/imenu-delegate-test.cs"
"delegate PromptCallback"
"delegate PromptStateCallback"
"delegate PromptStateCallback<T>"
"delegate Foobar.TargetCallback"
"delegate Foobar.TargetStateCallback"
"delegate Foobar.TargetStateCallback<T>")

(ert-deftest imenu-indexing-resolves-correct-container ()
(let* ((testcase-no-namespace '( ("class Global" . 10)
(("namespace_a" . 20) ("namespace_b" . 30))
nil))
(testcase-namespace-a '( ("class A" . 10)
(("namespace_a" . 0) ("namespace_b" . 30))
"namespace_a"))
(testcase-namespace-b '( ("class B" . 40)
(("namespace_a" . 0) ("namespace_b" . 30))
"namespace_b"))
(testcases (list testcase-no-namespace
testcase-namespace-a
testcase-namespace-b)))
(dolist (testcase testcases)
(let ((class (car testcase))
(namespaces (cadr testcase))
(expected (caddr testcase)))
(should (equal expected
(csharp--imenu-get-container-name class namespaces)))))))

(ert-deftest imenu-indexing-resolves-correct-name ()
(let* ((testcase-no-namespace '( ("class Global" . 10)
(("namespace_a" . 20) ("namespace_b" . 30))
"class Global"))
(testcase-namespace-a '( ("class A" . 10)
(("namespace_a" . 0) ("namespace_b" . 30))
"class namespace_a.A"))
(testcase-namespace-b '( ("class B" . 40)
(("namespace_a" . 0) ("namespace_b" . 30))
"class namespace_b.B"))
(testcases (list testcase-no-namespace
testcase-namespace-a
testcase-namespace-b)))
(dolist (testcase testcases)
(let ((class (car testcase))
(namespaces (cadr testcase))
(expected (caddr testcase)))
(should (equal expected
(csharp--imenu-get-class-name class namespaces)))))))

(ert-deftest imenu-transforms-index-correctly ()
;; this test-case checks for the following aspects of the transformation:
;; 1. hierarchial nesting
;; 2. sorting of members
(should (equalp
'(("class A" . (("( top )" . 20)
("(method) method_a1" . 30)
("(method) method_a2" . 25)))
("class B" . (("( top )" . 0)
("(method) method_b1" . 15)
("(method) method_b2" . 10))))

(csharp--imenu-transform-index
'(("class" . (("class B" . 0) ("class A" . 20)))
("method" . (("method_b2" . 10) ("method_b1" . 15)
("method_a2" . 25) ("method_a1" . 30))))))))

(ert-deftest imenu-transforms-index-correctly-with-namespaces ()
;; this test-case checks for the following aspects of the transformation:
;; 1. hierarchial nesting
;; 2. sorting of members
(should (equalp
'(("class ns.A" . (("( top )" . 20)
("(method) method_a1" . 30)
("(method) method_a2" . 25)))
("class ns.B" . (("( top )" . 0)
("(method) method_b1" . 15)
("(method) method_b2" . 10))))

(csharp--imenu-transform-index
'(("namespace" . (("ns" . 0)))
("class" . (("class B" . 0) ("class A" . 20)))
("method" . (("method_b2" . 10) ("method_b1" . 15)
("method_a2" . 25) ("method_a1" . 30))))))))

(defvar csharp-hook1 nil)
(defvar csharp-hook2 nil)

Expand Down Expand Up @@ -413,16 +270,16 @@
(forward-word -1)
(should (looking-at "fontifies")))

(ert-deftest fontification-of-regions ()
(require 'assess)
(require 'm-buffer)
(find-file "test-files/region-fontification.cs")
(csharp-mode)
(let ((buf (current-buffer)))
;; look for 'a region comment' - should always be a comment
(should (assess-face-at= buf 'csharp-mode (lambda (buf) (m-buffer-match buf "a region comment")) 'font-lock-comment-face))
;; look for 'string' - should always be a type
(should (assess-face-at= buf 'csharp-mode (lambda (buf) (m-buffer-match buf "string")) 'font-lock-type-face))))
;; (ert-deftest fontification-of-regions ()
;; (require 'assess)
;; (require 'm-buffer)
;; (find-file "test-files/region-fontification.cs")
;; (csharp-mode)
;; (let ((buf (current-buffer)))
;; ;; look for 'a region comment' - should always be a comment
;; (should (assess-face-at= buf 'csharp-mode (lambda (buf) (m-buffer-match buf "a region comment")) 'font-lock-comment-face))
;; ;; look for 'string' - should always be a type
;; (should (assess-face-at= buf 'csharp-mode (lambda (buf) (m-buffer-match buf "string")) 'font-lock-type-face))))

(ert-deftest activating-mode-doesnt-clobber-global-adaptive-fill-regexp ()
(let ((before adaptive-fill-regexp))
Expand All @@ -432,25 +289,25 @@
(equal before adaptive-fill-regexp))))

(ert-deftest activating-mode-style-defaults-to-csharp ()
(let ((c-default-style "defaultc#"))
(let ((c-default-style "csharp"))
(with-temp-buffer
(csharp-mode)
(should
(equal "defaultc#" c-indentation-style))))
(let ((c-default-style '((csharp-mode . "defaultc#fromlist")
(java-mode . "defaultjava"))))
(equal "csharp" c-indentation-style))))
(let ((c-default-style '((csharp-mode . "csharp")
(java-mode . "java"))))
(with-temp-buffer
(csharp-mode)
(should
(equal "defaultc#fromlist" c-indentation-style))))
(equal "csharp" c-indentation-style))))
(let (c-default-style)
(with-temp-buffer
(csharp-mode)
(should
(equal "C#" c-indentation-style)))))
(equal "csharp" c-indentation-style)))))

(ert-deftest inside-bracelist-test ()
(let ((c-default-style "defaultc#"))
(let ((c-default-style "csharp"))
(with-temp-buffer
(csharp-mode)
(insert "public class A { public void F() {")
Expand Down

0 comments on commit f6314e5

Please sign in to comment.