Skip to content

Commit 7e25637

Browse files
committed
feat: v2.0.0
1 parent 3cf3c08 commit 7e25637

File tree

4 files changed

+20
-71
lines changed

4 files changed

+20
-71
lines changed

debug/src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use lombok_macros::*;
2-
use std::fmt::Debug;
2+
use std::{f64::consts::PI, fmt::Debug};
33

44
#[derive(Data, Debug, Clone, DisplayDebugFormat)]
55
struct LombokTest<'a, T: Clone + Debug> {
@@ -121,9 +121,9 @@ struct ComplexNestedStruct {
121121

122122
#[derive(CustomDebug)]
123123
enum ComplexEnum {
124-
SimpleVariant,
125-
TupleVariant(String, i32),
126-
StructVariant {
124+
Simple,
125+
Tuple(String, i32),
126+
Struct {
127127
field1: String,
128128
#[debug(skip)]
129129
_secret: String,
@@ -181,7 +181,6 @@ struct MultiAttributes {
181181
complex_field: Vec<String>,
182182
}
183183

184-
#[test]
185184
fn main() {
186185
let mut data: LombokTest<usize> = LombokTest {
187186
list: Vec::new(),
@@ -300,17 +299,17 @@ fn main() {
300299
assert_eq!(complex.get_nested().get_name(), "inner");
301300
assert_eq!(complex.get_nested_list().len(), 1);
302301
assert_eq!(complex.get_metadata().get("key").unwrap(), "value");
303-
let simple = ComplexEnum::SimpleVariant;
304-
let tuple = ComplexEnum::TupleVariant("test".to_string(), 123);
305-
let struct_variant = ComplexEnum::StructVariant {
302+
let simple = ComplexEnum::Simple;
303+
let tuple = ComplexEnum::Tuple("test".to_string(), 123);
304+
let struct_variant = ComplexEnum::Struct {
306305
field1: "visible".to_string(),
307306
_secret: "hidden".to_string(),
308-
value: 3.14,
307+
value: PI,
309308
};
310309
let simple_debug = format!("{simple:?}");
311310
let tuple_debug = format!("{tuple:?}");
312311
let struct_debug = format!("{struct_variant:?}");
313-
assert!(simple_debug.contains("SimpleVariant"));
312+
assert!(simple_debug.contains("Simple"));
314313
assert!(tuple_debug.contains("test"));
315314
assert!(tuple_debug.contains("123"));
316315
assert!(struct_debug.contains("visible"));

src/parse/fn.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ pub(crate) fn parse_tokens(tokens: TokenStream2, config: &mut Config) {
2929
config.visibility = Visibility::PublicCrate;
3030
} else if ident_str == PUBLIC_SUPER && config.visibility.is_public() {
3131
config.visibility = Visibility::PublicSuper;
32-
} else if ReturnType::is_known(&ident_str) {
33-
if config.return_type.is_default() {
34-
config.return_type = ident_str.parse::<ReturnType>().unwrap_or_default();
35-
}
32+
} else if ReturnType::is_known(&ident_str) && config.return_type.is_default() {
33+
config.return_type = ident_str.parse::<ReturnType>().unwrap_or_default();
3634
}
3735
}
3836
TokenTree2::Group(group) => {

tests/comprehensive_reference_clone_test.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,27 @@ use lombok_macros::*;
22

33
#[derive(Getter, Clone)]
44
struct ComprehensiveTestStruct {
5-
// Basic types
65
#[get(pub, reference)]
76
name_ref: String,
8-
97
#[get(pub, clone)]
108
name_clone: String,
11-
12-
// Option types
139
#[get(pub, reference)]
1410
optional_string_ref: Option<String>,
15-
1611
#[get(pub, clone)]
1712
optional_string_clone: Option<String>,
18-
19-
// Vec types
2013
#[get(pub, reference)]
2114
vec_ref: Vec<i32>,
22-
2315
#[get(pub, clone)]
2416
vec_clone: Vec<i32>,
25-
26-
// With visibility and other attributes
2717
#[get(pub(crate), reference)]
2818
_crate_ref: String,
29-
3019
#[get(private, clone)]
3120
_private_clone: String,
3221
}
3322

3423
#[test]
3524
fn test_comprehensive_reference_clone() {
36-
let test = ComprehensiveTestStruct {
25+
let test: ComprehensiveTestStruct = ComprehensiveTestStruct {
3726
name_ref: "reference_name".to_string(),
3827
name_clone: "clone_name".to_string(),
3928
optional_string_ref: Some("opt_ref".to_string()),
@@ -43,28 +32,16 @@ fn test_comprehensive_reference_clone() {
4332
_crate_ref: "crate_reference".to_string(),
4433
_private_clone: "private_clone".to_string(),
4534
};
46-
47-
// Test basic reference returns &String
4835
let name_ref: &String = test.get_name_ref();
4936
assert_eq!(*name_ref, "reference_name");
50-
51-
// Test basic clone returns String
5237
let name_clone: String = test.get_name_clone();
5338
assert_eq!(name_clone, "clone_name");
54-
55-
// Test option reference returns &Option<String>
5639
let opt_ref: &Option<String> = test.get_optional_string_ref();
5740
assert_eq!(opt_ref, &Some("opt_ref".to_string()));
58-
59-
// Test option clone returns Option<String>
6041
let opt_clone: Option<String> = test.get_optional_string_clone();
6142
assert_eq!(opt_clone, Some("opt_clone".to_string()));
62-
63-
// Test vec reference returns &Vec<i32>
6443
let vec_ref: &Vec<i32> = test.get_vec_ref();
6544
assert_eq!(vec_ref, &vec![1, 2, 3]);
66-
67-
// Test vec clone returns Vec<i32>
6845
let vec_clone: Vec<i32> = test.get_vec_clone();
6946
assert_eq!(vec_clone, vec![4, 5, 6]);
7047
}
@@ -73,23 +50,18 @@ fn test_comprehensive_reference_clone() {
7350
struct TestDefaultBehavior {
7451
#[get(pub)]
7552
default_field: String,
76-
7753
#[get(pub)]
7854
default_option: Option<String>,
7955
}
8056

8157
#[test]
8258
fn test_default_behavior() {
83-
let test = TestDefaultBehavior {
59+
let test: TestDefaultBehavior = TestDefaultBehavior {
8460
default_field: "default".to_string(),
8561
default_option: Some("option_default".to_string()),
8662
};
87-
88-
// Default should return reference for non-Option types
8963
let default_ref: &String = test.get_default_field();
9064
assert_eq!(*default_ref, "default");
91-
92-
// Default should return inner value for Option types (cloned)
9365
let default_option: String = test.get_default_option();
9466
assert_eq!(default_option, "option_default");
9567
}

tests/reference_clone_test.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,54 @@ use lombok_macros::*;
44
struct TestStruct {
55
#[get(pub, reference)]
66
field_ref: String,
7-
87
#[get(pub, clone)]
98
field_clone: String,
10-
119
#[get(pub)]
1210
field_default: String,
13-
1411
#[get(pub, reference)]
1512
optional_ref: Option<String>,
16-
1713
#[get(pub, clone)]
1814
optional_clone: Option<String>,
1915
}
2016

2117
#[test]
2218
fn test_reference_clone_getters() {
23-
let test = TestStruct {
19+
let test: TestStruct = TestStruct {
2420
field_ref: "reference_field".to_string(),
2521
field_clone: "clone_field".to_string(),
2622
field_default: "default_field".to_string(),
2723
optional_ref: Some("optional_ref".to_string()),
2824
optional_clone: Some("optional_clone".to_string()),
2925
};
30-
31-
// Test reference getter - should return &String
3226
let ref_result: &String = test.get_field_ref();
3327
assert_eq!(*ref_result, "reference_field");
34-
35-
// Test clone getter - should return String
3628
let clone_result: String = test.get_field_clone();
3729
assert_eq!(clone_result, "clone_field");
38-
39-
// Test default getter - should return &String (default behavior for non-Option)
4030
let default_result: &String = test.get_field_default();
4131
assert_eq!(*default_result, "default_field");
42-
43-
// Test reference getter for Option - should return &Option<String>
4432
let opt_ref_result: &Option<String> = test.get_optional_ref();
4533
assert_eq!(opt_ref_result, &Some("optional_ref".to_string()));
46-
47-
// Test clone getter for Option - should return Option<String>
4834
let opt_clone_result: Option<String> = test.get_optional_clone();
4935
assert_eq!(opt_clone_result, Some("optional_clone".to_string()));
5036
}
5137

5238
#[test]
5339
fn test_return_type_behavior() {
54-
let test = TestStruct {
40+
let test: TestStruct = TestStruct {
5541
field_ref: "test".to_string(),
5642
field_clone: "test".to_string(),
5743
field_default: "test".to_string(),
5844
optional_ref: Some("test".to_string()),
5945
optional_clone: Some("test".to_string()),
6046
};
61-
62-
// Verify reference returns work correctly
63-
let ref_val = test.get_field_ref();
64-
let same_ref_val = test.get_field_ref();
65-
// Both should point to the same underlying data
47+
let ref_val: &String = test.get_field_ref();
48+
let same_ref_val: &String = test.get_field_ref();
6649
assert!(std::ptr::eq(ref_val, same_ref_val));
67-
68-
// Verify clone returns work correctly
69-
let clone_val1 = test.get_field_clone();
70-
let clone_val2 = test.get_field_clone();
71-
// These should be different owned values
50+
let clone_val1: String = test.get_field_clone();
51+
let clone_val2: String = test.get_field_clone();
7252
assert_ne!(
7353
std::ptr::addr_of!(clone_val1),
7454
std::ptr::addr_of!(clone_val2)
7555
);
76-
assert_eq!(clone_val1, clone_val2); // But have the same content
56+
assert_eq!(clone_val1, clone_val2);
7757
}

0 commit comments

Comments
 (0)