Skip to content

Commit

Permalink
docs: move examples [#48] (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedhyw authored Oct 4, 2022
1 parent 428fe84 commit 8378c9e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"thelper",
"paralleltest",
"ireturn",
"gomnd"
"gomnd",
"nolintlint"
]
},
"linters-settings": {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOLANG_CI_LINT_VER:=v1.46.2
GOLANG_CI_LINT_VER:=v1.50.0
COVER_PACKAGES=${shell go list ./... | grep -Ev 'test' | tr '\n' ','}

all: lint test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- **[Why?](#why)**
- **[FAQ](#faq)**
- **[Documentation](_docs/library.md)**
- **[Examples](pkg/examples_test.go)**
- **[Examples](pkg/rex/examples_test.go)**
- **[License](#license)**

## Why?
Expand Down
2 changes: 1 addition & 1 deletion _docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ submatches := re.FindAllStringSubmatch(text, -1)

#### More examples

More examples can be found here: [examples_test.go](examples_test.go).
More examples can be found here: [examples_test.go](../pkg/rex/examples_test.go).
8 changes: 4 additions & 4 deletions pkg/dialect/base/helper_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type NumberRange struct {
//
// It doesn't match leading zeros. If you want to match them, use:
//
// Group.NonCaptured(
// Chars.Single('0').Repeat().ZeroOrMore(),
// Helper.NumberRange(0, 99),
// )
// Group.NonCaptured(
// Chars.Single('0').Repeat().ZeroOrMore(),
// Helper.NumberRange(0, 99),
// )
func (h HelperDialect) NumberRange(from int32, to int32) NumberRange {
return NumberRange{
initialFrom: int64(from),
Expand Down
12 changes: 7 additions & 5 deletions pkg/dialect/base/helper_phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
// Phone contains composite of different phone patterns: E.164, E.123.
//
// Examples:
// +15555555
// (607) 123 4567
// +22 607 123 4567
//
// +15555555
// (607) 123 4567
// +22 607 123 4567
func (h HelperDialect) Phone() dialect.Token {
return Group.Composite(
h.PhoneE164(),
Expand Down Expand Up @@ -43,8 +44,9 @@ func (HelperDialect) PhoneE164() dialect.Token {
// It combines international and national formats.
//
// Examples:
// (607) 123 4567
// +22 607 123 4567
//
// (607) 123 4567
// +22 607 123 4567
func (h HelperDialect) PhoneE123() dialect.Token {
return Group.Composite(
h.PhoneNationalE123(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/dialect/base/helper_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (HelperDialect) HostnameRFC1123() dialect.Token {
// Hostname is validated considering RFC-1123.
//
// Localpart is unquoted, and may use any of these ASCII characters:
// - uppercase and lowercase Latin letters A to Z and a to z, digits 0 to 9
// - printable characters !#$%&'*+-/=?^_`{|}~
// - dot ., provided that it is not the first or last character and provided
// also that it does not appear consecutively (e.g., [email protected] is not allowed).
// - uppercase and lowercase Latin letters A to Z and a to z, digits 0 to 9
// - printable characters !#$%&'*+-/=?^_`{|}~
// - dot ., provided that it is not the first or last character and provided
// also that it does not appear consecutively (e.g., [email protected] is not allowed).
func (h HelperDialect) Email() dialect.Token {
localCharsWithoutDot := Common.Class(
Chars.Alphanumeric(),
Expand Down
7 changes: 5 additions & 2 deletions pkg/dialect/base/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ func (rt RawToken) WriteTo(w dialect.StringByteWriter) (n int, err error) {
// backslash '\#' or it is not in the character class '[#]'.
//
// This input:
// .+\#[#] # comment
//
// .+\#[#] # comment
//
// Will be converted to:
// .+\#[#]
//
// .+\#[#]
func removeComment(val string) string {
var (
backslash bool
Expand Down
6 changes: 3 additions & 3 deletions pkg/examples_test.go → pkg/rex/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint: lll // Generated regular expression can be long.
// nolint: lll,nosnakecase // Generated regular expression can be long.
package rex_test

import (
Expand All @@ -12,15 +12,15 @@ import (
func Example_basicMethods() {
rexRe := rex.New(rex.Chars.Any().Repeat().ZeroOrMore())

// Use Compile if you spcify dynamic arguments.
// Use Compile if you specify dynamic arguments.
re, err := rexRe.Compile()
if err != nil {
log.Fatal(err)
}

fmt.Println(`re.MatchString("a"):`, re.MatchString("a"))

// Use MustCompile if you don't speicfy dynamic arguments.
// Use MustCompile if you don't specify dynamic arguments.
re = rexRe.MustCompile()
fmt.Println(`re.MatchString("a"):`, re.MatchString("a"))

Expand Down

0 comments on commit 8378c9e

Please sign in to comment.