Have dumbindent no longer treat labels specially

This commit is contained in:
Nigel Tao committed 2020-06-06 22:38:29 +10:00
1 parent 6424bae087
commit 0ad5f9b617
3 files changed
+229 -254

No files matched your search

-25
View File
@@ -138,9 +138,6 @@ func FormatBytes(dst []byte, src []byte) []byte {
if (nParens > 0) || hanging {
indent += 4
}
if (indent >= 2) && isLabel(line) {
indent -= 2
}
for indent > 0 {
n := indent
if n > len(spaces) {
@@ -234,28 +231,6 @@ func trimTrailingWhiteSpace(s []byte) []byte {
return s
}
// isLabel returns whether s looks like "foo:" or "bar_baz:;".
func isLabel(s []byte) bool {
for (len(s) > 0) && (s[len(s)-1] == ';') {
s = s[:len(s)-1]
}
if (len(s) < 2) || (s[len(s)-1] != ':') {
return false
}
s = s[:len(s)-1]
for _, c := range s {
switch {
case ('0' <= c) && (c <= '9'):
case ('A' <= c) && (c <= 'Z'):
case ('a' <= c) && (c <= 'z'):
case c == '_':
default:
return false
}
}
return true
}
// lastNonWhiteSpace returns the 'z' in "abc xyz ". It returns '\x00' if s
// consists entirely of spaces or tabs.
func lastNonWhiteSpace(s []byte) byte {
+2 -2
View File
@@ -63,9 +63,9 @@ func TestFormatBytes(tt *testing.T) {
src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n",
want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n",
}, {
// Label.
// Nested blocks with label.
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
want: "if (b) {\nlabel:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
}}
for i, tc := range testCases {