|
7 | 7 |
|
8 | 8 | import unittest |
9 | 9 |
|
10 | | -from ..input_filters.doxygen_strip_comments import ( |
11 | | - strip_block_comments, |
12 | | - strip_deprecated_msg, |
13 | | -) |
| 10 | +from ..input_filters.strip_block_comments import strip_block_comments |
| 11 | +from ..input_filters.strip_deprecated_msg import strip_deprecated_msg |
| 12 | +from ..input_filters.strip_ns_unavailable import strip_ns_unavailable |
14 | 13 |
|
15 | 14 |
|
16 | 15 | class TestDoxygenStripComments(unittest.TestCase): |
@@ -116,5 +115,98 @@ def test_strips_deprecated_before_interface(self): |
116 | 115 | self.assertEqual(result, "@interface RCTSurface : NSObject") |
117 | 116 |
|
118 | 117 |
|
| 118 | +class TestStripNSUnavailable(unittest.TestCase): |
| 119 | + def test_strips_single_line_init(self): |
| 120 | + content = "- (instancetype)init NS_UNAVAILABLE;" |
| 121 | + result = strip_ns_unavailable(content) |
| 122 | + self.assertEqual(result, "") |
| 123 | + |
| 124 | + def test_strips_single_line_new(self): |
| 125 | + content = "+ (instancetype)new NS_UNAVAILABLE;" |
| 126 | + result = strip_ns_unavailable(content) |
| 127 | + self.assertEqual(result, "") |
| 128 | + |
| 129 | + def test_strips_init_with_frame(self): |
| 130 | + content = "- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;" |
| 131 | + result = strip_ns_unavailable(content) |
| 132 | + self.assertEqual(result, "") |
| 133 | + |
| 134 | + def test_strips_property(self): |
| 135 | + content = "@property (nonatomic, copy, nullable) NSString *text NS_UNAVAILABLE;" |
| 136 | + result = strip_ns_unavailable(content) |
| 137 | + self.assertEqual(result, "") |
| 138 | + |
| 139 | + def test_strips_method_with_params(self): |
| 140 | + content = ( |
| 141 | + "- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index" |
| 142 | + " NS_UNAVAILABLE;" |
| 143 | + ) |
| 144 | + result = strip_ns_unavailable(content) |
| 145 | + self.assertEqual(result, "") |
| 146 | + |
| 147 | + def test_strips_multiline_declaration(self): |
| 148 | + content = ( |
| 149 | + "- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface\n" |
| 150 | + " sizeMeasureMode:(RCTSurfaceSizeMeasureMode)" |
| 151 | + "sizeMeasureMode NS_UNAVAILABLE;" |
| 152 | + ) |
| 153 | + result = strip_ns_unavailable(content) |
| 154 | + # Should preserve line count (2 lines -> 1 newline) |
| 155 | + self.assertEqual(result, "\n") |
| 156 | + |
| 157 | + def test_preserves_normal_methods(self): |
| 158 | + content = "- (instancetype)initWithBridge:(RCTBridge *)bridge;" |
| 159 | + result = strip_ns_unavailable(content) |
| 160 | + self.assertEqual(result, content) |
| 161 | + |
| 162 | + def test_preserves_normal_properties(self): |
| 163 | + content = "@property (nonatomic, strong) NSString *name;" |
| 164 | + result = strip_ns_unavailable(content) |
| 165 | + self.assertEqual(result, content) |
| 166 | + |
| 167 | + def test_preserves_designated_initializer(self): |
| 168 | + content = ( |
| 169 | + "- (instancetype)initWithName:(NSString *)name NS_DESIGNATED_INITIALIZER;" |
| 170 | + ) |
| 171 | + result = strip_ns_unavailable(content) |
| 172 | + self.assertEqual(result, content) |
| 173 | + |
| 174 | + def test_does_not_strip_across_semicolons(self): |
| 175 | + content = ( |
| 176 | + "- (void)normalMethod;\n" |
| 177 | + "- (instancetype)init NS_UNAVAILABLE;\n" |
| 178 | + "- (void)anotherMethod;" |
| 179 | + ) |
| 180 | + result = strip_ns_unavailable(content) |
| 181 | + self.assertEqual(result, "- (void)normalMethod;\n\n- (void)anotherMethod;") |
| 182 | + |
| 183 | + def test_strips_multiple_unavailable_methods(self): |
| 184 | + content = ( |
| 185 | + "- (instancetype)init NS_UNAVAILABLE;\n+ (instancetype)new NS_UNAVAILABLE;" |
| 186 | + ) |
| 187 | + result = strip_ns_unavailable(content) |
| 188 | + self.assertEqual(result, "\n") |
| 189 | + |
| 190 | + def test_handles_empty_content(self): |
| 191 | + result = strip_ns_unavailable("") |
| 192 | + self.assertEqual(result, "") |
| 193 | + |
| 194 | + def test_preserves_line_count(self): |
| 195 | + content = ( |
| 196 | + "@interface RCTHost : NSObject\n" |
| 197 | + "- (instancetype)init NS_UNAVAILABLE;\n" |
| 198 | + "+ (instancetype)new NS_UNAVAILABLE;\n" |
| 199 | + "- (void)start;\n" |
| 200 | + "@end" |
| 201 | + ) |
| 202 | + result = strip_ns_unavailable(content) |
| 203 | + self.assertEqual(result.count("\n"), content.count("\n")) |
| 204 | + |
| 205 | + def test_handles_leading_whitespace(self): |
| 206 | + content = " - (instancetype)init NS_UNAVAILABLE;" |
| 207 | + result = strip_ns_unavailable(content) |
| 208 | + self.assertEqual(result, "") |
| 209 | + |
| 210 | + |
119 | 211 | if __name__ == "__main__": |
120 | 212 | unittest.main() |
0 commit comments