How to use prettifyName method of generators Package

Best Ginkgo code snippet using generators.prettifyName

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

generators_common.go

Source: generators_common.go Github

copy
1package generators
2
3import (
4	"go/build"
5	"os"
6	"path/filepath"
7	"strconv"
8	"strings"
9
10	"github.com/onsi/ginkgo/v2/ginkgo/command"
11)
12
13type GeneratorsConfig struct {
14	Agouti, NoDot, Internal bool
15	CustomTemplate          string
16}
17
18func getPackageAndFormattedName() (string, string, string) {
19	path, err := os.Getwd()
20	command.AbortIfError("Could not get current working diretory:", err)
21
22	dirName := strings.Replace(filepath.Base(path), "-", "_", -1)
23	dirName = strings.Replace(dirName, " ", "_", -1)
24
25	pkg, err := build.ImportDir(path, 0)
26	packageName := pkg.Name
27	if err != nil {
28		packageName = ensureLegalPackageName(dirName)
29	}
30
31	formattedName := prettifyName(filepath.Base(path))
32	return packageName, dirName, formattedName
33}
34
35func ensureLegalPackageName(name string) string {
36	if name == "_" {
37		return "underscore"
38	}
39	if len(name) == 0 {
40		return "empty"
41	}
42	n, isDigitErr := strconv.Atoi(string(name[0]))
43	if isDigitErr == nil {
44		return []string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}[n] + name[1:]
45	}
46	return name
47}
48
49func prettifyName(name string) string {
50	name = strings.Replace(name, "-", " ", -1)
51	name = strings.Replace(name, "_", " ", -1)
52	name = strings.Title(name)
53	name = strings.Replace(name, " ", "", -1)
54	return name
55}
56
57func determinePackageName(name string, internal bool) string {
58	if internal {
59		return name
60	}
61
62	return name + "_test"
63}
64
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger prettifyName code on LambdaTest Cloud Grid

Execute automation tests with prettifyName on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)