Skip to content

Commit 0777c19

Browse files
Harshit2405-2004ggazzo
authored andcommitted
test(message-parser): replace boolean with pass counter and clean up comments
1 parent 9774929 commit 0777c19

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

packages/message-parser/tests/fuzz.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,29 @@ import { parse } from '../src/index';
33

44
describe('Message Parser Property-Based Fuzz Testing', () => {
55
it('should return a valid array of ASTNodes for any arbitrary string', () => {
6-
let hasSuccessfulParse = false;
6+
let successfulParses = 0;
77
fc.assert(
88
fc.property(fc.string({ maxLength: 500 }), (text) => {
99
try {
1010
const ast = parse(text);
1111
expect(Array.isArray(ast)).toBe(true);
12-
// For any payload, if it's an array, it should be an array of nodes containing a "type"
1312
ast.forEach((val: unknown) => {
1413
expect(val).toMatchObject({ type: expect.any(String) });
1514
});
16-
hasSuccessfulParse = true;
15+
successfulParses++;
1716
} catch (error) {
1817
if (!(error instanceof Error && error.name === 'SyntaxError')) {
1918
throw error;
2019
}
21-
// Intentionally ignore SyntaxError during fuzzing
2220
}
2321
}),
24-
{ numRuns: 1000 } // Execute 1000 random string checks
22+
{ numRuns: 1000 }
2523
);
26-
expect(hasSuccessfulParse).toBe(true);
24+
expect(successfulParses).toBeGreaterThan(0);
2725
});
2826

2927
it('should guarantee structural integrity for deeply nested markdown', () => {
30-
let hasSuccessfulParse = false;
31-
// Valid sequences that generate various inline tokens
28+
let successfulParses = 0;
3229
const sequences = ['*', '_', '~', '`', '# ', '## ', '> ', 'http://', 'https://', ' [', '](', ':', '!)', '\n'];
3330

3431
fc.assert(
@@ -45,24 +42,21 @@ describe('Message Parser Property-Based Fuzz Testing', () => {
4542
try {
4643
const ast = parse(text);
4744

48-
// Verify that any Paragraph node contains valid Elements
4945
ast.forEach((val: unknown) => {
5046
if (typeof val === 'object' && val !== null && 'type' in val && val.type === 'PARAGRAPH') {
5147
expect(val).toMatchObject({ value: expect.any(Array) });
5248
}
5349
});
54-
hasSuccessfulParse = true;
50+
successfulParses++;
5551
} catch (e) {
5652
if (!(e instanceof Error && e.name === 'SyntaxError')) {
5753
throw e;
5854
}
59-
// Intentionally ignore SyntaxError during fuzzing
6055
}
6156
}
6257
),
6358
{ numRuns: 1000 }
6459
);
65-
expect(hasSuccessfulParse).toBe(true);
60+
expect(successfulParses).toBeGreaterThan(0);
6661
});
6762
});
68-

0 commit comments

Comments
 (0)