12
12
(defun rust-test-explain-bad-manip (original point-pos manip-func expected got )
13
13
(if (equal expected got)
14
14
nil
15
- (list
15
+ (list
16
16
; ; The (goto-char) and (insert) business here is just for
17
17
; ; convenience--after an error, you can copy-paste that into emacs eval to
18
18
; ; 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
66
66
do (rust-test-manip-code
67
67
(concat padding-beginning unfilled padding-end)
68
68
pos
69
- (lambda ()
69
+ (lambda ()
70
70
(let ((fill-column rust-test-fill-column))
71
71
(fill-paragraph )))
72
72
(concat padding-beginning expected padding-end)))))))
73
73
74
74
(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line ()
75
- (test-fill-paragraph
75
+ (test-fill-paragraph
76
76
" /**
77
77
* This is a very very very very very very very long string
78
78
*/"
@@ -188,10 +188,10 @@ This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall.
188
188
189
189
(ert-deftest fill-paragraph-with-no-space-after-star-prefix ()
190
190
(test-fill-paragraph
191
- " /**
191
+ " /**
192
192
*This is a very very very very very very very long string
193
193
*/"
194
- " /**
194
+ " /**
195
195
*This is a very very very very
196
196
*very very very long string
197
197
*/" ))
@@ -226,7 +226,7 @@ fn bar() { }"
226
226
fn bar() { }" 14 67 ))
227
227
228
228
(defun test-auto-fill (initial position inserted expected )
229
- (rust-test-manip-code
229
+ (rust-test-manip-code
230
230
initial
231
231
position
232
232
(lambda ()
@@ -244,7 +244,7 @@ fn bar() { }" 14 67))
244
244
(ert-deftest auto-fill-multi-line-doc-comment ()
245
245
(test-auto-fill
246
246
" /**
247
- *
247
+ *
248
248
*/"
249
249
8
250
250
" This is a very very very very very very very long string"
@@ -301,7 +301,7 @@ struct Foo { bar: int,
301
301
302
302
struct Blah {x:int,
303
303
y:int,
304
- z:~str} " ))
304
+ z:String " ))
305
305
306
306
(ert-deftest indent-doc-comments ()
307
307
(test-indent
@@ -317,7 +317,7 @@ fn foo() {
317
317
/*!
318
318
* this is a nested doc comment
319
319
*/
320
-
320
+
321
321
//! And so is this
322
322
}" ))
323
323
@@ -331,7 +331,7 @@ struct foo {
331
331
b:char
332
332
}
333
333
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
335
335
bla();
336
336
bla();
337
337
}" ))
@@ -387,7 +387,7 @@ fn baz( a:int, // shoudl work with a comment here
387
387
"
388
388
fn args_on_the_next_line( // with a comment
389
389
a:int,
390
- b:~str ) {
390
+ b:String ) {
391
391
let aaaaaa = [
392
392
1,
393
393
2,
@@ -456,7 +456,7 @@ fn foo() {
456
456
(test-indent
457
457
"
458
458
fn foo() {
459
- let x =
459
+ let x =
460
460
match blah {
461
461
Pattern |
462
462
Pattern2 => {
@@ -473,7 +473,7 @@ fn foo() {
473
473
(test-indent
474
474
"
475
475
fn foo() {
476
- let x =
476
+ let x =
477
477
foo(bar(|x| {
478
478
only_one_indent_here();
479
479
}));
@@ -572,7 +572,7 @@ fn indenting_middle_of_line() {
572
572
}
573
573
574
574
fn indented_already() {
575
-
575
+
576
576
// The previous line already has its spaces
577
577
}
578
578
"
@@ -654,91 +654,91 @@ All positions are position symbols found in `rust-test-positions-alist'."
654
654
(rust-get-buffer-pos reg-end))))))
655
655
656
656
(ert-deftest rust-beginning-of-defun-from-middle-of-fn ()
657
- (rust-test-motion
657
+ (rust-test-motion
658
658
rust-test-motion-string
659
659
'middle-of-fn1
660
660
'start-of-fn1
661
661
#'beginning-of-defun ))
662
662
663
663
(ert-deftest rust-beginning-of-defun-from-end ()
664
- (rust-test-motion
664
+ (rust-test-motion
665
665
rust-test-motion-string
666
666
'end-of-fn1
667
667
'start-of-fn1
668
668
#'beginning-of-defun ))
669
669
670
670
(ert-deftest rust-beginning-of-defun-before-open-brace ()
671
- (rust-test-motion
671
+ (rust-test-motion
672
672
rust-test-motion-string
673
673
'start-of-fn1-middle-of-line
674
674
'start-of-fn1
675
675
#'beginning-of-defun ))
676
676
677
677
(ert-deftest rust-beginning-of-defun-between-fns ()
678
- (rust-test-motion
678
+ (rust-test-motion
679
679
rust-test-motion-string
680
680
'between-fn1-fn2
681
681
'start-of-fn1
682
682
#'beginning-of-defun ))
683
683
684
684
(ert-deftest rust-beginning-of-defun-with-arg ()
685
- (rust-test-motion
685
+ (rust-test-motion
686
686
rust-test-motion-string
687
687
'middle-of-fn2
688
688
'start-of-fn1
689
689
#'beginning-of-defun 2 ))
690
690
691
691
(ert-deftest rust-beginning-of-defun-with-negative-arg ()
692
- (rust-test-motion
692
+ (rust-test-motion
693
693
rust-test-motion-string
694
694
'middle-of-fn1
695
695
'beginning-of-fn3
696
696
#'beginning-of-defun -2 ))
697
697
698
698
(ert-deftest rust-beginning-of-defun-pub-fn ()
699
- (rust-test-motion
699
+ (rust-test-motion
700
700
rust-test-motion-string
701
701
'middle-of-fn3
702
702
'beginning-of-fn3
703
703
#'beginning-of-defun ))
704
704
705
705
(ert-deftest rust-end-of-defun-from-middle-of-fn ()
706
- (rust-test-motion
706
+ (rust-test-motion
707
707
rust-test-motion-string
708
708
'middle-of-fn1
709
709
'between-fn1-fn2
710
710
#'end-of-defun ))
711
711
712
712
(ert-deftest rust-end-of-defun-from-beg ()
713
- (rust-test-motion
713
+ (rust-test-motion
714
714
rust-test-motion-string
715
715
'start-of-fn1
716
716
'between-fn1-fn2
717
717
#'end-of-defun ))
718
718
719
719
(ert-deftest rust-end-of-defun-before-open-brace ()
720
- (rust-test-motion
720
+ (rust-test-motion
721
721
rust-test-motion-string
722
722
'start-of-fn1-middle-of-line
723
723
'between-fn1-fn2
724
724
#'end-of-defun ))
725
725
726
726
(ert-deftest rust-end-of-defun-between-fns ()
727
- (rust-test-motion
727
+ (rust-test-motion
728
728
rust-test-motion-string
729
729
'between-fn1-fn2
730
730
'after-end-of-fn2
731
731
#'end-of-defun ))
732
732
733
733
(ert-deftest rust-end-of-defun-with-arg ()
734
- (rust-test-motion
734
+ (rust-test-motion
735
735
rust-test-motion-string
736
736
'middle-of-fn1
737
737
'after-end-of-fn2
738
738
#'end-of-defun 2 ))
739
739
740
740
(ert-deftest rust-end-of-defun-with-negative-arg ()
741
- (rust-test-motion
741
+ (rust-test-motion
742
742
rust-test-motion-string
743
743
'middle-of-fn3
744
744
'between-fn1-fn2
@@ -752,14 +752,14 @@ All positions are position symbols found in `rust-test-positions-alist'."
752
752
#'mark-defun ))
753
753
754
754
(ert-deftest rust-mark-defun-from-end ()
755
- (rust-test-region
755
+ (rust-test-region
756
756
rust-test-region-string
757
757
'end-of-fn1
758
758
'before-start-of-fn1 'between-fn1-fn2
759
759
#'mark-defun ))
760
760
761
761
(ert-deftest rust-mark-defun-start-of-defun ()
762
- (rust-test-region
762
+ (rust-test-region
763
763
rust-test-region-string
764
764
'start-of-fn2
765
765
'between-fn1-fn2 'after-end-of-fn2
@@ -834,3 +834,63 @@ All positions are position symbols found in `rust-test-positions-alist'."
834
834
'nonblank-line-indented-already-middle-start
835
835
'nonblank-line-indented-already-middle-target
836
836
#'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