From e105bb9090da77541cb228ab0707ce4a9bbe8eda Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Wed, 22 Nov 2023 10:46:11 +0800 Subject: [PATCH] ++ --- .../cxx_parser.integration.test.ts | 96 ++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/cxx-parser/__integration_test__/cxx_parser.integration.test.ts b/cxx-parser/__integration_test__/cxx_parser.integration.test.ts index 7956431..3e32897 100644 --- a/cxx-parser/__integration_test__/cxx_parser.integration.test.ts +++ b/cxx-parser/__integration_test__/cxx_parser.integration.test.ts @@ -264,7 +264,6 @@ describe('cxx_parser', () => { { "__TYPE":"Enumz", "attributes":[], - "base_clazzs":[], "comment":"", "enum_constants": [ { @@ -326,7 +325,6 @@ describe('cxx_parser', () => { { "__TYPE":"Enumz", "attributes":[], - "base_clazzs":[], "comment":"", "enum_constants": [ { @@ -419,6 +417,100 @@ describe('cxx_parser', () => { // Use `JSON.parse` to parse the json string to avoid the format issue expect(JSON.parse(json)).toEqual(JSON.parse(expectedJson)); }); + + it('normal typedef void* under typedef struct', () => { + let file1Path = path.join(tmpDir, 'file1.h'); + + fs.writeFileSync( + file1Path, + ` + struct AAA { + int a; + }; + + typedef void* view_t; + ` + ); + + let checkSum = generateChecksum([file1Path]); + let preProcessParseFilesDir = path.join( + cxxParserCacheDir, + `preProcess@${checkSum}` + ); + + // TODO(littlegnal): Should move the tmp/*.h to the build dir in the future + const expectedJson = ` + [ + { + "__TYPE":"CXXFile", + "file_path":"${preProcessParseFilesDir}/file1.h", + "nodes":[ + { + "__TYPE":"Struct", + "attributes":[], + "base_clazzs":[], + "comment":"", + "constructors":[], + "file_path":"${preProcessParseFilesDir}/file1.h", + "member_variables":[ + { + "__TYPE":"MemberVariable", + "access_specifier":"", + "is_mutable":false, + "name":"a", + "type":{ + "__TYPE":"SimpleType", + "is_builtin_type":true, + "is_const":false, + "kind":100, + "name":"int", + "source":"int", + "template_arguments":[] + } + } + ], + "methods":[], + "name":"AAA", + "namespaces":[], + "parent_name":"${preProcessParseFilesDir}/file1.h", + "source":"" + }, + { + "__TYPE": "TypeAlias", + "attributes": [], + "comment": "", + "file_path":"${preProcessParseFilesDir}/file1.h", + "name": "view_t", + "namespaces": [], + "parent_name":"${preProcessParseFilesDir}/file1.h", + "source": "", + "underlyingType": { + "__TYPE": "SimpleType", + "is_builtin_type": true, + "is_const": false, + "kind": 101, + "name": "void", + "source": "void*", + "template_arguments": [] + } + } + ] + } + ] + `; + + let json = dumpCXXAstJson( + new TerraContext(tmpDir), + [], + [file1Path], + [] + ); + + expect(fs.existsSync(preProcessParseFilesDir)).toBe(true); + + // Use `JSON.parse` to parse the json string to avoid the format issue + expect(JSON.parse(json)).toEqual(JSON.parse(expectedJson)); + }); }); });