Skip to content

Commit a648bba

Browse files
committed
ed script tests pass
1 parent 8e66efb commit a648bba

File tree

15 files changed

+133
-40
lines changed

15 files changed

+133
-40
lines changed

src/cedarscript_editor/cedarscript_editor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,13 @@ def _apply_action(
200200

201201
case ReplaceClause() | InsertClause():
202202
match content:
203-
case (region, processed_content):
204-
content = processed_content
205203
case str():
206204
content = IndentationInfo.from_content(lines).apply_relative_indents(
207205
content, range_spec.indent
208206
)
207+
case Sequence():
208+
content = [line.rstrip() for line in content]
209+
209210

210211
range_spec.write(content, lines)
211212

src/cedarscript_editor/ed_script_filter.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ def process_ed_script(content: Sequence[str], ed_script: str) -> list[str]:
1717
Raises:
1818
RuntimeError: If ed command fails
1919
"""
20-
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt') as content_file, \
21-
tempfile.NamedTemporaryFile(mode='w', suffix='.ed') as script_file:
20+
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt') as content_file:
2221

2322
# Write content and script to temp files
2423
content_file.write('\n'.join(content))
2524
content_file.flush()
2625

27-
script_file.write(ed_script)
28-
script_file.flush()
29-
3026
# Run ed
27+
ed_script = ed_script.strip()
28+
# 'H' to Enable verbose errors
29+
match ed_script:
30+
case '':
31+
ed_script = 'H\nw\nq'
32+
case _:
33+
ed_script = f'H\n{ed_script}\nw\nq'
3134
process = subprocess.run(
3235
['ed', content_file.name],
33-
input=f'H\n', # Enable verbose errors
34-
stdin=open(script_file.name),
36+
input=ed_script,
3537
capture_output=True,
3638
text=True
3739
)

tests/corpus/.update.identifier.ed-script-filter/1.py

-6
This file was deleted.

tests/corpus/.update.identifier.ed-script-filter/chat.xml

-13
This file was deleted.

tests/corpus/.update.identifier.ed-script-filter/expected.1.py

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
class BaseConverter:
2-
def encode(self, i):
3-
neg, value = self.convert(i, self.decimal_digits, self.digits, "-")
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (self.convert(i, self.decimal_digits, self.digits, "-"))
45
def decode(self, s):
56
neg, value = self.convert(s, self.digits, self.decimal_digits, self.sign)
7+
def xx(self, number, from_digits, to_digits, sign):
8+
def convert(self, number, from_digits, to_digits, sign):
69
def convert(self, number, from_digits, to_digits, sign):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BaseConverter:
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (self.convert(i, self.decimal_digits, self.digits, "-"))
5+
def decode(self, s):
6+
neg, value = self.convert(s, self.digits, self.decimal_digits, self.sign)
7+
def convert(self, number, from_digits, to_digits, sign):
8+
b = def convert(self, number, from_digits, to_digits, sign):
9+
def a():
10+
def convert(self, number, from_digits, to_digits, sign):

tests/corpus/update.identifier.case-filter/chat.xml

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<no-train>
22
```CEDARScript
3-
UPDATE FILE "1.py"
3+
UPDATE FILE "1.txt"
44
REPLACE WHOLE WITH CASE
55
WHEN PREFIX 'def convert(' THEN SUB
6-
r'(def convert\()self, '
6+
r'self, '
7+
r''
8+
WHEN REGEX r'self\.convert' THEN SUB
9+
r'self\.(convert)'
710
r'\1'
11+
END;
12+
13+
UPDATE FILE "1.py"
14+
REPLACE WHOLE WITH CASE
15+
WHEN PREFIX 'def convert(' THEN SUB
16+
r'self, '
17+
r''
818
WHEN REGEX r'self\.convert' THEN SUB
919
r'self\.(convert)'
1020
r'\1'
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
class BaseConverter:
2-
def encode(self, i):
3-
neg, value = convert(i, self.decimal_digits, self.digits, "-")
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (convert(i, self.decimal_digits, self.digits, "-"))
45
def decode(self, s):
56
neg, value = convert(s, self.digits, self.decimal_digits, self.sign)
7+
def xx(self, number, from_digits, to_digits, sign):
8+
def convert(number, from_digits, to_digits, sign):
69
def convert(number, from_digits, to_digits, sign):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BaseConverter:
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (convert(i, self.decimal_digits, self.digits, "-"))
5+
def decode(self, s):
6+
neg, value = convert(s, self.digits, self.decimal_digits, self.sign)
7+
def convert(number, from_digits, to_digits, sign):
8+
b = def convert(self, number, from_digits, to_digits, sign):
9+
def a():
10+
def convert(number, from_digits, to_digits, sign):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def calc1(a):
2+
return a * 7.0
3+
def calc2(a):
4+
c = ["x", str(calc1(
5+
5), "xx")]
6+
c = ["x", str(calc1(
7+
6), "xx")]
8+
c = ["x", str(calc1(#...
9+
6), "xx")]
10+
# Done...
11+
return c
12+
def calc3(a):
13+
return calc1(a)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BaseConverter:
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (self.convert(i, self.decimal_digits, self.digits, "-"))
5+
def decode(self, s):
6+
neg, value = self.convert(s, self.digits, self.decimal_digits, self.sign)
7+
def convert(self, number, from_digits, to_digits, sign):
8+
b = def convert(self, number, from_digits, to_digits, sign):
9+
def a():
10+
def convert(self, number, from_digits, to_digits, sign):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<no-train>
2+
```CEDARScript
3+
UPDATE FILE "1.txt"
4+
REPLACE WHOLE WITH ED r'''
5+
6+
g/self\.convert/s/self\.\(convert\)/\1/g
7+
g/^def convert/s/self, //
8+
9+
''';
10+
11+
-- 1. Update the function signature of `calc1()` to add parameter `tax: float` as the first one and use the new parameter instead of `7`
12+
UPDATE FUNCTION "calc1"
13+
FROM FILE "1.py"
14+
REPLACE WHOLE WITH ED r'''
15+
16+
g/def calc1/s/(/(tax: float, /
17+
g/return/s/7.*/tax/
18+
19+
''';
20+
21+
-- 2. Update the function signature of `calc2()` to add parameter `base_tax: float = 1.3` as the last one
22+
-- 3. Update ALL call sites of `calc1()` to pass `base_tax` as the first argument
23+
UPDATE FUNCTION "calc2"
24+
FROM FILE "1.py"
25+
REPLACE WHOLE WITH ED r'''
26+
27+
g/def calc2/s/)/, base_tax: float = 1.3)/
28+
g/calc1(/s/\(calc1(\)/\1base_tax, /
29+
30+
''';
31+
32+
```
33+
</no-train>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def calc1(tax: float, a):
2+
return a * tax
3+
def calc2(a, base_tax: float = 1.3):
4+
c = ["x", str(calc1(base_tax,
5+
5), "xx")]
6+
c = ["x", str(calc1(base_tax,
7+
6), "xx")]
8+
c = ["x", str(calc1(base_tax, #...
9+
6), "xx")]
10+
# Done...
11+
return c
12+
def calc3(a):
13+
return calc1(a)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BaseConverter:
2+
def __init(self, s):
3+
def encode(self, i):
4+
neg, value = (convert(i, self.decimal_digits, self.digits, "-"))
5+
def decode(self, s):
6+
neg, value = convert(s, self.digits, self.decimal_digits, self.sign)
7+
def convert(number, from_digits, to_digits, sign):
8+
b = def convert(self, number, from_digits, to_digits, sign):
9+
def a():
10+
def convert(number, from_digits, to_digits, sign):

0 commit comments

Comments
 (0)