Skip to content

Commit 84bab53

Browse files
committed
test(fontlock): update tests related to arglist fontification
1 parent d21c983 commit 84bab53

File tree

1 file changed

+174
-17
lines changed

1 file changed

+174
-17
lines changed

typescript-mode-general-tests.el

+174-17
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3): ret3;"
358358
("exportedDefaultDefn" . font-lock-function-name-face)
359359
("declareFunctionDefn" . font-lock-function-name-face)
360360
(("x0" "x1" "x2" "x3") . font-lock-variable-name-face)
361-
(("y0" "y1" "y2" "y3") . font-lock-variable-name-face)
361+
(("\\by0" "\\by1" "\\by2" "\\by3") . font-lock-variable-name-face)
362362
(("ret0" "ret1" "ret2" "ret3") . nil))))
363363

364364
(ert-deftest font-lock/level-four ()
@@ -380,7 +380,7 @@ snake_cased_function(1, 2, 3)"
380380
("methodCall" . font-lock-function-name-face)
381381
("snake_cased_function" . font-lock-function-name-face)
382382
(("string" "boolean" "number" "any") . typescript-primitive-face)
383-
(("endpoint" "data") . nil)
383+
(("endpoint" "data") . font-lock-variable-name-face)
384384
(("<" ">" ",") . nil))))
385385

386386
(ert-deftest font-lock/generics ()
@@ -593,19 +593,24 @@ should be fontified as variable, keyword and type."
593593
(should (eq (get-face-at "Namespaced") 'font-lock-type-face))
594594
(should (eq (get-face-at "ClassName") 'font-lock-type-face))))
595595

596-
(ert-deftest font-lock/variables-in-declaration-multiline-with-types ()
596+
(ert-deftest font-lock/funargs--function--multiline-with-types ()
597597
"Variables should be highlighted in multiline declarations with types."
598598
(test-with-fontified-buffer
599599
"function test(
600-
var1: Type1,
601-
var2: Type2,
600+
var1: Promise<U1, V1>,
601+
var2: (xxx: Foo) => Bar,
602+
var3: Type3,
602603
): RetType {\n}"
603604
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
604605
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))
605-
(should (eq (get-face-at "Type1") 'font-lock-type-face))
606-
(should (eq (get-face-at "Type2") 'font-lock-type-face))))
606+
(should (eq (get-face-at "var3") 'font-lock-variable-name-face))
607+
(should (eq (get-face-at "xxx") 'font-lock-variable-name-face))
608+
(should (eq (get-face-at "Promise") 'font-lock-type-face))
609+
(should (eq (get-face-at "U1") 'font-lock-type-face))
610+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
611+
(should (eq (get-face-at "Type3") 'font-lock-type-face))))
607612

608-
(ert-deftest font-lock/variables-in-declaration-multiline-without-types ()
613+
(ert-deftest font-lock/funargs--function--multiline-without-types ()
609614
"Variables should be highlighted in multiline declarations without types."
610615
(test-with-fontified-buffer
611616
"function test(
@@ -615,33 +620,33 @@ var2,
615620
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
616621
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
617622

618-
(ert-deftest font-lock/variables-in-declaration-multiline-no-hanging-paren ()
619-
"Variables should be highlighted in multiline declarations with no hanging paren."
623+
(ert-deftest font-lock/funargs--function--multiline-hanging-paren ()
624+
"Variables should be highlighted in multiline declarations with hanging paren."
620625
(test-with-fontified-buffer
621626
"function test(
622627
var1,
623628
var2): RetType {\n}"
624629
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
625630
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
626631

627-
(ert-deftest font-lock/variables-in-declaration-multiline-ending-comma-no-hanging-paren ()
628-
"Variables should be highlighted in multiline declarations with no hanging paren and trailing comma."
632+
(ert-deftest font-lock/funargs--function--multiline-ending-comma-hanging-paren ()
633+
"Variables should be highlighted in multiline declarations with hanging paren and trailing comma."
629634
(test-with-fontified-buffer
630635
"function test(
631636
var1,
632637
var2,): RetType {\n}"
633638
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
634639
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
635640

636-
(ert-deftest font-lock/variables-in-declaration-singleline-ending-comma-hanging-paren ()
637-
"Variables should be highlighted in singleline declarations with hanging paren and trailing comma."
641+
(ert-deftest font-lock/funargs--function--singleline-ending-comma-no-hanging-paren ()
642+
"Variables should be highlighted in singleline declarations with no hanging paren and trailing comma."
638643
(test-with-fontified-buffer
639644
"function test(var1,var2,
640645
): RetType {\n}"
641646
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
642647
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
643648

644-
(ert-deftest font-lock/variables-in-declaration-singleline-with-types ()
649+
(ert-deftest font-lock/funargs--function--singleline-with-types ()
645650
"Variables should be highlighted in singleline declarations with types."
646651
(test-with-fontified-buffer
647652
"function test(var1: Foo, var2: Bar,): RetType {\n}"
@@ -650,13 +655,165 @@ var2,): RetType {\n}"
650655
(should (eq (get-face-at "Foo") 'font-lock-type-face))
651656
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
652657

653-
(ert-deftest font-lock/variables-in-declaration-singleline-ending-comma-no-hanging-paren ()
654-
"Variables should be highlighted in singleline declarations with no hanging paren and trailing comma."
658+
(ert-deftest font-lock/funargs--function--singleline-ending-comma-hanging-paren ()
659+
"Variables should be highlighted in singleline declarations with hanging paren and trailing comma."
655660
(test-with-fontified-buffer
656661
"function test(var1,var2,): RetType {\n}"
657662
(should (eq (get-face-at "var1") 'font-lock-variable-name-face))
658663
(should (eq (get-face-at "var2") 'font-lock-variable-name-face))))
659664

665+
(ert-deftest font-lock/funargs--function--keywords-as-variables ()
666+
"Keywords when used as variables should have variable face"
667+
(test-with-fontified-buffer
668+
"function test(type, unknown): void {}"
669+
(should (eq (get-face-at "type") 'font-lock-variable-name-face))
670+
(should (eq (get-face-at "unknown") 'font-lock-variable-name-face))))
671+
672+
(ert-deftest font-lock/funargs--arrow--keywords-as-variables ()
673+
"Keywords when used as variables should have variable face"
674+
(test-with-fontified-buffer
675+
"const test = (type, unknown): void => {}"
676+
(should (eq (get-face-at "type") 'font-lock-variable-name-face))
677+
(should (eq (get-face-at "unknown") 'font-lock-variable-name-face))))
678+
679+
(ert-deftest font-lock/funargs--arrow--single-line--no-type ()
680+
(test-with-fontified-buffer
681+
"const test = (aaa, bbb, ccc): void => {}"
682+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
683+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
684+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
685+
686+
(ert-deftest font-lock/funargs--arrow--single-line--no-type--no-return-type ()
687+
(test-with-fontified-buffer
688+
"const test = (aaa, bbb, ccc) => {}"
689+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
690+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
691+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
692+
693+
(ert-deftest font-lock/funargs--arrow--single-line--no-type--trailing-comma ()
694+
(test-with-fontified-buffer
695+
"const test = (aaa, bbb, ccc,): void => {}"
696+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
697+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
698+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))))
699+
700+
(ert-deftest font-lock/funargs--arrow--single-line--no-type--optional ()
701+
(test-with-fontified-buffer
702+
"const test = (aaa, bbb?): void => {}"
703+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
704+
(should (eq (get-face-at "bbb?") 'font-lock-variable-name-face))))
705+
706+
(ert-deftest font-lock/funargs--arrow--multiline--no-type ()
707+
(test-with-fontified-buffer
708+
"const test = (aaa, bbb,
709+
ccc, ddd): void => {}"
710+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
711+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
712+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
713+
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
714+
715+
(ert-deftest font-lock/funargs--arrow--multiline--no-type--newline-after-last ()
716+
(test-with-fontified-buffer
717+
"const test = (aaa, bbb,
718+
ccc, ddd
719+
): void => {}"
720+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
721+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
722+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
723+
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
724+
725+
(ert-deftest font-lock/funargs--arrow--multiline--no-type--newline-before-first ()
726+
(test-with-fontified-buffer
727+
"const test = (
728+
aaa, bbb,
729+
ccc, ddd
730+
): void => {}"
731+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
732+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
733+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
734+
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
735+
736+
(ert-deftest font-lock/funargs--arrow--multiline--no-type--with-comment ()
737+
(test-with-fontified-buffer
738+
"const test = (
739+
aaa, bbb, // comment
740+
ccc, ddd // comment
741+
): void => {}"
742+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
743+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
744+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
745+
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))))
746+
747+
(ert-deftest font-lock/funargs--arrow--single--mixed-type--newline-before-first ()
748+
(test-with-fontified-buffer
749+
"const test = (aaa, bbb: Promise, ccc: number, ddd): void => {}"
750+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
751+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
752+
(should (eq (get-face-at "ccc") 'font-lock-variable-name-face))
753+
(should (eq (get-face-at "ddd") 'font-lock-variable-name-face))
754+
(should (eq (get-face-at "Promise") 'font-lock-type-face))
755+
(should (eq (get-face-at "number") 'typescript-primitive-face))))
756+
757+
(ert-deftest font-lock/funargs--arrow--single--with-type--complex-type ()
758+
(test-with-fontified-buffer
759+
"const test = (aaa: Promise<U, V, (xxx: A) => Foo>, bbb): void => {}"
760+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
761+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
762+
(should (eq (get-face-at "xxx") 'font-lock-variable-name-face))))
763+
764+
(ert-deftest font-lock/funargs--arrow--multiline--with-type--newline-before-first-after-last ()
765+
(test-with-fontified-buffer
766+
"const test = (
767+
aaa: Foo,
768+
bbb: Bar
769+
): void => {}"
770+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
771+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
772+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
773+
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
774+
775+
(ert-deftest font-lock/funargs--arrow--multiline--with-type--newline-before-first-after-last--hanging-comma ()
776+
(test-with-fontified-buffer
777+
"const test = (
778+
aaa: Foo,
779+
bbb: Bar,
780+
): void => {}"
781+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
782+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
783+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
784+
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
785+
786+
(ert-deftest font-lock/funargs--method--multiline--with-type ()
787+
(test-with-fontified-buffer
788+
"class Foo { foo(
789+
aaa: Foo,
790+
bbb: Bar,
791+
): void {}"
792+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
793+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
794+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
795+
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
796+
797+
(ert-deftest font-lock/funargs--method--single-line--with-type ()
798+
(test-with-fontified-buffer
799+
"class Foo { foo(aaa: Foo,bbb: Bar,): void {}"
800+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
801+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))
802+
(should (eq (get-face-at "Foo") 'font-lock-type-face))
803+
(should (eq (get-face-at "Bar") 'font-lock-type-face))))
804+
805+
(ert-deftest font-lock/funargs--method--single-line--no-type ()
806+
(test-with-fontified-buffer
807+
"class Foo { foo(aaa, bbb): void {}"
808+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
809+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))))
810+
811+
(ert-deftest font-lock/funargs--method--single-line--no-return-type ()
812+
(test-with-fontified-buffer
813+
"class Foo { foo(aaa, bbb) {}"
814+
(should (eq (get-face-at "aaa") 'font-lock-variable-name-face))
815+
(should (eq (get-face-at "bbb") 'font-lock-variable-name-face))))
816+
660817
(defun flyspell-predicate-test (search-for)
661818
"This function runs a test on
662819
`typescript--flyspell-mode-predicate'. `SEARCH-FOR' is a string

0 commit comments

Comments
 (0)