Skip to content

Commit 9b4df9a

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add missing test cases for processBoxShadow parseLength edge cases (facebook#55715)
Summary: Changelog: [Internal] Add tests covering previously untested branches in the parseLength regex and processBoxShadow logic Reviewed By: jorge-cab Differential Revision: D94087958
1 parent bd4eee2 commit 9b4df9a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,36 @@ describe('processBoxShadow', () => {
213213
expect(processBoxShadow('red 10foo 5px 2px 3px,')).toEqual([]);
214214
});
215215

216+
it('should fail to parse decimal number with invalid unit', () => {
217+
expect(processBoxShadow('1.5dog 2px')).toEqual([]);
218+
});
219+
216220
it('should fail to parse invalid argument', () => {
217221
expect(processBoxShadow('red asf 5px 2px 3px')).toEqual([]);
218222
});
219223

224+
it('should parse string with leading dot decimal', () => {
225+
expect(processBoxShadow('.5px 2px')).toEqual([
226+
{
227+
offsetX: 0.5,
228+
offsetY: 2,
229+
},
230+
]);
231+
});
232+
233+
it('should parse string with explicit positive sign', () => {
234+
expect(processBoxShadow('+5px 2px')).toEqual([
235+
{
236+
offsetX: 5,
237+
offsetY: 2,
238+
},
239+
]);
240+
});
241+
242+
it('should fail to parse trailing dot without fractional digits', () => {
243+
expect(processBoxShadow('10.px 5px')).toEqual([]);
244+
});
245+
220246
it('should fail to parse negative blur', () => {
221247
expect(processBoxShadow('red 5px 2px -3px')).toEqual([]);
222248
});
@@ -306,4 +332,15 @@ describe('processBoxShadow', () => {
306332
]),
307333
).toEqual([]);
308334
});
335+
336+
it('should fail to parse object with unitless non-zero string', () => {
337+
expect(
338+
processBoxShadow([
339+
{
340+
offsetX: '5',
341+
offsetY: 10,
342+
},
343+
]),
344+
).toEqual([]);
345+
});
309346
});

0 commit comments

Comments
 (0)