diff options
author | Yoshua Wuyts <[email protected]> | 2021-02-09 11:30:13 +0000 |
---|---|---|
committer | Yoshua Wuyts <[email protected]> | 2021-02-09 23:08:41 +0000 |
commit | e8d7bcc35507425f384cff25feb564ac41a5c5a7 (patch) | |
tree | e83b3748c4471ba020e169b199982f64270970de /crates/assists/src/tests | |
parent | 876c4519e37db3cd134efb5dda604ac5a29c3853 (diff) |
Add getter/setter assists
Finish implementing `generate_setter` assists
Make `generate_impl_text` util generic
generate getter methods
Fix getter / setter naming
It's now in-line with the Rust API naming guidelines: https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter
apply clippy
Improve examples
Diffstat (limited to 'crates/assists/src/tests')
-rw-r--r-- | crates/assists/src/tests/generated.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 0dbb05f2a..6f2b22bc2 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs | |||
@@ -534,6 +534,54 @@ fn bar(arg: &str, baz: Baz) ${0:-> ()} { | |||
534 | } | 534 | } |
535 | 535 | ||
536 | #[test] | 536 | #[test] |
537 | fn doctest_generate_getter() { | ||
538 | check_doc_test( | ||
539 | "generate_getter", | ||
540 | r#####" | ||
541 | struct Person { | ||
542 | nam$0e: String, | ||
543 | } | ||
544 | "#####, | ||
545 | r#####" | ||
546 | struct Person { | ||
547 | name: String, | ||
548 | } | ||
549 | |||
550 | impl Person { | ||
551 | /// Get a reference to the person's name. | ||
552 | fn name(&self) -> &String { | ||
553 | &self.name | ||
554 | } | ||
555 | } | ||
556 | "#####, | ||
557 | ) | ||
558 | } | ||
559 | |||
560 | #[test] | ||
561 | fn doctest_generate_getter_mut() { | ||
562 | check_doc_test( | ||
563 | "generate_getter_mut", | ||
564 | r#####" | ||
565 | struct Person { | ||
566 | nam$0e: String, | ||
567 | } | ||
568 | "#####, | ||
569 | r#####" | ||
570 | struct Person { | ||
571 | name: String, | ||
572 | } | ||
573 | |||
574 | impl Person { | ||
575 | /// Get a mutable reference to the person's name. | ||
576 | fn name_mut(&mut self) -> &mut String { | ||
577 | &mut self.name | ||
578 | } | ||
579 | } | ||
580 | "#####, | ||
581 | ) | ||
582 | } | ||
583 | |||
584 | #[test] | ||
537 | fn doctest_generate_impl() { | 585 | fn doctest_generate_impl() { |
538 | check_doc_test( | 586 | check_doc_test( |
539 | "generate_impl", | 587 | "generate_impl", |
@@ -571,7 +619,30 @@ struct Ctx<T: Clone> { | |||
571 | impl<T: Clone> Ctx<T> { | 619 | impl<T: Clone> Ctx<T> { |
572 | fn $0new(data: T) -> Self { Self { data } } | 620 | fn $0new(data: T) -> Self { Self { data } } |
573 | } | 621 | } |
622 | "#####, | ||
623 | ) | ||
624 | } | ||
574 | 625 | ||
626 | #[test] | ||
627 | fn doctest_generate_setter() { | ||
628 | check_doc_test( | ||
629 | "generate_setter", | ||
630 | r#####" | ||
631 | struct Person { | ||
632 | nam$0e: String, | ||
633 | } | ||
634 | "#####, | ||
635 | r#####" | ||
636 | struct Person { | ||
637 | name: String, | ||
638 | } | ||
639 | |||
640 | impl Person { | ||
641 | /// Set the person's name. | ||
642 | fn set_name(&mut self, name: String) { | ||
643 | self.name = name; | ||
644 | } | ||
645 | } | ||
575 | "#####, | 646 | "#####, |
576 | ) | 647 | ) |
577 | } | 648 | } |