Skip to content

Commit e1a64b8

Browse files
committed
Use %q to format-quote strings
1 parent e755795 commit e1a64b8

4 files changed

Lines changed: 9 additions & 10 deletions

File tree

exercises/concept/gross-store/gross_store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func TestUnits(t *testing.T) {
2828
qty, ok := units[tt.name]
2929

3030
if !ok {
31-
t.Errorf(`Unit "%s" not found!`, tt.name)
31+
t.Errorf("Unit %q not found!", tt.name)
3232
continue
3333
}
3434

3535
if qty != tt.qty {
36-
t.Errorf(`Unit "%s" should have quantity %d, found %d`, tt.name, tt.qty, qty)
36+
t.Errorf("Unit %q should have quantity %d, found %d", tt.name, tt.qty, qty)
3737
}
3838
}
3939
}

exercises/concept/weather-forecast/weather_forecast_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func testComment(entityKind, entityName, comment, wantedPrefix string) (ok bool,
111111

112112
// Check if comment has wanted prefix
113113
if !strings.HasPrefix(trimmedComment, wantedPrefix) {
114-
errorString := fmt.Sprintf("%s comment for %s '%s' should start with '// %s ...': got '// %s'",
114+
errorString := fmt.Sprintf("%s comment for %s %q should start with '// %s ...': got '// %s'",
115115
entityKind, lowerEntity, entityName, wantedPrefix, trimmedComment)
116116
return false, errorString
117117
}
@@ -123,14 +123,14 @@ func testComment(entityKind, entityName, comment, wantedPrefix string) (ok bool,
123123

124124
if commentContent == "" {
125125
lowerEntity := strings.ToLower(entityKind)
126-
errorString := fmt.Sprintf("%s comment of '%s' should provide a description of the %s, e.g '// %s <%s_description>'",
126+
errorString := fmt.Sprintf("%s comment of %q should provide a description of the %s, e.g '// %s <%s_description>'",
127127
entityKind, entityName, lowerEntity, wantedPrefix, lowerEntity)
128128
return false, errorString
129129
}
130130

131131
// Check if comment ends in a period
132132
if !strings.HasSuffix(trimmedComment, ".") {
133-
return false, fmt.Sprintf("%s comment for %s '%s' should end with a period (.)",
133+
return false, fmt.Sprintf("%s comment for %s %q should end with a period (.)",
134134
entityKind, lowerEntity, entityName)
135135
}
136136

exercises/practice/nucleotide-count/.meta/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (t testCase) SortedMapString() string {
4444
for k, v := range t.Expected {
4545
switch t := v.(type) {
4646
case float64:
47-
strs = append(strs, fmt.Sprintf("'%s':%d", k, int(t)))
47+
strs = append(strs, fmt.Sprintf("%q:%d", k, int(t)))
4848
default:
4949
log.Fatalf("unexpected type %T for %v", t, v)
5050
}

gomod-sync/gomod/version_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ go 1.18
9696
}
9797

9898
if string(data) != test.Modified {
99-
t.Fatalf("expected go.mod file with the following contents:\n"+
100-
"%s\n"+
101-
"but got:\n"+
102-
"%s", test.Modified, string(data))
99+
t.Fatalf(
100+
"expected go.mod file with the following contents:\n%s\nbut got:\n%s", test.Modified, string(data),
101+
)
103102
}
104103

105104
err = os.Remove(filePath)

0 commit comments

Comments
 (0)