1212(defun rust-test-explain-bad-manip (original point-pos manip-func expected got )
1313 (if (equal expected got)
1414 nil
15- (list
15+ (list
1616 ; ; The (goto-char) and (insert) business here is just for
1717 ; ; convenience--after an error, you can copy-paste that into emacs eval to
1818 ; ; insert the bare strings into a buffer
@@ -66,13 +66,13 @@ Also, the result should be the same regardless of whether the code is at the beg
6666 do (rust-test-manip-code
6767 (concat padding-beginning unfilled padding-end)
6868 pos
69- (lambda ()
69+ (lambda ()
7070 (let ((fill-column rust-test-fill-column))
7171 (fill-paragraph )))
7272 (concat padding-beginning expected padding-end)))))))
7373
7474(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line ()
75- (test-fill-paragraph
75+ (test-fill-paragraph
7676 " /**
7777 * This is a very very very very very very very long string
7878 */"
@@ -188,10 +188,10 @@ This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall.
188188
189189(ert-deftest fill-paragraph-with-no-space-after-star-prefix ()
190190 (test-fill-paragraph
191- " /**
191+ " /**
192192 *This is a very very very very very very very long string
193193 */"
194- " /**
194+ " /**
195195 *This is a very very very very
196196 *very very very long string
197197 */" ))
@@ -226,7 +226,7 @@ fn bar() { }"
226226fn bar() { }" 14 67 ))
227227
228228(defun test-auto-fill (initial position inserted expected )
229- (rust-test-manip-code
229+ (rust-test-manip-code
230230 initial
231231 position
232232 (lambda ()
@@ -244,7 +244,7 @@ fn bar() { }" 14 67))
244244(ert-deftest auto-fill-multi-line-doc-comment ()
245245 (test-auto-fill
246246 " /**
247- *
247+ *
248248 */"
249249 8
250250 " This is a very very very very very very very long string"
@@ -301,7 +301,7 @@ struct Foo { bar: int,
301301
302302struct Blah {x:int,
303303 y:int,
304- z:~str} " ))
304+ z:String " ))
305305
306306(ert-deftest indent-doc-comments ()
307307 (test-indent
@@ -317,7 +317,7 @@ fn foo() {
317317 /*!
318318 * this is a nested doc comment
319319 */
320-
320+
321321 //! And so is this
322322}" ))
323323
@@ -331,7 +331,7 @@ struct foo {
331331 b:char
332332}
333333
334- fn bar(x:~ int) { // comment here should not affect the next indent
334+ fn bar(x:Box< int> ) { // comment here should not affect the next indent
335335 bla();
336336 bla();
337337}" ))
@@ -387,7 +387,7 @@ fn baz( a:int, // shoudl work with a comment here
387387 "
388388fn args_on_the_next_line( // with a comment
389389 a:int,
390- b:~str ) {
390+ b:String ) {
391391 let aaaaaa = [
392392 1,
393393 2,
@@ -456,7 +456,7 @@ fn foo() {
456456 (test-indent
457457 "
458458fn foo() {
459- let x =
459+ let x =
460460 match blah {
461461 Pattern |
462462 Pattern2 => {
@@ -473,7 +473,7 @@ fn foo() {
473473 (test-indent
474474 "
475475fn foo() {
476- let x =
476+ let x =
477477 foo(bar(|x| {
478478 only_one_indent_here();
479479 }));
@@ -572,7 +572,7 @@ fn indenting_middle_of_line() {
572572}
573573
574574fn indented_already() {
575-
575+
576576 // The previous line already has its spaces
577577}
578578"
@@ -654,91 +654,91 @@ All positions are position symbols found in `rust-test-positions-alist'."
654654 (rust-get-buffer-pos reg-end))))))
655655
656656(ert-deftest rust-beginning-of-defun-from-middle-of-fn ()
657- (rust-test-motion
657+ (rust-test-motion
658658 rust-test-motion-string
659659 'middle-of-fn1
660660 'start-of-fn1
661661 #'beginning-of-defun ))
662662
663663(ert-deftest rust-beginning-of-defun-from-end ()
664- (rust-test-motion
664+ (rust-test-motion
665665 rust-test-motion-string
666666 'end-of-fn1
667667 'start-of-fn1
668668 #'beginning-of-defun ))
669669
670670(ert-deftest rust-beginning-of-defun-before-open-brace ()
671- (rust-test-motion
671+ (rust-test-motion
672672 rust-test-motion-string
673673 'start-of-fn1-middle-of-line
674674 'start-of-fn1
675675 #'beginning-of-defun ))
676676
677677(ert-deftest rust-beginning-of-defun-between-fns ()
678- (rust-test-motion
678+ (rust-test-motion
679679 rust-test-motion-string
680680 'between-fn1-fn2
681681 'start-of-fn1
682682 #'beginning-of-defun ))
683683
684684(ert-deftest rust-beginning-of-defun-with-arg ()
685- (rust-test-motion
685+ (rust-test-motion
686686 rust-test-motion-string
687687 'middle-of-fn2
688688 'start-of-fn1
689689 #'beginning-of-defun 2 ))
690690
691691(ert-deftest rust-beginning-of-defun-with-negative-arg ()
692- (rust-test-motion
692+ (rust-test-motion
693693 rust-test-motion-string
694694 'middle-of-fn1
695695 'beginning-of-fn3
696696 #'beginning-of-defun -2 ))
697697
698698(ert-deftest rust-beginning-of-defun-pub-fn ()
699- (rust-test-motion
699+ (rust-test-motion
700700 rust-test-motion-string
701701 'middle-of-fn3
702702 'beginning-of-fn3
703703 #'beginning-of-defun ))
704704
705705(ert-deftest rust-end-of-defun-from-middle-of-fn ()
706- (rust-test-motion
706+ (rust-test-motion
707707 rust-test-motion-string
708708 'middle-of-fn1
709709 'between-fn1-fn2
710710 #'end-of-defun ))
711711
712712(ert-deftest rust-end-of-defun-from-beg ()
713- (rust-test-motion
713+ (rust-test-motion
714714 rust-test-motion-string
715715 'start-of-fn1
716716 'between-fn1-fn2
717717 #'end-of-defun ))
718718
719719(ert-deftest rust-end-of-defun-before-open-brace ()
720- (rust-test-motion
720+ (rust-test-motion
721721 rust-test-motion-string
722722 'start-of-fn1-middle-of-line
723723 'between-fn1-fn2
724724 #'end-of-defun ))
725725
726726(ert-deftest rust-end-of-defun-between-fns ()
727- (rust-test-motion
727+ (rust-test-motion
728728 rust-test-motion-string
729729 'between-fn1-fn2
730730 'after-end-of-fn2
731731 #'end-of-defun ))
732732
733733(ert-deftest rust-end-of-defun-with-arg ()
734- (rust-test-motion
734+ (rust-test-motion
735735 rust-test-motion-string
736736 'middle-of-fn1
737737 'after-end-of-fn2
738738 #'end-of-defun 2 ))
739739
740740(ert-deftest rust-end-of-defun-with-negative-arg ()
741- (rust-test-motion
741+ (rust-test-motion
742742 rust-test-motion-string
743743 'middle-of-fn3
744744 'between-fn1-fn2
@@ -752,14 +752,14 @@ All positions are position symbols found in `rust-test-positions-alist'."
752752 #'mark-defun ))
753753
754754(ert-deftest rust-mark-defun-from-end ()
755- (rust-test-region
755+ (rust-test-region
756756 rust-test-region-string
757757 'end-of-fn1
758758 'before-start-of-fn1 'between-fn1-fn2
759759 #'mark-defun ))
760760
761761(ert-deftest rust-mark-defun-start-of-defun ()
762- (rust-test-region
762+ (rust-test-region
763763 rust-test-region-string
764764 'start-of-fn2
765765 'between-fn1-fn2 'after-end-of-fn2
@@ -834,3 +834,63 @@ All positions are position symbols found in `rust-test-positions-alist'."
834834 'nonblank-line-indented-already-middle-start
835835 'nonblank-line-indented-already-middle-target
836836 #'indent-for-tab-command ))
837+
838+ (defun rust-test-fontify-string (str )
839+ (with-temp-buffer
840+ (rust-mode )
841+ (insert str)
842+ (font-lock-fontify-buffer )
843+ (buffer-string )))
844+
845+ (defun rust-test-group-str-by-face (str )
846+ " Fontify `STR' in rust-mode and group it by face, returning a
847+ list of substrings of `STR' each followed by its face."
848+ (cl-loop with fontified = (rust-test-fontify-string str)
849+ for start = 0 then end
850+ while start
851+ for end = (next-single-property-change start 'face fontified)
852+ for prop = (get-text-property start 'face fontified)
853+ for text = (substring-no-properties fontified start end)
854+ if prop
855+ append (list text prop)))
856+
857+ (defun rust-test-font-lock (source face-groups )
858+ " Test that `SOURCE' fontifies to the expected `FACE-GROUPS' "
859+ (should (equal (rust-test-group-str-by-face source )
860+ face-groups)))
861+
862+ (ert-deftest font-lock-attribute-simple ()
863+ (rust-test-font-lock
864+ " #[foo]"
865+ '(" #[foo]" font-lock-preprocessor-face )))
866+
867+ (ert-deftest font-lock-attribute-inner ()
868+ (rust-test-font-lock
869+ " #![foo]"
870+ '(" #![foo]" font-lock-preprocessor-face )))
871+
872+ (ert-deftest font-lock-attribute-key-value ()
873+ (rust-test-font-lock
874+ " #[foo = \" bar\" ]"
875+ '(" #[foo = " font-lock-preprocessor-face
876+ " \" bar\" " font-lock-string-face
877+ " ]" font-lock-preprocessor-face )))
878+
879+ (ert-deftest font-lock-attribute-around-comment ()
880+ (rust-test-font-lock
881+ " #[foo /* bar */]"
882+ '(" #[foo " font-lock-preprocessor-face
883+ " /* " font-lock-comment-delimiter-face
884+ " bar */" font-lock-comment-face
885+ " ]" font-lock-preprocessor-face )))
886+
887+ (ert-deftest font-lock-attribute-inside-string ()
888+ (rust-test-font-lock
889+ " \" #[foo]\" "
890+ '(" \" #[foo]\" " font-lock-string-face )))
891+
892+ (ert-deftest font-lock-attribute-inside-comment ()
893+ (rust-test-font-lock
894+ " /* #[foo] */"
895+ '(" /* " font-lock-comment-delimiter-face
896+ " #[foo] */" font-lock-comment-face )))
0 commit comments