Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names
Short and single-letter names in application code become full words (tests keep theirs). Wrapped calls, signatures and composite literals put one item per line, and one-line function bodies are expanded. Exported names and groups of constants get doc comments, and comments refer to the renamed identifiers.
This commit is contained in:
1 parent
043e307663
commit
465358609a
78 files changed
+2374
-1402
No files matched your search
@@ -119,7 +119,9 @@ func TestMapOf(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFlattenOfPrefix(t *testing.T) {
|
||||
m := flattenOf("p", testSection{Dur: 90 * time.Second})
|
||||
m := flattenOf("p", testSection{
|
||||
Dur: 90 * time.Second,
|
||||
})
|
||||
for _, k := range []string{"p.str", "p.on", "p.inner.name"} {
|
||||
if _, ok := m[k]; !ok {
|
||||
t.Errorf("flattenOf missing %q in %v", k, m)
|
||||
@@ -145,14 +147,18 @@ func TestApplyDefaults(t *testing.T) {
|
||||
t.Fatalf("applyDefaults: %v", err)
|
||||
}
|
||||
want := testSection{
|
||||
testEmbedded: testEmbedded{On: true},
|
||||
Str: "hello",
|
||||
Int: -42,
|
||||
Uint: 7,
|
||||
Float: 1.5,
|
||||
Dur: 90 * time.Second,
|
||||
Size: 32 << 10,
|
||||
Inner: testInner{Name: "inner"},
|
||||
testEmbedded: testEmbedded{
|
||||
On: true,
|
||||
},
|
||||
Str: "hello",
|
||||
Int: -42,
|
||||
Uint: 7,
|
||||
Float: 1.5,
|
||||
Dur: 90 * time.Second,
|
||||
Size: 32 << 10,
|
||||
Inner: testInner{
|
||||
Name: "inner",
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(s, want) {
|
||||
t.Errorf("applyDefaults = %+v; want %+v", s, want)
|
||||
@@ -247,6 +253,7 @@ func TestSetValue(t *testing.T) {
|
||||
{"size", "1 mb", "1MB"}, // byte sizes are given out as strings
|
||||
{"size", "1.5KiB", "1536B"},
|
||||
{"size", "4096", "4KiB"},
|
||||
{"size", "-1", "-1"}, // no limit
|
||||
{"slice", " a, b ,, c ", []string{"a", "b", "c"}},
|
||||
{"slice", "", []string(nil)},
|
||||
{"inner.name", "nested", "nested"},
|
||||
@@ -286,8 +293,14 @@ func TestSetValue(t *testing.T) {
|
||||
}
|
||||
got, err := valueOf(s, tt.key)
|
||||
if err != nil || !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("after setValue(%q, %#v): valueOf = %#v, %v; want %#v",
|
||||
tt.key, tt.value, got, err, tt.want)
|
||||
t.Errorf(
|
||||
"after setValue(%q, %#v): valueOf = %#v, %v; want %#v",
|
||||
tt.key,
|
||||
tt.value,
|
||||
got,
|
||||
err,
|
||||
tt.want,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,8 +335,13 @@ func TestSetValueErrors(t *testing.T) {
|
||||
before := s
|
||||
err := setValue(&s, tt.key, tt.value)
|
||||
if err == nil || !strings.Contains(err.Error(), tt.want) {
|
||||
t.Errorf("setValue(%q, %#v) = %v; want error containing %q",
|
||||
tt.key, tt.value, err, tt.want)
|
||||
t.Errorf(
|
||||
"setValue(%q, %#v) = %v; want error containing %q",
|
||||
tt.key,
|
||||
tt.value,
|
||||
err,
|
||||
tt.want,
|
||||
)
|
||||
}
|
||||
if !reflect.DeepEqual(s, before) {
|
||||
t.Errorf("setValue(%q, %#v) modified the section on error", tt.key, tt.value)
|
||||
@@ -334,7 +352,9 @@ func TestSetValueErrors(t *testing.T) {
|
||||
// A []string is given out as a copy, so changing it leaves the section as it
|
||||
// was.
|
||||
func TestValueOfSliceIsACopy(t *testing.T) {
|
||||
s := testSection{Slice: []string{"a", "b"}}
|
||||
s := testSection{
|
||||
Slice: []string{"a", "b"},
|
||||
}
|
||||
got, err := valueOf(s, "slice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in new issue
Block a user