Skip to content

Commit

Permalink
test(manipurator): Add test for python f-string, multi-line string li…
Browse files Browse the repository at this point in the history
…teral
  • Loading branch information
yamadashy committed Aug 25, 2024
1 parent dc64d22 commit c2505c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/core/file/fileManipulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class StripCommentsManipulator extends BaseManipulator {

class PythonManipulator extends BaseManipulator {
removeComments(content: string): string {

// Remove single-line comments
let result = content.replace(/(?<!\\)#.*$/gm, '');

Expand All @@ -49,7 +48,10 @@ class PythonManipulator extends BaseManipulator {
}

private rtrimLines(content: string): string {
return content.split('\n').map(line => line.trimEnd()).join('\n');
return content
.split('\n')
.map((line) => line.trimEnd())
.join('\n');
}
}

Expand Down
53 changes: 46 additions & 7 deletions tests/core/file/fileManipulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('fileManipulator', () => {
`,
},
{
name: 'Python comment removal',
name: 'Python comment, docstring removal',
ext: '.py',
input: `
# Single line comment
Expand All @@ -166,13 +166,52 @@ describe('fileManipulator', () => {
expected: `
def test():
'''
docstring
'''
return True
`,
},
{
name: 'Python comment f-string is not removed',
ext: '.py',
input: `
# Single line comment
def test():
f'f-string'
f"""
f-string
"""
return True
`,
expected: `
def test():
f'f-string'
f"""
f-string
"""
return True
`,
},
{
name: 'Python comment multi-line string literal is not removed',
ext: '.py',
input: `
def test():
hoge = """
multi-line
string
"""
return True
`,
expected: `
def test():
hoge = """
multi-line
string
"""
return True
"""
Another docstring
"""
`,
},
{
Expand Down

0 comments on commit c2505c9

Please sign in to comment.