Skip to content

Commit

Permalink
Rm robots comment (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Jun 5, 2022
1 parent 7069a2a commit a994308
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
dist
coverage.txt
.vscode
112 changes: 56 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ In Go, variables declared without an explicit initial value are given their zero

## Inspiration

* Java [Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)
* [https://github.com/leighmcculloch/go-optional](https://github.com/leighmcculloch/go-optional)
* [https://github.com/golang/go/issues/7054](https://github.com/golang/go/issues/7054)
- Java [Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)
- [https://github.com/leighmcculloch/go-optional](https://github.com/leighmcculloch/go-optional)
- [https://github.com/golang/go/issues/7054](https://github.com/golang/go/issues/7054)

## Tool

Expand Down Expand Up @@ -55,50 +55,50 @@ and output file is optional_t.go. This can be overridden with the -output flag.

## Library

* [bool](bool.go)
* [byte](byte.go)
* [complex128](complex128.go)
* [complex64](complex64.go)
* [float32](float32.go)
* [float64](float64.go)
* [int](int.go)
* [int16](int16.go)
* [int32](int32.go)
* [int64](int64.go)
* [int8](int8.go)
* [rune](rune.go)
* [string](string.go)
* [uint](uint.go)
* [uint16](uint16.go)
* [uint32](uint32.go)
* [uint64](uint64.go)
* [uint8](uint8.go)
* [uintptr](uintptr.go)
* [error](error.go)
- [bool](bool.go)
- [byte](byte.go)
- [complex128](complex128.go)
- [complex64](complex64.go)
- [float32](float32.go)
- [float64](float64.go)
- [int](int.go)
- [int16](int16.go)
- [int32](int32.go)
- [int64](int64.go)
- [int8](int8.go)
- [rune](rune.go)
- [string](string.go)
- [uint](uint.go)
- [uint16](uint16.go)
- [uint32](uint32.go)
- [uint64](uint64.go)
- [uint8](uint8.go)
- [uintptr](uintptr.go)
- [error](error.go)

### Usage

```go
package main

import (
"fmt"
"fmt"

"github.com/markphelps/optional"
"github.com/markphelps/optional"
)

func main() {
s := optional.NewString("foo")
s := optional.NewString("foo")

value, err := s.Get()
if err != nil {
// handle error!
} else {
fmt.Println(value)
}
value, err := s.Get()
if err != nil {
// handle error!
} else {
fmt.Println(value)
}

t := optional.String{}
fmt.Println(t.OrElse("bar"))
t := optional.String{}
fmt.Println(t.OrElse("bar"))
}
```

Expand All @@ -118,21 +118,21 @@ Option types marshal to/from JSON as you would expect:
package main

import (
"encoding/json"
"fmt"
"encoding/json"
"fmt"
)

func main() {
var value = struct {
Field optional.String `json:"field,omitempty"`
}{
Field: optional.NewString("bar"),
}
var value = struct {
Field optional.String `json:"field,omitempty"`
}{
Field: optional.NewString("bar"),
}

out, _ := json.Marshal(value)
out, _ := json.Marshal(value)

fmt.Println(string(out))
// outputs: {"field":"bar"}
fmt.Println(string(out))
// outputs: {"field":"bar"}
}
```

Expand All @@ -142,21 +142,21 @@ func main() {
package main

import (
"encoding/json"
"fmt"
"encoding/json"
"fmt"
)

func main() {
var value = &struct {
Field optional.String `json:"field,omitempty"`
}{}
var value = &struct {
Field optional.String `json:"field,omitempty"`
}{}

_ = json.Unmarshal([]byte(`{"field":"bar"}`), value)
_ = json.Unmarshal([]byte(`{"field":"bar"}`), value)

value.Field.If(func(s string) {
fmt.Println(s)
})
// outputs: bar
value.Field.If(func(s string) {
fmt.Println(s)
})
// outputs: bar
}
```

Expand All @@ -168,8 +168,8 @@ As you can see test coverage is a bit lacking for the library. This is simply be

Also checkout:

* [example_test.go](example_test.go) for example usage.
* [cmd/optional/golden_test.go](cmd/optional/golden_test.go) for [golden file](https://medium.com/soon-london/testing-with-golden-files-in-go-7fccc71c43d3) based testing of the generator itself.
- [example_test.go](example_test.go) for example usage.
- [cmd/optional/golden_test.go](cmd/optional/golden_test.go) for [golden file](https://medium.com/soon-london/testing-with-golden-files-in-go-7fccc71c43d3) based testing of the generator itself.

### Golden Files

Expand Down
3 changes: 1 addition & 2 deletions cmd/optional/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ func main() {
}
}

const tmpl = `// Code generated by go generate
// This file was generated by robots at {{ .Timestamp }}
const tmpl = `// Code generated by 'go generate'
package {{ .PackageName }}
Expand Down
3 changes: 1 addition & 2 deletions cmd/optional/testdata/optional_bar.go

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

3 changes: 1 addition & 2 deletions cmd/optional/testdata/optional_foo.go

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

3 changes: 1 addition & 2 deletions cmd/optional/testdata/string.go

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

2 changes: 1 addition & 1 deletion int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestInt_MustGet_Present(t *testing.T) {
func TestInt_MustGet_NotPresent(t *testing.T) {
o := Int{}

assert.Panics(t, func(){ _ = o.MustGet() })
assert.Panics(t, func() { _ = o.MustGet() })
assert.False(t, o.Present())
}

Expand Down
4 changes: 1 addition & 3 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestString_Get_NotPresent(t *testing.T) {
assert.Equal(t, zero, v)
}


func TestString_MustGet_Present(t *testing.T) {
o := NewString("foo")

Expand All @@ -35,11 +34,10 @@ func TestString_MustGet_Present(t *testing.T) {
assert.Equal(t, "foo", v)
}


func TestString_MustGet_NotPresent(t *testing.T) {
o := String{}

assert.Panics(t, func(){ _ = o.MustGet() })
assert.Panics(t, func() { _ = o.MustGet() })
assert.False(t, o.Present())
}

Expand Down

0 comments on commit a994308

Please sign in to comment.