better automated reformat tests
This commit is contained in:
parent
40fbd38712
commit
dfe42d8d23
14
Makefile
14
Makefile
|
@ -17,6 +17,7 @@ help: build
|
||||||
test:
|
test:
|
||||||
reset
|
reset
|
||||||
make goimports vet build
|
make goimports vet build
|
||||||
|
git checkout example/fruit.proto
|
||||||
make -C example testGlobal
|
make -C example testGlobal
|
||||||
make -C example testProtoc
|
make -C example testProtoc
|
||||||
make -C example all
|
make -C example all
|
||||||
|
@ -92,12 +93,19 @@ clean-more:
|
||||||
ls -l autogenpb autogenpb.last
|
ls -l autogenpb autogenpb.last
|
||||||
-rm -f autogenpb.2*
|
-rm -f autogenpb.2*
|
||||||
|
|
||||||
reformat-signal.proto-comments:
|
reformat-signal.proto-reset:
|
||||||
|
git checkout example/*.proto
|
||||||
|
|
||||||
|
reformat-signal.proto-comments: goimports vet build
|
||||||
git checkout example/fruit.proto
|
git checkout example/fruit.proto
|
||||||
make -C example proto-reformat-restore
|
make -C example proto-reformat-restore
|
||||||
make -C example proto-reformat-comments
|
make -C example proto-reformat-comments
|
||||||
|
|
||||||
reformat-signal.proto-full:
|
reformat-signal.proto-full: goimports vet build
|
||||||
git checkout example/fruit.proto
|
git checkout example/*.proto
|
||||||
make -C example proto-reformat-restore
|
make -C example proto-reformat-restore
|
||||||
make -C example proto-reformat-full
|
make -C example proto-reformat-full
|
||||||
|
|
||||||
|
reformat-signal.proto-fruit: goimports vet build
|
||||||
|
git checkout example/*.proto
|
||||||
|
make -C example proto-reformat-fruit
|
||||||
|
|
|
@ -111,3 +111,6 @@ proto-reformat-comments:
|
||||||
|
|
||||||
proto-reformat-full:
|
proto-reformat-full:
|
||||||
autogenpb --proto signal.proto --format
|
autogenpb --proto signal.proto --format
|
||||||
|
|
||||||
|
proto-reformat-fruit:
|
||||||
|
autogenpb --proto fruit.proto --format
|
||||||
|
|
|
@ -76,12 +76,12 @@ func protoReformat(filename string) error {
|
||||||
|
|
||||||
var newfile string
|
var newfile string
|
||||||
|
|
||||||
var fmtmsg *FormatMsg
|
|
||||||
fmtmsg = new(FormatMsg)
|
|
||||||
|
|
||||||
var bigName int64
|
var bigName int64
|
||||||
var bigType int64
|
var bigType int64
|
||||||
|
|
||||||
|
var fmtmsg *FormatMsg
|
||||||
|
fmtmsg = new(FormatMsg)
|
||||||
|
|
||||||
var inMessage bool
|
var inMessage bool
|
||||||
var allLinesIter iter.Seq[string]
|
var allLinesIter iter.Seq[string]
|
||||||
allLinesIter = makeLineIter(data)
|
allLinesIter = makeLineIter(data)
|
||||||
|
@ -110,10 +110,15 @@ func protoReformat(filename string) error {
|
||||||
if !inMessage {
|
if !inMessage {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
|
||||||
}
|
}
|
||||||
fmtmsg.MaxVarname = bigName
|
|
||||||
fmtmsg.MaxVartype = bigType
|
var basemsg *FormatMsg
|
||||||
|
basemsg = new(FormatMsg)
|
||||||
|
basemsg.MaxVarname = bigName
|
||||||
|
basemsg.MaxVartype = bigType
|
||||||
|
inMessage = false
|
||||||
|
|
||||||
|
var comments string
|
||||||
|
|
||||||
// write out the messages
|
// write out the messages
|
||||||
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
||||||
|
@ -121,35 +126,59 @@ func protoReformat(filename string) error {
|
||||||
line := allTheLines.NextRaw()
|
line := allTheLines.NextRaw()
|
||||||
|
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := fmtmsg.newOneofMessage(line)
|
newmsg := basemsg.newOneofMessage(line)
|
||||||
|
newmsg.msgPB.Notes = strings.Split(comments, "\n")
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
for _, newline := range newmsg.msgPB.format() {
|
basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
|
||||||
newfile += fmt.Sprintln(newline)
|
/*
|
||||||
}
|
for _, newline := range newmsg.msgPB.format() {
|
||||||
|
newfile += fmt.Sprintln(newline)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
inMessage = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := fmtmsg.newEnumMessage(line)
|
newmsg := basemsg.newEnumMessage(line)
|
||||||
|
newmsg.msgPB.Notes = strings.Split(comments, "\n")
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
|
||||||
// loadEnumDefinition(newmsg)
|
// loadEnumDefinition(newmsg)
|
||||||
for _, newline := range newmsg.msgPB.format() {
|
/*
|
||||||
newfile += fmt.Sprintln(newline)
|
for _, newline := range newmsg.msgPB.format() {
|
||||||
}
|
newfile += fmt.Sprintln(newline)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
inMessage = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "message ") {
|
if strings.HasPrefix(line, "message ") {
|
||||||
newmsg := fmtmsg.newStdMessage(line)
|
|
||||||
newmsg.load()
|
|
||||||
log.Info("got to message", line)
|
log.Info("got to message", line)
|
||||||
for _, newline := range newmsg.msgPB.format() {
|
|
||||||
newfile += fmt.Sprintln(newline)
|
newmsg := basemsg.newStdMessage(line)
|
||||||
}
|
newmsg.msgPB.Notes = strings.Split(comments, "\n")
|
||||||
|
newmsg.load()
|
||||||
|
basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
|
||||||
|
/*
|
||||||
|
for _, newline := range newmsg.msgPB.format() {
|
||||||
|
newfile += fmt.Sprintln(newline)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
inMessage = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
newfile += fmt.Sprintln(line)
|
if inMessage {
|
||||||
|
comments += fmt.Sprintln(line)
|
||||||
|
} else {
|
||||||
|
basemsg.Notes = append(basemsg.Notes, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, newline := range basemsg.format() {
|
||||||
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveFile(filename, newfile)
|
return saveFile(filename, newfile)
|
||||||
|
@ -375,6 +404,11 @@ func (msg *FormatMsg) format() []string {
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
|
|
||||||
|
// print the Notes
|
||||||
|
for _, line := range curmsg.Notes {
|
||||||
|
newmsg = append(newmsg, line)
|
||||||
|
}
|
||||||
|
|
||||||
if curmsg.Header != "" {
|
if curmsg.Header != "" {
|
||||||
line := fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
|
line := fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
|
|
Loading…
Reference in New Issue