Skip to content

Commit 920442f

Browse files
Merge pull request #48 from brazzcore/feature/47-apply-the-camel-case-naming-convention
[feature/47] :: applied the camelcase naming convention
2 parents 4679e96 + d6bd9cc commit 920442f

File tree

21 files changed

+214
-106
lines changed

21 files changed

+214
-106
lines changed

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,36 @@ go get github.com/brazzcore/mocai
3737
Basic Usage
3838
Import the library into your project and start generating mocks:
3939

40-
```
41-
package examples
42-
43-
import (
44-
"fmt"
45-
46-
"github.com/brazzcore/mocai/pkg/mocai/entities/person"
47-
"github.com/brazzcore/mocai/pkg/mocai/translations"
48-
)
40+
```go
41+
// specific
42+
translations.SetLanguage("ptbr")
4943

50-
func GenerateMockExample() {
51-
translations.SetLanguage("ptbr")
52-
53-
p, err := person.GeneratePerson()
54-
if err != nil {
55-
fmt.Print(err)
56-
return
57-
}
44+
addr, err := address.GenerateAddress()
45+
if err != nil {
46+
log.Println(err)
47+
}
5848

59-
fmt.Printf("Person: %s %s, %s, %d years old, CPF: %s\n",
60-
p.FirstNameMale, p.LastName, p.Gender, p.Age, p.CPF)
49+
addr.Street // returns street name
50+
```
6151

52+
```go
53+
// mocker
54+
m, err := mocai.NewMocker("ptbr")
55+
if err != nil {
56+
log.Println(err)
6257
}
63-
```
6458

59+
m.Address().Street // returns street name
60+
m.Phone().Number // returns phone number
61+
```
6562
### Examples
66-
The ***examples*** folder contains samples of how to use the library. To run the examples, navigate to the root folder and execute:
63+
The ***examples*** folder contains samples of how to use the library, organized by approach:
64+
65+
- `specific/`: Examples using direct calls to each of Mocaí's mockable entities (e.g., phone.GeneratePhone, etc).
66+
67+
- `mocker/`: Example using a main entry point `mocai.NewMocker("ptbr")` to generate mocks in a fluent and simplified way.
6768

69+
To run an example, navigate to the desired directory and run:
6870
```
6971
go run main.go
7072
```

docs/localization/pt/README-PT.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,37 @@ go get github.com/brazzcore/mocai
3535
Uso Básico
3636
Importe a biblioteca em seu projeto e comece a gerar mocks:
3737

38-
```
39-
package examples
40-
41-
import (
42-
"fmt"
43-
44-
"github.com/brazzcore/mocai/pkg/mocai/entities/person"
45-
"github.com/brazzcore/mocai/pkg/mocai/translations"
46-
)
38+
```go
39+
// specific
40+
translations.SetLanguage("ptbr")
4741

48-
func GenerateMockExample() {
49-
translations.SetLanguage("ptbr")
50-
51-
p, err := person.GeneratePerson()
52-
if err != nil {
53-
fmt.Print(err)
54-
return
55-
}
42+
addr, err := address.GenerateAddress()
43+
if err != nil {
44+
log.Println(err)
45+
}
5646

57-
fmt.Printf("Person: %s %s, %s, %d years old, CPF: %s\n",
58-
p.FirstNameMale, p.LastName, p.Gender, p.Age, p.CPF)
47+
addr.Street // retorna o nome da rua
48+
```
5949

50+
```go
51+
// mocker
52+
m, err := mocai.NewMocker("ptbr")
53+
if err != nil {
54+
log.Println(err)
6055
}
56+
57+
m.Address().Street // retorna o nome da rua
58+
m.Phone().Number // retorna o número de telefone
6159
```
6260

6361
### Exemplos
64-
A pasta ***examples*** contém exemplos de como usar a biblioteca. Para executar os exemplos, navegue até a pasta raiz e execute:
62+
O diretório ***examples*** contém exemplos de comoo usar a biblioteca, organizados por abordagem:
63+
64+
- `specific/`: Exemplos usando as funções diretas de cada entidade mockável do Mocaí (`phone.GeneratePhone`, etc).
65+
66+
- `mocker/`: Exemplo usando um ponto de entrada principal `mocai.NewMocker("ptbr")` para gerar mocks de maneira fluida e simplificada.
6567

68+
Para executar um exemplo, acesse o diretório desejado e execute:
6669
```
6770
go run main.go
6871
```

examples/mocker/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/brazzcore/mocai/internal/cli"
8+
"github.com/brazzcore/mocai/pkg/mocai"
9+
)
10+
11+
func main() {
12+
13+
fmt.Println(cli.HeaderMain)
14+
fmt.Println(cli.SubHeader)
15+
16+
// Initialize mocai and set a supported language
17+
// If the language is not available, the default language pt-BR will be set
18+
m, err := mocai.NewMocker("ptbr")
19+
if err != nil {
20+
log.Println(err)
21+
}
22+
// Generate mock data
23+
// You can select which entity attributes to use
24+
// by accessing the entity and its fields
25+
m.Person() // m.Person().Age, m.Person().CPF...
26+
m.Address() // m.Address().City, m.Address().Number...
27+
m.Phone() // m.Phone().AreaCode, m.Phone().Number
28+
29+
// Printing mocks example
30+
addr := m.Address()
31+
fmt.Printf("Address: %s, %d - %s, %s (%s) - %s\n",
32+
addr.Street, addr.Number, addr.City, addr.State, addr.UF, addr.ZIP)
33+
34+
fmt.Println(cli.Footer)
35+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package examples
1+
package main
22

33
import (
44
"fmt"
55

6-
"github.com/brazzcore/mocai/pkg/mocai/constants"
6+
"github.com/brazzcore/mocai/internal/cli"
77
"github.com/brazzcore/mocai/pkg/mocai/entities/address"
88
"github.com/brazzcore/mocai/pkg/mocai/entities/certificate"
99
"github.com/brazzcore/mocai/pkg/mocai/entities/company"
@@ -14,7 +14,7 @@ import (
1414
"github.com/brazzcore/mocai/pkg/mocai/translations"
1515
)
1616

17-
func GenerateMockExample() {
17+
func main() {
1818
// Set the language to pt-BR
1919
translations.SetLanguage("ptbr")
2020

@@ -61,11 +61,11 @@ func GenerateMockExample() {
6161
return
6262
}
6363

64-
fmt.Println(constants.HeaderMain)
65-
fmt.Println(constants.SubHeader)
64+
fmt.Println(cli.HeaderMain)
65+
fmt.Println(cli.SubHeader)
6666

6767
fmt.Printf("Person: %s %s, %s, %d years old, CPF: %s\n",
68-
p.FirstNameMale, p.LastName, p.Gender, p.Age, p.CPF)
68+
p.FirstNameMale, p.LastName, *p.Gender, p.Age, p.CPF)
6969

7070
fmt.Printf("RG: %s, State: %s, Issuing Body: %s\n",
7171
nid.BrazilianRG.Number, nid.BrazilianRG.State, nid.BrazilianRG.IssuingBody)
@@ -92,5 +92,5 @@ func GenerateMockExample() {
9292
vr.BrazilianVoteRegistration.Section, vr.BrazilianVoteRegistration.Zone,
9393
vr.BrazilianVoteRegistration.Number)
9494

95-
fmt.Println(constants.Footer)
95+
fmt.Println(cli.Footer)
9696
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
package constants
2-
3-
import (
4-
"github.com/brazzcore/mocai/pkg/mocai"
5-
)
1+
package cli
62

73
// ANSI Escape Codes
84
var (
@@ -22,7 +18,7 @@ var (
2218

2319
func init() {
2420
// Checks if the terminal supports ANSI
25-
if mocai.SupportsANSI() {
21+
if SupportsANSI() {
2622
CyanBold = "\033[1;36m"
2723
BlueBold = "\033[1;34m"
2824
Italic = "\033[3m"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mocai
1+
package cli
22

33
import (
44
"os"

main.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

pkg/mocai/entities/address/generator.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ func GenerateAddress() (*Address, error) {
6767
state := states[rand.Intn(len(states))]
6868
zip := zips[rand.Intn(len(zips))]
6969

70-
createdAddress := &Address{
70+
return &Address{
7171
Street: street,
7272
Number: rand.Intn(9999),
7373
City: city,
7474
State: state,
7575
UF: uf,
7676
ZIP: zip,
77-
}
78-
79-
return createdAddress, nil
77+
}, nil
8078
}

pkg/mocai/entities/company/countries/brazilian_company.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package countries
22

33
import (
4-
"errors"
54
"fmt"
65
"math/rand"
76
"strings"
@@ -27,7 +26,7 @@ func GenerateBrazilianCompany(formatted bool) (*BrazilianCompany, error) {
2726

2827
// Validate data
2928
if len(companyNames) == 0 {
30-
return nil, errors.New("no company names available")
29+
return nil, ErrNoCompanyNamesAvailable
3130
}
3231

3332
// Choose a random company name

pkg/mocai/entities/company/countries/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ import "errors"
88
var (
99
ErrGeneratingBrazilianCompany = errors.New("error generating brazilian company")
1010
ErrGeneratingCNPJ = errors.New("error generating CNPJ")
11+
ErrNoCompanyNamesAvailable = errors.New("no company names available")
1112
)

0 commit comments

Comments
 (0)