Skip to content

Commit

Permalink
Merge pull request #777 from prettier-solidity/null-node-printer
Browse files Browse the repository at this point in the history
Adding test for null node in printer
  • Loading branch information
fvictorio authored Dec 23, 2022
2 parents d7f1529 + e5c7c0d commit f927935
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"check-coverage": true,
"branches": 99,
"lines": 99,
"lines": 100,
"functions": 100,
"statements": 99,
"statements": 100,
"exclude": ["/node_modules/", "/scripts/", "/src/prettier-comments/"],
"include": ["src/**/*.js", "!src/prettier-comments/**/*.js"],
"reporter": ["lcov", "text"],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/binary-operation.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const genericPrint = require('../../src/printer');

test('given an unknown module type then genericPrint function should throw', () => {
test('given an unknown operator then the BinaryOperation print function should throw', () => {
const mockPath = {
getValue: () => ({ type: 'BinaryOperation', operator: '?' })
};
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/printer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ test('given an unknown module type then genericPrint function should throw', ()
genericPrint(mockPath);
}).toThrow(`Unknown type: ${JSON.stringify(node.type)}`);
});

test('if the AST contains a null node, print an empty string', () => {
// Prettier V3 avoids returning null when traversing the AST, but V2 does not.
// By mocking this, we ensure both cases are covered.
const mockPath = { getValue: () => null };

expect(genericPrint(mockPath)).toEqual('');
});

0 comments on commit f927935

Please sign in to comment.