From de4bdae2de74ebedbba8b539668269d5a09f50ba Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 30 Aug 2024 18:12:58 -0700 Subject: [PATCH] test: add TSX file support and corresponding test --- tests/basic/test_repomap.py | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/basic/test_repomap.py b/tests/basic/test_repomap.py index 11f644f0f..8734786e5 100644 --- a/tests/basic/test_repomap.py +++ b/tests/basic/test_repomap.py @@ -332,6 +332,40 @@ export function myFunction(input: number): number { # close the open cache files, so Windows won't error del repo_map + def test_get_repo_map_tsx(self): + # Create a temporary directory with a sample TSX file + test_file_tsx = "test_file.tsx" + file_content_tsx = """\ +import React from 'react'; + +interface GreetingProps { + name: string; +} + +const Greeting: React.FC = ({ name }) => { + return

Hello, {name}!

; +}; + +export default Greeting; +""" + + with IgnorantTemporaryDirectory() as temp_dir: + with open(os.path.join(temp_dir, test_file_tsx), "w") as f: + f.write(file_content_tsx) + + io = InputOutput() + repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io) + other_files = [os.path.join(temp_dir, test_file_tsx)] + result = repo_map.get_repo_map([], other_files) + + # Check if the result contains the expected tags map with TSX identifiers + self.assertIn("test_file.tsx", result) + self.assertIn("GreetingProps", result) + self.assertIn("Greeting", result) + + # close the open cache files, so Windows won't error + del repo_map + class TestRepoMapAllLanguages(unittest.TestCase): def setUp(self): @@ -406,6 +440,10 @@ class TestRepoMapAllLanguages(unittest.TestCase): "test.ts", "function greet(name: string): void {\n console.log(`Hello, ${name}!`);\n}\n", ), + "tsx": ( + "test.tsx", + "import React from 'react';\n\nconst Greeting: React.FC<{ name: string }> = ({ name }) => {\n return

Hello, {name}!

;\n};\n\nexport default Greeting;\n", + ), } with IgnorantTemporaryDirectory() as temp_dir: