Skip to content

Commit e13808e

Browse files
author
Randall C. O'Reilly
committed
fix for loop _, and update tests.
1 parent 2ff24e7 commit e13808e

File tree

6 files changed

+1440
-1354
lines changed

6 files changed

+1440
-1354
lines changed

gotopy.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func initParserMode() {
8080
if *allErrors {
8181
parserMode |= parser.AllErrors
8282
}
83+
if *gopyMode {
84+
printerMode |= pyprint.GoPy
85+
}
86+
87+
if *gogiMode {
88+
printerMode |= pyprint.GoGi | pyprint.GoPy
89+
}
8390
}
8491

8592
func isGoFile(f os.FileInfo) bool {
@@ -227,14 +234,6 @@ func gofmtMain() {
227234
return
228235
}
229236

230-
if *gopyMode {
231-
printerMode |= pyprint.GoPy
232-
}
233-
234-
if *gogiMode {
235-
printerMode |= pyprint.GoGi | pyprint.GoPy
236-
}
237-
238237
for i := 0; i < flag.NArg(); i++ {
239238
path := flag.Arg(i)
240239
switch dir, err := os.Stat(path); {

gotopy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func runTest(t *testing.T, in, out string) {
7979
*rewriteRule = value
8080
case "-s":
8181
*simplifyAST = true
82+
case "-gopy":
83+
*gopyMode = true
84+
case "-gogi":
85+
*gopyMode = true
86+
*gogiMode = true
8287
case "-stdin":
8388
// fake flag - pretend input is from stdin
8489
stdin = true

pyedits.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ func pyEditsReplace(lines [][]byte) {
138138
eqappend := []byte("= append(")
139139
elseif := []byte("else if")
140140
elif := []byte("elif")
141+
forblank := []byte("for _, ")
142+
fornoblank := []byte("for ")
141143
itoa := []byte("strconv.Itoa")
142144
float64p := []byte("float64(")
143145
float32p := []byte("float32(")
@@ -162,6 +164,7 @@ func pyEditsReplace(lines [][]byte) {
162164
ln = bytes.Replace(ln, float64p, floatp, -1)
163165
ln = bytes.Replace(ln, float32p, floatp, -1)
164166
ln = bytes.Replace(ln, stringp, strp, -1)
167+
ln = bytes.Replace(ln, forblank, fornoblank, -1)
165168

166169
if bytes.Contains(ln, fmtSprintf) {
167170
if bytes.Contains(ln, []byte("%")) {

testdata/basic.golden

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,56 @@ GlobBool = False
66

77
class MyStru:
88
# A struct definition
9-
def __init__(self):
10-
# field desc
11-
self.A int
12-
self.B float32 # `desc:"field tag"`
13-
self.C string # `desc:"more tags"`
14-
def MethOne(st, arg1):
15-
"""
16-
MethOne does something
17-
"""
18-
rv = st.A
19-
for _, a in SomeList :
20-
rv += a
21-
st.A = True
22-
23-
ano = MyStru(A= 22, B= 44.2, C= "happy")
24-
25-
return rv
26-
27-
def MethTwo(st, arg1, arg2, arg3):
28-
"""
29-
MethTwo does something
30-
it is pretty cool
31-
not really sure about that
32-
"""
33-
rv = st.A
34-
for a in range(100):
35-
rv += a
36-
switch rv:
37-
if 100:
38-
rv *= 2
39-
if 500:
40-
rv /= 5
41-
return rv
9+
"""
10+
A struct definition
11+
12+
# field desc
13+
"""
14+
15+
def __init__(self):
16+
self.A = int()
17+
self.B = float() # `desc:"field tag"`
18+
self.C = str() # `desc:"more tags"`
19+
20+
def MethOne(st, arg1):
21+
"""
22+
MethOne does something
23+
"""
24+
rv = st.A
25+
for a in SomeList :
26+
rv += a
27+
st.A = True
28+
29+
ano = MyStru(A= 22, B= 44.2, C= "happy")
30+
31+
return rv
32+
33+
def MethTwo(st, arg1, arg2, arg3):
34+
"""
35+
MethTwo does something
36+
it is pretty cool
37+
not really sure about that
38+
"""
39+
rv = st.A
40+
for a in range(100):
41+
rv += a
42+
switch rv:
43+
if 100:
44+
rv *= 2
45+
if 500:
46+
rv /= 5
47+
return rv
4248

4349

4450
# A global function
4551
def GlobFun(a, b):
46-
"""
47-
A global function
48-
"""
49-
if a > b and a == 0 or b == 0:
50-
return a + b
51-
else if a == b:
52-
return a * b
53-
else:
54-
return a - b
52+
"""
53+
A global function
54+
"""
55+
if a > b and a == 0 or b == 0:
56+
return a + b
57+
elif a == b:
58+
return a * b
59+
else:
60+
return a - b
5561

0 commit comments

Comments
 (0)