Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/matchcode_toolkit/stemming.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def get_stem_code(location):

# Apply mutations bottom-up
mutations = dict(sorted(mutations.items(), reverse=True))
text = source.decode()
# Ensure the text always ends with a newline character.
text = source.decode().rstrip("\n") + "\n"
cur_count = 0
lines = text.splitlines(keepends=True)
successive_line_count = [cur_count := cur_count + len(line) for line in lines]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_stemming.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ def test_rust_code_stemming(self):
expected_file_location = self.test_data_dir / "rust/metrics-stemmeds.rs"
results = stemming.get_stem_code(location=str(file_location))
check_against_expected_code_file(results, expected_file_location)

def test_javascript_code_stemming_endwith_no_newline(self):
file_location = self.test_data_dir / "javascript/main.js"
expected_file_location = self.test_data_dir / "javascript/main-stemmed.js"
results = stemming.get_stem_code(location=str(file_location))
check_against_expected_code_file(results, expected_file_location)
2 changes: 2 additions & 0 deletions tests/testfiles/stemming/javascript/main-stemmed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testfiles/stemming/javascript/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.