Skip to content

Commit

Permalink
moves example to test
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Aug 31, 2022
1 parent acaf276 commit c522a3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 17 additions & 0 deletions converter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package caps_test

import (
"fmt"
"testing"

"github.com/chanced/caps"
Expand Down Expand Up @@ -106,3 +107,19 @@ func TestConverterTableOps(t *testing.T) {
// t.Errorf("expected \"WSS\", got \"%s\"", wss.Screaming)
// }
}

type MyConverter struct{}

func (MyConverter) Convert(req caps.ConvertRequest) string {
res := caps.DefaultConverter.Convert(req)
if req.Style == caps.StyleLowerCamel && req.ReplaceStyle == caps.ReplaceStyleCamel && res == "id" {
return "_id"
}
return res
}

func ExampleWithConverter() {
fmt.Println(caps.ToLowerCamel("id", caps.WithConverter(MyConverter{}), caps.WithReplaceStyle(caps.ReplaceStyleCamel)))
// Output:
// _id
}
16 changes: 0 additions & 16 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,3 @@ func ExampleToTitle() {
// Output:
// This Is An Example ID 32
}

type MyConverter struct{}

func (MyConverter) Convert(req caps.ConvertRequest) string {
res := caps.DefaultConverter.Convert(req)
if req.Style == caps.StyleLowerCamel && req.ReplaceStyle == caps.ReplaceStyleCamel && res == "id" {
return "_id"
}
return res
}

func ExampleWithConverter() {
fmt.Println(caps.ToLowerCamel("id", caps.WithConverter(MyConverter{}), caps.WithReplaceStyle(caps.ReplaceStyleCamel)))
// Output:
// _id
}

0 comments on commit c522a3a

Please sign in to comment.