Generate assertion code with error collection instead of immediate panic.
(value_expr: &TokenStream, pattern: &Pattern)
| 74 | |
| 75 | /// Generate assertion code with error collection instead of immediate panic. |
| 76 | fn expand_pattern_assertion(value_expr: &TokenStream, pattern: &Pattern) -> TokenStream { |
| 77 | match pattern { |
| 78 | Pattern::Simple(simple_pattern) => expand_simple_assertion(value_expr, simple_pattern), |
| 79 | Pattern::String(string_pattern) => expand_string_assertion(value_expr, string_pattern), |
| 80 | Pattern::Struct(struct_pattern) => expand_struct_assertion(value_expr, struct_pattern), |
| 81 | Pattern::Comparison(comparison_pattern) => { |
| 82 | expand_comparison_assertion(value_expr, comparison_pattern) |
| 83 | } |
| 84 | Pattern::Enum(enum_pattern) => { |
| 85 | // Enum tuple variant - use collection version |
| 86 | expand_enum_assertion(value_expr, enum_pattern) |
| 87 | } |
| 88 | Pattern::Tuple(tuple_pattern) => { |
| 89 | // Plain tuple - use collection version for proper error collection |
| 90 | expand_tuple_assertion(value_expr, tuple_pattern) |
| 91 | } |
| 92 | Pattern::Wildcard(_) => { |
| 93 | // Wildcard patterns generate no assertions - they just verify the field exists |
| 94 | // which is already handled by the struct/tuple destructuring |
| 95 | quote! {} |
| 96 | } |
| 97 | Pattern::Range(range_pattern) => { |
| 98 | // Generate improved range assertion with error collection |
| 99 | expand_range_assertion(value_expr, range_pattern) |
| 100 | } |
| 101 | Pattern::Slice(slice_pattern) => { |
| 102 | // Generate slice assertion with error collection |
| 103 | expand_slice_assertion(value_expr, slice_pattern) |
| 104 | } |
| 105 | #[cfg(feature = "regex")] |
| 106 | Pattern::Regex(regex_pattern) => { |
| 107 | // Generate regex assertion with error collection |
| 108 | expand_regex_assertion(value_expr, regex_pattern) |
| 109 | } |
| 110 | #[cfg(feature = "regex")] |
| 111 | Pattern::Like(like_pattern) => { |
| 112 | // Generate Like trait assertion with error collection |
| 113 | expand_like_assertion(value_expr, like_pattern) |
| 114 | } |
| 115 | Pattern::Closure(closure_pattern) => { |
| 116 | // Generate closure assertion with error collection |
| 117 | expand_closure_assertion(value_expr, closure_pattern) |
| 118 | } |
| 119 | Pattern::Map(map_pattern) => { |
| 120 | // Generate map assertion with error collection |
| 121 | expand_map_assertion(value_expr, map_pattern) |
| 122 | } |
| 123 | Pattern::Set(set_pattern) => { |
| 124 | // Generate set assertion with backtracking |
| 125 | expand_set_assertion(value_expr, set_pattern) |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /// Generate struct assertion with error collection for multiple field failures |
| 131 | fn expand_struct_assertion(value_expr: &TokenStream, pattern: &PatternStruct) -> TokenStream { |
no test coverage detected