Skip to content

TNTP-3729: generator for builtin go types #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,54 @@ formatters:
- goimports

linters:
enable:
- forbidigo
- gocritic
- lll
- reassign
- unconvert
- gosec
- errorlint
- godot
- revive
- testpackage
- unused
default: all

disable:
- dupl
- cyclop
- wsl
- nlreturn
- ireturn
- wrapcheck
Comment on lines +13 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add comments: why do we disable the checks? After a while, it's not clear.


exclusions:
rules:
- path-except: cmd/generator/*.go
linters:
- forbidigo
- gochecknoglobals
Comment on lines +21 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.


settings:
godot:
scope: all
lll:
line-length: 120
tab-width: 4
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
case-max-lines: 0
default: all
disable:
- return
- assign-exclusive
- assign-expr
Comment on lines +40 to +43
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add comments: why do we disable the checks? After a while, it's not clear.

depguard:
rules:
main:
files:
- "$all"
- "!$test"
allow:
- $gostd
- "github.com/vmihailenco/msgpack/v5"
- "golang.org/x/text"
test:
files:
- "$test"
allow:
- $gostd
- "github.com/stretchr/testify"
- "github.com/vmihailenco/msgpack/v5"
- "github.com/tarantool/go-option"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

### Added

* Implemented optional types for builtin go types int*, uint*, float*,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See:

https://keepachangelog.com/en/1.0.0/

Suggested change
* Implemented optional types for builtin go types int*, uint*, float*,
- Implemented optional types for builtin go types int*, uint*, float*,

bytes, string, bool.


### Changed

### Fixed
Expand Down
90 changes: 90 additions & 0 deletions bool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions bool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package option_test

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-option"
)

func TestOptionalBool(t *testing.T) {
t.Parallel()

var buf bytes.Buffer

enc := msgpack.NewEncoder(&buf)
dec := msgpack.NewDecoder(&buf)

someBool := option.SomeBool(true)
assert.True(t, someBool.IsSome(), "Expected IsPresent() to return true")
require.NoError(t, someBool.EncodeMsgpack(enc))

var shouldBeSomeBool option.Bool
require.NoError(t, shouldBeSomeBool.DecodeMsgpack(dec))
assert.True(t, shouldBeSomeBool.IsSome(), "Expected IsPresent() to return true")
assert.Equal(t, someBool.Unwrap(), shouldBeSomeBool.Unwrap(), "Expected Value() to return the same value")

emptyBool := option.NoneBool()
assert.False(t, emptyBool.IsSome(), "Expected IsPresent() to return false")
require.NoError(t, emptyBool.EncodeMsgpack(enc))

var shouldBeEmptyBool option.Bool
require.NoError(t, shouldBeEmptyBool.DecodeMsgpack(dec))
assert.False(t, shouldBeEmptyBool.IsSome(), "Expected IsPresent() to return false")
}
Comment on lines +14 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, split the test into 3 or 4 tests by AAA-pattern:

https://medium.com/@pjbgf/title-testing-code-ocd-and-the-aaa-pattern-df453975ab80

Here we have a one tests for multiple test cases. This is a bad example for future developers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we don't cover all methods in the tests. MustGet as example.

90 changes: 90 additions & 0 deletions bytes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions bytes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package option_test

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-option"
)

func TestOptionalBytes(t *testing.T) {
t.Parallel()

var buf bytes.Buffer

enc := msgpack.NewEncoder(&buf)
dec := msgpack.NewDecoder(&buf)

someBytes := option.SomeBytes([]byte("1234"))
assert.True(t, someBytes.IsSome(), "Expected IsPresent() to return true")
require.NoError(t, someBytes.EncodeMsgpack(enc))

var shouldBeSomeBytes option.Bytes
require.NoError(t, shouldBeSomeBytes.DecodeMsgpack(dec))
assert.True(t, shouldBeSomeBytes.IsSome(), "Expected IsPresent() to return true")
assert.Equal(t, someBytes.Unwrap(), shouldBeSomeBytes.Unwrap(), "Expected Value() to return the same value")

emptyBytes := option.NoneBytes()
assert.False(t, emptyBytes.IsSome(), "Expected IsPresent() to return false")
require.NoError(t, emptyBytes.EncodeMsgpack(enc))

var shouldBeEmptyBytes option.Bytes
require.NoError(t, shouldBeEmptyBytes.DecodeMsgpack(dec))
assert.False(t, shouldBeEmptyBytes.IsSome(), "Expected IsPresent() to return false")
}
Loading
Loading