Repository: ccxt/ccxt
File: build/goTranspiler.ts (TypeScript)

Code before:
    }

    transpileBaseTests (outDir) {

        const baseFolders = {
            ts: './ts/src/test/base/',
        };

        let baseFunctionTests = fs.readdirSync (baseFolders.ts).filter(filename => filename.endsWith('.ts')).map(filename => filename.replace('.ts', ''));

        for (const testName of baseFunctionTests) {
            const tsFile = baseFolders.ts + testName + '.ts';
            const tsContent = fs.readFileSync(tsFile).toString();
            if (!tsContent.includes ('// AUTO_TRANSPILE_ENABLED')) {
                continue;
            }

            // const goFileName = this.capitalize(testName.replace ('test.', ''));
            const goFile = `${outDir}/${testName}.go`;

            log.magenta ('Transpiling from', (tsFile as any).yellow)

            const go = this.transpiler.transpileGoByPath(tsFile);
            let content = go.content;
            content = this.regexAll (content, [
                [/(\w+) := new ccxt\.Exchange\(([\S\s]+?)\)/gm, '$1 := ccxt.NewExchange().(*ccxt.Exchange); $1.InitParent($2, map[string]interface{}{}, $1)' ],
                [/exchange interface\{\}, /g,'exchange *ccxt.Exchange, '], // in arguments
                [/ interface\{\}(?= \= map\[string\]interface\{\} )/g, ' map[string]interface{}'], // fix incorrect variable type
                [ /interface{}\sfunc\sEquals.+\n.*\n.+\n.+/gm, '' ], // remove equals
                [/Precise\.String/gm, 'ccxt.Precise.String'],
                [ /testSharedMethods.AssertDeepEqual/gm, 'AssertDeepEqual' ], // deepEqual added
                [ /func Equals\(.+\n.*\n.*\n.*\}/gm, '' ], // remove equals
                [ /Assert\("GO_SKIP_START"\)[\S\s]+?Assert\("GO_SKIP_END"\)/gm, '' ], // remove equals

            ]).trim ()

            const file = [
                'package base',
                testName.indexOf('tests.init') === -1 ? 'import "github.com/ccxt/ccxt/go/v4"' : '',
                '',
                this.createGeneratedHeader().join('\n'),
                content,
            ].join('\n')

            log.magenta ('→', (goFile as any).yellow)

            goTests.push(this.capitalize(testName));
            overwriteFileAndFolder (goFile, file);
        }
    }


Review comment (suggestion):
 in `GO`, when we instantiate "base exchange" in tests, we need to set `.DerivedExchange` too, otherwise `this.DerivedExchange` is nil, causing breaks in base methods

Code after:
    }

    transpileBaseTests (outDir) {

        const baseFolders = {
            ts: './ts/src/test/base/',
        };

        let baseFunctionTests = fs.readdirSync (baseFolders.ts).filter(filename => filename.endsWith('.ts')).map(filename => filename.replace('.ts', ''));

        for (const testName of baseFunctionTests) {
            const tsFile = baseFolders.ts + testName + '.ts';
            const tsContent = fs.readFileSync(tsFile).toString();
            if (!tsContent.includes ('// AUTO_TRANSPILE_ENABLED')) {
                continue;
            }

            // const goFileName = this.capitalize(testName.replace ('test.', ''));
            const goFile = `${outDir}/${testName}.go`;

            log.magenta ('Transpiling from', (tsFile as any).yellow)

            const go = this.transpiler.transpileGoByPath(tsFile);
            let content = go.content;
            content = this.regexAll (content, [
                [/(\w+) := new ccxt\.Exchange\(([\S\s]+?)\)/gm, '$1 := ccxt.NewExchange().(*ccxt.Exchange); $1.DerivedExchange = $1; $1.InitParent($2, map[string]interface{}{}, $1)' ],
                [/exchange interface\{\}, /g,'exchange *ccxt.Exchange, '], // in arguments
                [/ interface\{\}(?= \= map\[string\]interface\{\} )/g, ' map[string]interface{}'], // fix incorrect variable type
                [ /interface{}\sfunc\sEquals.+\n.*\n.+\n.+/gm, '' ], // remove equals
                [/Precise\.String/gm, 'ccxt.Precise.String'],
                [ /testSharedMethods.AssertDeepEqual/gm, 'AssertDeepEqual' ], // deepEqual added
                [ /func Equals\(.+\n.*\n.*\n.*\}/gm, '' ], // remove equals
                [ /Assert\("GO_SKIP_START"\)[\S\s]+?Assert\("GO_SKIP_END"\)/gm, '' ], // remove equals

            ]).trim ()

            const file = [
                'package base',
                testName.indexOf('tests.init') === -1 ? 'import "github.com/ccxt/ccxt/go/v4"' : '',
                '',
                this.createGeneratedHeader().join('\n'),
                content,
            ].join('\n')

            log.magenta ('→', (goFile as any).yellow)

            goTests.push(this.capitalize(testName));
            overwriteFileAndFolder (goFile, file);
        }
    }