Skip to content

Commit b3efea9

Browse files
committed
generator: implement generator for builtin go types
* supported optional types are int*, uint*, float*, bytes, string, bool * fully redo configuration for golangci-lint * simple tests for encoding/decoding roundtrip
1 parent 9f66f2f commit b3efea9

27 files changed

+2398
-13
lines changed

.golangci.yml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,54 @@ formatters:
88
- goimports
99

1010
linters:
11-
enable:
12-
- forbidigo
13-
- gocritic
14-
- lll
15-
- reassign
16-
- unconvert
17-
- gosec
18-
- errorlint
19-
- godot
20-
- revive
21-
- testpackage
22-
- unused
11+
default: all
12+
13+
disable:
14+
- dupl
15+
- cyclop
16+
- wsl
17+
- nlreturn
18+
- ireturn
19+
- wrapcheck
20+
21+
exclusions:
22+
rules:
23+
- path-except: cmd/generator/*.go
24+
linters:
25+
- forbidigo
26+
- gochecknoglobals
2327

2428
settings:
2529
godot:
2630
scope: all
2731
lll:
2832
line-length: 120
2933
tab-width: 4
34+
wsl_v5:
35+
allow-first-in-block: true
36+
allow-whole-block: false
37+
branch-max-lines: 2
38+
case-max-lines: 0
39+
default: all
40+
disable:
41+
- return
42+
- assign-exclusive
43+
- assign-expr
44+
depguard:
45+
rules:
46+
main:
47+
files:
48+
- "$all"
49+
- "!$test"
50+
allow:
51+
- $gostd
52+
- "github.com/vmihailenco/msgpack/v5"
53+
- "golang.org/x/text"
54+
test:
55+
files:
56+
- "$test"
57+
allow:
58+
- $gostd
59+
- "github.com/stretchr/testify"
60+
- "github.com/vmihailenco/msgpack/v5"
61+
- "github.com/tarantool/go-option"

bool.go

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bool_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalBool(t *testing.T) {
15+
t.Parallel()
16+
17+
var buf bytes.Buffer
18+
19+
enc := msgpack.NewEncoder(&buf)
20+
dec := msgpack.NewDecoder(&buf)
21+
22+
someBool := option.SomeBool(true)
23+
assert.True(t, someBool.IsSome(), "Expected IsPresent() to return true")
24+
require.NoError(t, someBool.EncodeMsgpack(enc))
25+
26+
var shouldBeSomeBool option.Bool
27+
require.NoError(t, shouldBeSomeBool.DecodeMsgpack(dec))
28+
assert.True(t, shouldBeSomeBool.IsSome(), "Expected IsPresent() to return true")
29+
assert.Equal(t, someBool.Unwrap(), shouldBeSomeBool.Unwrap(), "Expected Value() to return the same value")
30+
31+
emptyBool := option.NoneBool()
32+
assert.False(t, emptyBool.IsSome(), "Expected IsPresent() to return false")
33+
require.NoError(t, emptyBool.EncodeMsgpack(enc))
34+
35+
var shouldBeEmptyBool option.Bool
36+
require.NoError(t, shouldBeEmptyBool.DecodeMsgpack(dec))
37+
assert.False(t, shouldBeEmptyBool.IsSome(), "Expected IsPresent() to return false")
38+
}

bytes.go

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bytes_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalBytes(t *testing.T) {
15+
t.Parallel()
16+
17+
var buf bytes.Buffer
18+
19+
enc := msgpack.NewEncoder(&buf)
20+
dec := msgpack.NewDecoder(&buf)
21+
22+
someBytes := option.SomeBytes([]byte("1234"))
23+
assert.True(t, someBytes.IsSome(), "Expected IsPresent() to return true")
24+
require.NoError(t, someBytes.EncodeMsgpack(enc))
25+
26+
var shouldBeSomeBytes option.Bytes
27+
require.NoError(t, shouldBeSomeBytes.DecodeMsgpack(dec))
28+
assert.True(t, shouldBeSomeBytes.IsSome(), "Expected IsPresent() to return true")
29+
assert.Equal(t, someBytes.Unwrap(), shouldBeSomeBytes.Unwrap(), "Expected Value() to return the same value")
30+
31+
emptyBytes := option.NoneBytes()
32+
assert.False(t, emptyBytes.IsSome(), "Expected IsPresent() to return false")
33+
require.NoError(t, emptyBytes.EncodeMsgpack(enc))
34+
35+
var shouldBeEmptyBytes option.Bytes
36+
require.NoError(t, shouldBeEmptyBytes.DecodeMsgpack(dec))
37+
assert.False(t, shouldBeEmptyBytes.IsSome(), "Expected IsPresent() to return false")
38+
}

0 commit comments

Comments
 (0)