Skip to content

Commit f927935

Browse files
authored
Merge pull request #777 from prettier-solidity/null-node-printer
Adding test for null node in printer
2 parents d7f1529 + e5c7c0d commit f927935

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.c8rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"check-coverage": true,
33
"branches": 99,
4-
"lines": 99,
4+
"lines": 100,
55
"functions": 100,
6-
"statements": 99,
6+
"statements": 100,
77
"exclude": ["/node_modules/", "/scripts/", "/src/prettier-comments/"],
88
"include": ["src/**/*.js", "!src/prettier-comments/**/*.js"],
99
"reporter": ["lcov", "text"],

tests/unit/binary-operation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const genericPrint = require('../../src/printer');
22

3-
test('given an unknown module type then genericPrint function should throw', () => {
3+
test('given an unknown operator then the BinaryOperation print function should throw', () => {
44
const mockPath = {
55
getValue: () => ({ type: 'BinaryOperation', operator: '?' })
66
};

tests/unit/printer.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ test('given an unknown module type then genericPrint function should throw', ()
88
genericPrint(mockPath);
99
}).toThrow(`Unknown type: ${JSON.stringify(node.type)}`);
1010
});
11+
12+
test('if the AST contains a null node, print an empty string', () => {
13+
// Prettier V3 avoids returning null when traversing the AST, but V2 does not.
14+
// By mocking this, we ensure both cases are covered.
15+
const mockPath = { getValue: () => null };
16+
17+
expect(genericPrint(mockPath)).toEqual('');
18+
});

0 commit comments

Comments
 (0)