@@ -52,24 +52,24 @@ Also, the result should be the same regardless of whether the code is at the beg
52
52
(loop
53
53
for pad-at-beginning from 0 to 1
54
54
do (loop for pad-at-end from 0 to 1
55
- with padding-beginning = (if (= 0 pad-at-beginning) " " padding)
56
- with padding-end = (if (= 0 pad-at-end) " " padding)
57
- with padding-adjust = (* padding-len pad-at-beginning)
58
- with padding-beginning = (if (= 0 pad-at-beginning) " " padding)
59
- with padding-end = (if (= 0 pad-at-end) " " padding)
60
- ; ; If we're adding space to the beginning, and our start position
61
- ; ; is at the very beginning, we want to test within the added space.
62
- ; ; Otherwise adjust the start and end for the beginning padding.
63
- with start-pos = (if (= 1 start-pos) 1 (+ padding-adjust start-pos))
64
- with end-pos = (+ end-pos padding-adjust)
65
- do (loop for pos from start-pos to end-pos
66
- do (rust-test-manip-code
67
- (concat padding-beginning unfilled padding-end)
68
- pos
69
- (lambda ()
70
- (let ((fill-column rust-test-fill-column))
71
- (fill-paragraph )))
72
- (concat padding-beginning expected padding-end)))))))
55
+ with padding-beginning = (if (= 0 pad-at-beginning) " " padding)
56
+ with padding-end = (if (= 0 pad-at-end) " " padding)
57
+ with padding-adjust = (* padding-len pad-at-beginning)
58
+ with padding-beginning = (if (= 0 pad-at-beginning) " " padding)
59
+ with padding-end = (if (= 0 pad-at-end) " " padding)
60
+ ; ; If we're adding space to the beginning, and our start position
61
+ ; ; is at the very beginning, we want to test within the added space.
62
+ ; ; Otherwise adjust the start and end for the beginning padding.
63
+ with start-pos = (if (= 1 start-pos) 1 (+ padding-adjust start-pos))
64
+ with end-pos = (+ end-pos padding-adjust)
65
+ do (loop for pos from start-pos to end-pos
66
+ do (rust-test-manip-code
67
+ (concat padding-beginning unfilled padding-end)
68
+ pos
69
+ (lambda ()
70
+ (let ((fill-column rust-test-fill-column))
71
+ (fill-paragraph )))
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
75
(test-fill-paragraph
@@ -262,14 +262,14 @@ fn bar() { }" 14 67))
262
262
/// "
263
263
103
264
264
" This is the second really really really really really really long paragraph"
265
- " /// This is the first really
265
+ " /// This is the first really
266
266
/// really really really really
267
267
/// really really long paragraph
268
268
///
269
269
/// This is the second really
270
270
/// really really really really
271
271
/// really long paragraph"
272
- ))
272
+ ))
273
273
274
274
(ert-deftest auto-fill-multi-line-prefixless ()
275
275
(test-auto-fill
@@ -295,7 +295,7 @@ very very very long string
295
295
296
296
(ert-deftest indent-struct-fields-aligned ()
297
297
(test-indent
298
- "
298
+ "
299
299
struct Foo { bar: int,
300
300
baz: int }
301
301
@@ -305,7 +305,7 @@ struct Blah {x:int,
305
305
306
306
(ert-deftest indent-doc-comments ()
307
307
(test-indent
308
- "
308
+ "
309
309
/**
310
310
* This is a doc comment
311
311
*
@@ -411,7 +411,7 @@ fn nexted_fns(a: fn(b:int,
411
411
0
412
412
}
413
413
"
414
- ))
414
+ ))
415
415
416
416
(ert-deftest indent-multi-line-expr ()
417
417
(test-indent
@@ -423,206 +423,4 @@ fn foo()
423
423
b();
424
424
}
425
425
"
426
- ))
427
-
428
- (setq rust-test-motion-string
429
- "
430
- fn fn1(arg: int) -> bool {
431
- let x = 5;
432
- let y = b();
433
- true
434
- }
435
-
436
- fn fn2(arg: int) -> bool {
437
- let x = 5;
438
- let y = b();
439
- true
440
- }
441
-
442
- pub fn fn3(arg: int) -> bool {
443
- let x = 5;
444
- let y = b();
445
- true
446
- }
447
-
448
- struct Foo {
449
- x: int
450
- }
451
- "
452
- rust-test-region-string rust-test-motion-string
453
- ; ; Symbol -> (line column)
454
- rust-test-positions-alist '((start-of-fn1 (2 0 ))
455
- (start-of-fn1-middle-of-line (2 15 ))
456
- (middle-of-fn1 (3 7 ))
457
- (end-of-fn1 (6 0 ))
458
- (between-fn1-fn2 (7 0 ))
459
- (start-of-fn2 (8 0 ))
460
- (middle-of-fn2 (10 4 ))
461
- (before-start-of-fn1 (1 0 ))
462
- (after-end-of-fn2 (13 0 ))
463
- (beginning-of-fn3 (14 0 ))
464
- (middle-of-fn3 (16 4 ))
465
- (middle-of-struct (21 10 ))
466
- (before-start-of-struct (19 0 ))
467
- (after-end-of-struct (23 0 ))))
468
-
469
- (defun rust-get-buffer-pos (pos-symbol )
470
- " Get buffer position from POS-SYMBOL.
471
-
472
- POS-SYMBOL is a symbol found in `rust-test-positions-alist' .
473
- Convert the line-column information from that list into a buffer position value."
474
- (interactive " P" )
475
- (pcase-let ((`(, line , column ) (cadr (assoc pos-symbol rust-test-positions-alist))))
476
- (save-excursion
477
- (goto-line line)
478
- (move-to-column column)
479
- (point ))))
480
-
481
- ; ;; TODO: Maybe add an ERT explainer function (something that shows the
482
- ; ;; surrounding code of the final point, not just the position).
483
- (defun rust-test-motion (source-code init-pos final-pos manip-func &optional &rest args )
484
- " Test that MANIP-FUNC moves point from INIT-POS to FINAL-POS.
485
-
486
- If ARGS are provided, send them to MANIP-FUNC.
487
-
488
- INIT-POS, FINAL-POS are position symbols found in `rust-test-positions-alist' ."
489
- (with-temp-buffer
490
- (rust-mode )
491
- (insert source-code)
492
- (goto-char (rust-get-buffer-pos init-pos))
493
- (apply manip-func args)
494
- (should (equal (point ) (rust-get-buffer-pos final-pos)))))
495
-
496
- (defun rust-test-region (source-code init-pos reg-beg reg-end manip-func &optional &rest args )
497
- " Test that MANIP-FUNC marks region from REG-BEG to REG-END.
498
-
499
- INIT-POS is the initial position of point.
500
- If ARGS are provided, send them to MANIP-FUNC.
501
- All positions are position symbols found in `rust-test-positions-alist' ."
502
- (with-temp-buffer
503
- (rust-mode )
504
- (insert source-code)
505
- (goto-char (rust-get-buffer-pos init-pos))
506
- (apply manip-func args)
507
- (should (equal (list (region-beginning ) (region-end ))
508
- (list (rust-get-buffer-pos reg-beg)
509
- (rust-get-buffer-pos reg-end))))))
510
-
511
- (ert-deftest rust-beginning-of-defun-from-middle-of-fn ()
512
- (rust-test-motion
513
- rust-test-motion-string
514
- 'middle-of-fn1
515
- 'start-of-fn1
516
- #'beginning-of-defun ))
517
-
518
- (ert-deftest rust-beginning-of-defun-from-end ()
519
- (rust-test-motion
520
- rust-test-motion-string
521
- 'end-of-fn1
522
- 'start-of-fn1
523
- #'beginning-of-defun ))
524
-
525
- (ert-deftest rust-beginning-of-defun-before-open-brace ()
526
- (rust-test-motion
527
- rust-test-motion-string
528
- 'start-of-fn1-middle-of-line
529
- 'start-of-fn1
530
- #'beginning-of-defun ))
531
-
532
- (ert-deftest rust-beginning-of-defun-between-fns ()
533
- (rust-test-motion
534
- rust-test-motion-string
535
- 'between-fn1-fn2
536
- 'start-of-fn1
537
- #'beginning-of-defun ))
538
-
539
- (ert-deftest rust-beginning-of-defun-with-arg ()
540
- (rust-test-motion
541
- rust-test-motion-string
542
- 'middle-of-fn2
543
- 'start-of-fn1
544
- #'beginning-of-defun 2 ))
545
-
546
- (ert-deftest rust-beginning-of-defun-with-negative-arg ()
547
- (rust-test-motion
548
- rust-test-motion-string
549
- 'middle-of-fn1
550
- 'beginning-of-fn3
551
- #'beginning-of-defun -2 ))
552
-
553
- (ert-deftest rust-beginning-of-defun-pub-fn ()
554
- (rust-test-motion
555
- rust-test-motion-string
556
- 'middle-of-fn3
557
- 'beginning-of-fn3
558
- #'beginning-of-defun ))
559
-
560
- (ert-deftest rust-end-of-defun-from-middle-of-fn ()
561
- (rust-test-motion
562
- rust-test-motion-string
563
- 'middle-of-fn1
564
- 'between-fn1-fn2
565
- #'end-of-defun ))
566
-
567
- (ert-deftest rust-end-of-defun-from-beg ()
568
- (rust-test-motion
569
- rust-test-motion-string
570
- 'start-of-fn1
571
- 'between-fn1-fn2
572
- #'end-of-defun ))
573
-
574
- (ert-deftest rust-end-of-defun-before-open-brace ()
575
- (rust-test-motion
576
- rust-test-motion-string
577
- 'start-of-fn1-middle-of-line
578
- 'between-fn1-fn2
579
- #'end-of-defun ))
580
-
581
- (ert-deftest rust-end-of-defun-between-fns ()
582
- (rust-test-motion
583
- rust-test-motion-string
584
- 'between-fn1-fn2
585
- 'after-end-of-fn2
586
- #'end-of-defun ))
587
-
588
- (ert-deftest rust-end-of-defun-with-arg ()
589
- (rust-test-motion
590
- rust-test-motion-string
591
- 'middle-of-fn1
592
- 'after-end-of-fn2
593
- #'end-of-defun 2 ))
594
-
595
- (ert-deftest rust-end-of-defun-with-negative-arg ()
596
- (rust-test-motion
597
- rust-test-motion-string
598
- 'middle-of-fn3
599
- 'between-fn1-fn2
600
- #'end-of-defun -2 ))
601
-
602
- (ert-deftest rust-mark-defun-from-middle-of-fn ()
603
- (rust-test-region
604
- rust-test-region-string
605
- 'middle-of-fn2
606
- 'between-fn1-fn2 'after-end-of-fn2
607
- #'mark-defun ))
608
-
609
- (ert-deftest rust-mark-defun-from-end ()
610
- (rust-test-region
611
- rust-test-region-string
612
- 'end-of-fn1
613
- 'before-start-of-fn1 'between-fn1-fn2
614
- #'mark-defun ))
615
-
616
- (ert-deftest rust-mark-defun-start-of-defun ()
617
- (rust-test-region
618
- rust-test-region-string
619
- 'start-of-fn2
620
- 'between-fn1-fn2 'after-end-of-fn2
621
- #'mark-defun ))
622
-
623
- (ert-deftest rust-mark-defun-from-middle-of-struct ()
624
- (rust-test-region
625
- rust-test-region-string
626
- 'middle-of-struct
627
- 'before-start-of-struct 'after-end-of-struct
628
- #'mark-defun ))
426
+ ))
0 commit comments