Skip to content

Commit

Permalink
Use backquotes for strings (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Sep 23, 2024
1 parent 74fd337 commit b05894d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 62 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ linters-settings:
settings:
shadow:
strict: true
staticcheck:
checks:
- all

linters:
disable-all: true
enable:
# TODO https://github.com/FerretDB/wire/issues/4
- govet
- staticcheck

issues:
max-issues-per-linter: 0
Expand Down
14 changes: 7 additions & 7 deletions op_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var msgTestCases = []testCase{
}},
},
command: "buildInfo",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -128,7 +128,7 @@ var msgTestCases = []testCase{
}},
},
command: "version",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -221,7 +221,7 @@ var msgTestCases = []testCase{
},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -315,7 +315,7 @@ var msgTestCases = []testCase{
}},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -389,7 +389,7 @@ var msgTestCases = []testCase{
},
},
command: "insert",
b: `
si: `
{
"FlagBits": "[]",
"Checksum": int64(0),
Expand Down Expand Up @@ -475,7 +475,7 @@ var msgTestCases = []testCase{
checksum: 1737537506,
},
command: "insert",
b: `
si: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(1737537506),
Expand Down Expand Up @@ -584,7 +584,7 @@ var msgTestCases = []testCase{
checksum: 2932997361,
},
command: "update",
b: `
si: `
{
"FlagBits": "[checksumPresent]",
"Checksum": int64(2932997361),
Expand Down
4 changes: 2 additions & 2 deletions op_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var queryTestCases = []testCase{
),
returnFieldsSelector: nil,
},
b: `
si: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand Down Expand Up @@ -129,7 +129,7 @@ var queryTestCases = []testCase{
),
returnFieldsSelector: nil,
},
b: `
si: `
{
"Flags": "[]",
"FullCollectionName": "admin.$cmd",
Expand Down
4 changes: 2 additions & 2 deletions op_reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var replyTestCases = []testCase{
"ok", float64(1),
),
},
b: `
si: `
{
"ResponseFlags": "[AwaitCapable]",
"CursorID": int64(0),
Expand Down Expand Up @@ -112,7 +112,7 @@ var replyTestCases = []testCase{
"ok", float64(1),
),
},
b: `
si: `
{
"ResponseFlags": "[AwaitCapable]",
"CursorID": int64(0),
Expand Down
5 changes: 3 additions & 2 deletions wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -70,7 +71,7 @@ type testCase struct {
msgHeader *MsgHeader
msgBody MsgBody
command string // only for OpMsg
b string
si string
err string // unwrapped
}

Expand Down Expand Up @@ -127,7 +128,7 @@ func testMessages(t *testing.T, testCases []testCase) {
require.NotNil(t, msgHeader)
require.NotNil(t, msgBody)
assert.NotEmpty(t, msgHeader.String())
assert.Equal(t, testutil.Unindent(tc.b), msgBody.StringIndent())
assert.Equal(t, strings.ReplaceAll(testutil.Unindent(tc.si), `"`, "`"), msgBody.StringIndent())
assert.NotEmpty(t, msgBody.String())

require.NoError(t, msgBody.check())
Expand Down
47 changes: 24 additions & 23 deletions wirebson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package wirebson

import (
"strings"
"testing"
"time"

Expand All @@ -31,7 +32,7 @@ type normalTestCase struct {
name string
raw RawDocument
doc *Document
b string
mi string
}

// decodeTestCase represents a single test case for unsuccessful decoding.
Expand Down Expand Up @@ -77,7 +78,7 @@ var normalTestCases = []normalTestCase{
"compression", MustArray("none"),
"loadBalanced", false,
),
b: `
mi: `
{
"ismaster": true,
"client": {
Expand Down Expand Up @@ -126,7 +127,7 @@ var normalTestCases = []normalTestCase{
"compression", MustArray("none"),
"loadBalanced", false,
),
b: `
mi: `
{
"ismaster": true,
"client": {
Expand Down Expand Up @@ -167,7 +168,7 @@ var normalTestCases = []normalTestCase{
),
"$db", "admin",
),
b: `
mi: `
{
"buildInfo": 1,
"lsid": {
Expand Down Expand Up @@ -220,7 +221,7 @@ var normalTestCases = []normalTestCase{
"storageEngines", MustArray("devnull", "ephemeralForTest", "wiredTiger"),
"ok", float64(1),
),
b: `
mi: `
{
"version": "5.0.0",
"gitVersion": "1184f004a99660de6f5e745573419bda8a28c0e9",
Expand Down Expand Up @@ -290,7 +291,7 @@ var normalTestCases = []normalTestCase{
"timestamp", MustArray(Timestamp(42), Timestamp(0)),
"decimal128", MustArray(Decimal128{L: 42, H: 13}),
),
b: `
mi: `
{
"array": [
[
Expand Down Expand Up @@ -353,7 +354,7 @@ var normalTestCases = []normalTestCase{
name: "nested",
raw: testutil.MustParseDumpFile("testdata", "nested.hex"),
doc: makeNested(false, 150).(*Document),
b: `
mi: `
{
"f": [
{
Expand Down Expand Up @@ -407,7 +408,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", float64(3.141592653589793),
),
b: `
mi: `
{
"f": 3.141592653589793,
}`,
Expand All @@ -424,7 +425,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", "v",
),
b: `
mi: `
{
"f": "v",
}`,
Expand All @@ -442,7 +443,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", Binary{B: []byte("v"), Subtype: BinaryUser},
),
b: `
mi: `
{
"f": Binary(user:dg==),
}`,
Expand All @@ -458,7 +459,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", ObjectID{0x62, 0x56, 0xc5, 0xba, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40},
),
b: `
mi: `
{
"f": ObjectID(6256c5ba182d4454fb210940),
}`,
Expand All @@ -474,7 +475,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", true,
),
b: `
mi: `
{
"f": true,
}`,
Expand All @@ -490,7 +491,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", time.Date(2024, 1, 17, 17, 40, 42, 123000000, time.UTC),
),
b: `
mi: `
{
"f": 2024-01-17T17:40:42.123Z,
}`,
Expand All @@ -505,7 +506,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", Null,
),
b: `
mi: `
{
"f": null,
}`,
Expand All @@ -522,7 +523,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", Regex{Pattern: "p", Options: "o"},
),
b: `
mi: `
{
"f": /p/o,
}`,
Expand All @@ -538,7 +539,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", int32(314159265),
),
b: `
mi: `
{
"f": 314159265,
}`,
Expand All @@ -554,7 +555,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", Timestamp(42),
),
b: `
mi: `
{
"f": Timestamp(42),
}`,
Expand All @@ -570,7 +571,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", int64(3141592653589793),
),
b: `
mi: `
{
"f": int64(3141592653589793),
}`,
Expand All @@ -586,7 +587,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"f", Decimal128{L: 42, H: 13},
),
b: `
mi: `
{
"f": Decimal128(42,13),
}`,
Expand All @@ -602,7 +603,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"foo", MustDocument(),
),
b: `
mi: `
{
"foo": {},
}`,
Expand All @@ -618,7 +619,7 @@ var normalTestCases = []normalTestCase{
doc: MustDocument(
"foo", MustArray(),
),
b: `
mi: `
{
"foo": [],
}`,
Expand All @@ -635,7 +636,7 @@ var normalTestCases = []normalTestCase{
"", false,
"", true,
),
b: `
mi: `
{
"": false,
"": true,
Expand Down Expand Up @@ -781,7 +782,7 @@ func TestNormal(t *testing.T) {
assert.NotContains(t, ls, "called too many times")

assert.NotEmpty(t, doc.LogMessage())
assert.Equal(t, testutil.Unindent(tc.b), doc.LogMessageIndent())
assert.Equal(t, strings.ReplaceAll(testutil.Unindent(tc.mi), `"`, "`"), doc.LogMessageIndent())

raw, err := doc.Encode()
require.NoError(t, err)
Expand Down
Loading

0 comments on commit b05894d

Please sign in to comment.