forked from Crowdfunding-DApp/stellar-raise-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_duplicates.py
More file actions
51 lines (44 loc) · 1.52 KB
/
remove_duplicates.py
File metadata and controls
51 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import re
# Read the file
with open('contracts/crowdfund/src/test.rs', 'r') as f:
lines = f.readlines()
# Track seen test functions
seen_tests = set()
output_lines = []
skip_until = -1
i = 0
while i < len(lines):
line = lines[i]
# Check if this is a test function definition
if i > skip_until:
match = re.match(r'^fn (test_\w+)\(\)', line)
if match:
test_name = match.group(1)
if test_name in seen_tests:
# This is a duplicate, skip until we find the next function or test
print(f"Removing duplicate: {test_name} at line {i+1}")
# Find the end of this function (next 'fn ' or end of file)
j = i + 1
brace_count = 0
found_opening = False
while j < len(lines):
if '{' in lines[j]:
brace_count += lines[j].count('{')
found_opening = True
if '}' in lines[j]:
brace_count -= lines[j].count('}')
if found_opening and brace_count == 0:
skip_until = j
break
j += 1
i += 1
continue
else:
seen_tests.add(test_name)
output_lines.append(line)
i += 1
# Write back
with open('contracts/crowdfund/src/test.rs', 'w') as f:
f.writelines(output_lines)
print(f"Kept {len(seen_tests)} unique tests")