Skip to content

Commit

Permalink
fix: PR
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Apr 29, 2024
1 parent c6de925 commit 597bd26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ greeter.set__greeting('Hola');
- Please, note that if you want to mock `internal` functions, you **must** make them `virtual`. The tool will not generate mocks for internal functions that are not virtual.
- Cannot set `private` variables and mock `private` functions.
- Mocking of structs containing mappings is not supported.
- Mocking of multi-dimensional struct arrays is not supported.
- Mocking of multi-dimensional arrays of structs is not supported.

# Licensing

Expand Down
19 changes: 9 additions & 10 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,24 @@ export function arrayVariableContext(node: VariableDeclaration): ArrayVariableCo
// Array type
const arrayType: string = sanitizeParameterType(explicitTypeStorageLocation(node.typeString));

// Base type
let baseType: string = sanitizeParameterType(explicitTypeStorageLocation(node.vType['vBaseType'].typeString));

// Struct flag
const isStructArray: boolean = node.typeString.startsWith('struct ');

// Check if the variable is a struct and get its fields
const structFields = extractStructFieldsNames(node.vType);

// If the array is internal we don't create mockCall for it
const isInternal: boolean = node.visibility === 'internal';

// Check if the array is multi-dimensional
const dimensionsQuantity = node.typeString.split('[]').length - 1;
const isMultiDimensional = dimensionsQuantity > 1;
const isMultiDimensionalStruct = isMultiDimensional && isStructArray;
const dimensions = [...Array(dimensionsQuantity).keys()];

if (isMultiDimensional) baseType = explicitTypeStorageLocation(node.typeString.replace(/\[\]/g, ''));
// Base type
const baseTypeString = isMultiDimensional ? node.typeString.replace(/\[\]/g, '') : node.vType['vBaseType'].typeString;
const baseType = sanitizeParameterType(explicitTypeStorageLocation(baseTypeString));

// Check if the variable is a struct and get its fields
const structFields = extractStructFieldsNames(node.vType);

// If the array is internal we don't create mockCall for it
const isInternal: boolean = node.visibility === 'internal';

return {
setFunction: {
Expand Down

0 comments on commit 597bd26

Please sign in to comment.