From a585c75115b45eb150ef7e8aea7a77048570aaf5 Mon Sep 17 00:00:00 2001 From: cuishuang Date: Fri, 27 Sep 2024 20:07:45 +0800 Subject: [PATCH 1/5] fix: fix slice init length Signed-off-by: cuishuang --- xml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml.go b/xml.go index 98ad7924..da467037 100644 --- a/xml.go +++ b/xml.go @@ -164,7 +164,7 @@ func xmlFunc(f *Faker, xo *XMLOptions) ([]byte, error) { } // Get key order by order of fields array - keyOrder := make([]string, len(xo.Fields)) + keyOrder := make([]string, 0, len(xo.Fields)) for _, f := range xo.Fields { keyOrder = append(keyOrder, f.Name) } From 7bd82489c522020cbc8d5194ed79e1126bc07cfd Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 20:36:20 -0500 Subject: [PATCH 2/5] products - new fields --- data/product.go | 34 ++++++++++++ product.go | 119 ++++++++++++++++++++++++++++++++++++++++ product_test.go | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) diff --git a/data/product.go b/data/product.go index 127d6655..81abf060 100644 --- a/data/product.go +++ b/data/product.go @@ -61,4 +61,38 @@ var Product = map[string][]string{ "quantum", "spark", "vertex", "core", "flux", "turbo", "shift", "wave", "matrix", }, + + "benefit": { + "comfort", "efficiency", "safety", "reliability", + "versatility", "ease of use", "long battery life", + "precision", "enhanced connectivity", "portability", + "durability", "energy savings", "aesthetic appeal", + "health benefits", "convenience", "time-saving", + "high performance", "noise reduction", "user satisfaction", + "customizability", "sustainability", "cost-effectiveness", + "innovative features", "improved productivity", "enhanced experience", + "robust construction", "weather resistance", "minimal maintenance", + "increased functionality", "advanced technology", "ergonomic design", + }, + + "use_case": { + "home", "office", "outdoors", "fitness", "travel", "gaming", + "cooking", "music", "learning", "entertainment", "professional work", + "healthcare", "educational purposes", "commuting", "camping", "hiking", + "sports", "art and craft", "gardening", "cleaning", "personal grooming", + "relaxation", "home security", "pet care", "smart automation", "food preparation", + "baking", "social gatherings", "productivity", "collaboration", "DIY projects", + "childcare", "remote work", "photography", "videography", "wellness routines", + }, + + "target_audience": { + "children", "adults", "seniors", "students", "professionals", "athletes", + "travelers", "families", "pet owners", "homeowners", "gamers", "cooks", "DIY enthusiasts", + "musicians", "artists", + }, + + "dimension": { + "small", "medium", "large", "extra-large", "compact", "lightweight", + "heavy", "mini", "standard", "oversized", + }, } diff --git a/product.go b/product.go index f0f8ea76..2cc7e029 100644 --- a/product.go +++ b/product.go @@ -14,6 +14,11 @@ type ProductInfo struct { Color string `json:"color" xml:"color"` Material string `json:"material" xml:"material"` UPC string `json:"upc" xml:"upc"` + Audience []string `json:"audience" xml:"audience"` + Dimension string `json:"dimension" xml:"dimension"` + UseCase string `json:"use_case" xml:"use_case"` + Benefit string `json:"benefit" xml:"benefit"` + Suffix string `json:"suffix" xml:"suffix"` } // Product will generate a random set of product information @@ -46,6 +51,11 @@ func product(f *Faker) *ProductInfo { Features: features, Color: safeColor(f), Material: productMaterial(f), + Audience: productAudience(f), + Dimension: productDimension(f), + UseCase: productUseCase(f), + Benefit: productBenefit(f), + Suffix: productSuffix(f), } return product @@ -157,6 +167,60 @@ func productUPC(f *Faker) string { return upc } +// ProductAudience will generate a random target audience +func ProductAudience() []string { return productAudience(GlobalFaker) } + +// ProductAudience will generate a random target audience +func (f *Faker) ProductAudience() []string { return productAudience(f) } + +func productAudience(f *Faker) []string { + targetAudiences := []string{} + for i := 0; i < number(f, 1, 2); i++ { + targetAudiences = append(targetAudiences, getRandValue(f, []string{"product", "target_audience"})) + } + return targetAudiences +} + +// ProductDimension will generate a random product dimension +func ProductDimension() string { return productDimension(GlobalFaker) } + +// ProductDimension will generate a random product dimension +func (f *Faker) ProductDimension() string { return productDimension(f) } + +func productDimension(f *Faker) string { + return getRandValue(f, []string{"product", "dimension"}) +} + +// ProductUseCase will generate a random product use case +func ProductUseCase() string { return productUseCase(GlobalFaker) } + +// ProductUseCase will generate a random product use case +func (f *Faker) ProductUseCase() string { return productUseCase(f) } + +func productUseCase(f *Faker) string { + return getRandValue(f, []string{"product", "use_case"}) +} + +// ProductBenefit will generate a random product benefit +func ProductBenefit() string { return productBenefit(GlobalFaker) } + +// ProductBenefit will generate a random product benefit +func (f *Faker) ProductBenefit() string { return productBenefit(f) } + +func productBenefit(f *Faker) string { + return getRandValue(f, []string{"product", "benefit"}) +} + +// ProductSuffix will generate a random product suffix +func ProductSuffix() string { return productSuffix(GlobalFaker) } + +// ProductSuffix will generate a random product suffix +func (f *Faker) ProductSuffix() string { return productSuffix(f) } + +func productSuffix(f *Faker) string { + return getRandValue(f, []string{"product", "suffix"}) +} + func addProductLookup() { AddFuncLookup("product", Info{ Display: "Product", @@ -249,4 +313,59 @@ func addProductLookup() { return productUPC(f), nil }, }) + + AddFuncLookup("productaudience", Info{ + Display: "Product Audience", + Category: "product", + Description: "The group of people for whom the product is designed or intended", + Example: "adults", + Output: "[]string", + Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { + return productAudience(f), nil + }, + }) + + AddFuncLookup("productdimension", Info{ + Display: "Product Dimension", + Category: "product", + Description: "The size or dimension of a product", + Example: "medium", + Output: "string", + Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { + return productDimension(f), nil + }, + }) + + AddFuncLookup("productusecase", Info{ + Display: "Product Use Case", + Category: "product", + Description: "The scenario or purpose for which a product is typically used", + Example: "home", + Output: "string", + Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { + return productUseCase(f), nil + }, + }) + + AddFuncLookup("productbenefit", Info{ + Display: "Product Benefit", + Category: "product", + Description: "The key advantage or value the product provides", + Example: "comfort", + Output: "string", + Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { + return productBenefit(f), nil + }, + }) + + AddFuncLookup("productsuffix", Info{ + Display: "Product Suffix", + Category: "product", + Description: "A suffix used to differentiate product models or versions", + Example: "pro", + Output: "string", + Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { + return productSuffix(f), nil + }, + }) } diff --git a/product_test.go b/product_test.go index 408cc281..9cc316b4 100644 --- a/product_test.go +++ b/product_test.go @@ -16,6 +16,11 @@ func ExampleProduct() { fmt.Println(product.Color) fmt.Println(product.Material) fmt.Println(product.UPC) + fmt.Println(product.Audience) + fmt.Println(product.Dimension) + fmt.Println(product.UseCase) + fmt.Println(product.Benefit) + fmt.Println(product.Suffix) // Output: Wave Precision Lamp // Since previously was that there a tennis occur why. Heels out can fire anyone sometimes. Leap whom troop now scarcely. @@ -25,6 +30,11 @@ func ExampleProduct() { // green // brass // 082447816155 + // [seniors] + // compact + // learning + // minimal maintenance + // dash } func ExampleFaker_Product() { @@ -38,6 +48,11 @@ func ExampleFaker_Product() { fmt.Println(product.Color) fmt.Println(product.Material) fmt.Println(product.UPC) + fmt.Println(product.Audience) + fmt.Println(product.Dimension) + fmt.Println(product.UseCase) + fmt.Println(product.Benefit) + fmt.Println(product.Suffix) // Output: Wave Precision Lamp // Since previously was that there a tennis occur why. Heels out can fire anyone sometimes. Leap whom troop now scarcely. @@ -47,6 +62,11 @@ func ExampleFaker_Product() { // green // brass // 082447816155 + // [seniors] + // compact + // learning + // minimal maintenance + // dash } func TestProduct(t *testing.T) { @@ -83,6 +103,26 @@ func TestProduct(t *testing.T) { if product.UPC == "" { t.Error("UPC is empty") } + + if len(product.Audience) == 0 { + t.Error("Audience is empty") + } + + if product.Dimension == "" { + t.Error("Dimension is empty") + } + + if len(product.UseCase) == 0 { + t.Error("UseCase is empty") + } + + if len(product.Benefit) == 0 { + t.Error("Benefit is empty") + } + + if product.Suffix == "" { + t.Error("Suffix is empty") + } } } @@ -211,3 +251,103 @@ func BenchmarkProductUPC(b *testing.B) { ProductUPC() } } + +func ExampleProductAudience() { + Seed(11) + fmt.Println(ProductAudience()) + + // Output: [DIY enthusiasts students] +} + +func ExampleFaker_ProductAudience() { + f := New(11) + fmt.Println(f.ProductAudience()) + + // Output: [DIY enthusiasts students] +} + +func BenchmarkProductAudience(b *testing.B) { + for i := 0; i < b.N; i++ { + ProductAudience() + } +} + +func ExampleProductDimension() { + Seed(11) + fmt.Println(ProductDimension()) + + // Output: standard +} + +func ExampleFaker_ProductDimension() { + f := New(11) + fmt.Println(f.ProductDimension()) + + // Output: standard +} + +func BenchmarkProductDimension(b *testing.B) { + for i := 0; i < b.N; i++ { + ProductDimension() + } +} + +func ExampleProductUseCase() { + Seed(11) + fmt.Println(ProductUseCase()) + + // Output: remote work +} + +func ExampleFaker_ProductUseCase() { + f := New(11) + fmt.Println(f.ProductUseCase()) + + // Output: remote work +} + +func BenchmarkProductUseCase(b *testing.B) { + for i := 0; i < b.N; i++ { + ProductUseCase() + } +} + +func ExampleProductBenefit() { + Seed(11) + fmt.Println(ProductBenefit()) + + // Output: minimal maintenance +} + +func ExampleFaker_ProductBenefit() { + f := New(11) + fmt.Println(f.ProductBenefit()) + + // Output: minimal maintenance +} + +func BenchmarkProductBenefit(b *testing.B) { + for i := 0; i < b.N; i++ { + ProductBenefit() + } +} + +func ExampleProductSuffix() { + Seed(11) + fmt.Println(ProductSuffix()) + + // Output: turbo +} + +func ExampleFaker_ProductSuffix() { + f := New(11) + fmt.Println(f.ProductSuffix()) + + // Output: turbo +} + +func BenchmarkProductSuffix(b *testing.B) { + for i := 0; i < b.N; i++ { + ProductSuffix() + } +} From 7afb47860675bbbc1c577263d9a6874fbb39ba90 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 20:41:18 -0500 Subject: [PATCH 3/5] product - added fields to exampel --- product.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/product.go b/product.go index 2cc7e029..1765a537 100644 --- a/product.go +++ b/product.go @@ -239,7 +239,14 @@ func addProductLookup() { ], "color": "navy", "material": "brass", - "upc": "012780949980" + "upc": "012780949980", + "audience": [ + "adults" + ], + "dimension": "medium", + "use_case": "home", + "benefit": "comfort", + "suffix": "pro" }`, Output: "map[string]any", ContentType: "application/json", From 577cd740d28abd6ed9cf37d4a1e70112be5fd095 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 20:45:04 -0500 Subject: [PATCH 4/5] readme - updated products --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 836a5e7b..246bb9c0 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,7 @@ FixedWidth(co *FixedWidthOptions) (string, error) ### Product + ```go Product() *ProductInfo ProductName() string @@ -394,6 +395,13 @@ ProductDescription() string ProductCategory() string ProductFeature() string ProductMaterial() string +ProductUPC() string +ProductAudience() string +ProductDimension() string +ProductUseCase() string +ProductBenefit() string +ProductSuffix() string + ``` ### Person From 59e0c2a9c154805748f21ed85d80d4aa14089c38 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 21:17:03 -0500 Subject: [PATCH 5/5] products - updated with better description --- data/product.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ product.go | 9 ++---- product_test.go | 55 ++++++++++++++++++++++--------------- 3 files changed, 108 insertions(+), 29 deletions(-) diff --git a/data/product.go b/data/product.go index 81abf060..cbe5b3a5 100644 --- a/data/product.go +++ b/data/product.go @@ -95,4 +95,77 @@ var Product = map[string][]string{ "small", "medium", "large", "extra-large", "compact", "lightweight", "heavy", "mini", "standard", "oversized", }, + + "description": { + "This {adjectivedescriptive} {productname} is perfect for {productusecase}, offering {productfeature} and {productbenefit}. Made from {productmaterial}, it's designed for {productaudience} who value {productbenefit}.", + "Introducing the {adjectivedescriptive} {productname} {productsuffix}, featuring {productfeature} technology and made from {productmaterial}. It ensures {productbenefit} for {productaudience}, making it ideal for {productusecase}.", + "Perfect for {productusecase}, the {productname} is crafted with {adjectivedescriptive} {productmaterial} and features {productfeature} for {productaudience}. Enjoy {productbenefit} every day.", + "Designed with {productaudience} in mind, this {adjectivedescriptive} {productname} offers {productbenefit}. It's equipped with {productfeature} and made from {productmaterial} for maximum {productbenefit}.", + "The {productname} {productsuffix} combines {adjectivedescriptive} design and {productmaterial} build to deliver {productfeature}. Its {productdimension} size makes it perfect for {productusecase} and ideal for {productaudience}.", + "With a focus on {productaudience}, the {productname} is built with {adjectivedescriptive} {productmaterial} for {productbenefit} and features {productfeature} to meet the needs of {productusecase}.", + "Experience the {productbenefit} of the {productname} {productsuffix}, made from {productmaterial} with a {adjectivedescriptive} design. It's ideal for {productusecase} and loved by {productaudience}.", + "Whether you're using it at {productusecase} or on the go, this {adjectivedescriptive} {productname} offers {productfeature} and ensures {productbenefit}. Crafted from {productmaterial}, it's perfect for {productaudience}.", + "The {productname} is a {adjectivedescriptive} solution for {productusecase}, featuring {productfeature} technology and built with {productmaterial} for {productbenefit}. Suitable for {productaudience}.", + "For {productaudience} who need {productbenefit}, the {productname} {productsuffix} delivers with {productfeature}, {adjectivedescriptive} design, and durable {productmaterial} construction. Ideal for {productusecase}.", + "Built with {adjectivedescriptive} {productmaterial}, this item is ideal for {productusecase} and provides {productaudience} with {productbenefit} through its {productfeature}.", + "Experience {productbenefit} with this {adjectivedescriptive} product, featuring {productfeature} and made from {productmaterial}, perfect for {productusecase}.", + "Designed for {productaudience}, this {adjectivedescriptive} product ensures {productbenefit} and is equipped with {productfeature} for the best {productusecase} experience.", + "For those who need {productbenefit}, this {adjectivedescriptive} product, made of {productmaterial}, offers {productfeature} and is perfect for {productusecase}.", + "Take your {productusecase} to the next level with this {adjectivedescriptive} product. Built from {productmaterial}, it features {productfeature} for {productaudience}.", + "Crafted from {productmaterial}, this product is ideal for {productaudience} seeking {productbenefit}. Its {adjectivedescriptive} design and {productfeature} make it perfect for {productusecase}.", + "This product, made with {productmaterial}, is designed for {productaudience} who value {productbenefit}. Its {adjectivedescriptive} design includes {productfeature}, making it ideal for {productusecase}.", + "Enjoy {productbenefit} with this {adjectivedescriptive} item, featuring {productfeature} technology. Made from {productmaterial}, it's perfect for {productusecase}.", + "With {productfeature} and {adjectivedescriptive} {productmaterial}, this product offers {productbenefit} for {productaudience}, ideal for {productusecase}.", + "The perfect solution for {productusecase}, this {adjectivedescriptive} product provides {productbenefit} with its {productfeature}, crafted from {productmaterial} for {productaudience}.", + "Built for {productaudience}, this product features {productfeature} and ensures {productbenefit}. Made from {productmaterial}, it's an {adjectivedescriptive} choice for {productusecase}.", + "Achieve {productbenefit} with this {adjectivedescriptive} product. Crafted from {productmaterial}, it features {productfeature}, perfect for {productaudience} during {productusecase}.", + "For {productaudience}, this {adjectivedescriptive} item offers {productfeature} and is made of {productmaterial}, providing {productbenefit} for {productusecase}.", + "This {adjectivedescriptive} product is crafted from {productmaterial} and includes {productfeature}, making it perfect for {productusecase} and delivering {productbenefit} for {productaudience}.", + "Featuring {productfeature} and made from {productmaterial}, this {adjectivedescriptive} product is ideal for {productaudience} looking for {productbenefit} in {productusecase}.", + "For {productusecase}, this {adjectivedescriptive} product provides {productbenefit} with its {productfeature}, crafted for {productaudience} from high-quality {productmaterial}.", + "This {adjectivedescriptive} product is perfect for {productaudience} who need {productbenefit}. Built from {productmaterial} and featuring {productfeature}, it's ideal for {productusecase}.", + "Delivering {productbenefit}, this product is made from {productmaterial} and designed for {productaudience}. Its {adjectivedescriptive} design includes {productfeature}, perfect for {productusecase}.", + "For those interested in {productusecase}, this {adjectivedescriptive} product offers {productfeature} and is made of {productmaterial} to provide {productbenefit} for {productaudience}.", + "This product is crafted for {productaudience}, featuring {adjectivedescriptive} {productmaterial} and equipped with {productfeature} to ensure {productbenefit} during {productusecase}.", + "Transform your {productusecase} with this {adjectivedescriptive} product, featuring {productfeature} and made from high-quality {productmaterial} to provide {productbenefit}.", + "This {adjectivedescriptive} item, built for {productaudience}, uses {productfeature} technology to deliver {productbenefit} during {productusecase}.", + "Enjoy the luxury of {productbenefit} with this product, crafted from {productmaterial}. Its {adjectivedescriptive} design and {productfeature} make it ideal for {productusecase}.", + "Made from {productmaterial} and designed with {productaudience} in mind, this product offers {productbenefit} and features {productfeature} for excellent {productusecase}.", + "Achieve seamless {productusecase} with this {adjectivedescriptive} product. Built using {productmaterial}, it delivers {productbenefit} with the help of {productfeature}.", + "This product, made for {productaudience}, offers {productbenefit} with its {adjectivedescriptive} {productmaterial} build and advanced {productfeature}, perfect for {productusecase}.", + "Built with {productmaterial}, this {adjectivedescriptive} product is designed to provide {productbenefit} for {productaudience} through its {productfeature}, ideal for {productusecase}.", + "Elevate your {productusecase} experience with this {adjectivedescriptive} product, made from {productmaterial} and offering {productfeature} to ensure {productbenefit}.", + "Perfect for {productaudience} who value {productbenefit}, this product features {productfeature} and is crafted from {adjectivedescriptive} {productmaterial}, ideal for {productusecase}.", + "With a focus on {productusecase}, this {adjectivedescriptive} product, made from {productmaterial}, ensures {productbenefit} with its {productfeature} for {productaudience}.", + "Whether for {productusecase} or everyday use, this product delivers {productbenefit} with its {adjectivedescriptive} {productmaterial} construction and {productfeature}, crafted for {productaudience}.", + "This {adjectivedescriptive} product is perfect for {productusecase}, made with {productmaterial} and offering {productfeature} to ensure {productbenefit} for {productaudience}.", + "Featuring state-of-the-art {productfeature}, this product is designed from {productmaterial} to deliver {productbenefit} for {productaudience}, ideal for {productusecase}.", + "For {productusecase}, this {adjectivedescriptive} product is crafted from {productmaterial} to provide {productfeature}, ensuring {productbenefit} for {productaudience}.", + "Built for {productaudience}, this item features {adjectivedescriptive} {productmaterial} and advanced {productfeature} to deliver {productbenefit} during {productusecase}.", + "With {productfeature} and a {adjectivedescriptive} design, this product is made from {productmaterial} to provide {productbenefit} for {productaudience}, ideal for {productusecase}.", + "This {adjectivedescriptive} item, crafted from {productmaterial}, offers {productfeature} for {productusecase}, ensuring {productbenefit} for {productaudience}.", + "For those who value {productbenefit}, this product, made from {productmaterial}, includes {productfeature} and is perfect for {productusecase}, designed for {productaudience}.", + "Achieve superior {productusecase} with this product, featuring {productfeature} and made from {adjectivedescriptive} {productmaterial}, offering {productbenefit} to {productaudience}.", + "Delivering {productbenefit}, this product is crafted from {productmaterial} and equipped with {productfeature}, making it ideal for {productaudience} during {productusecase}.", + "Revolutionize your {productusecase} with this {adjectivedescriptive} item, featuring {productfeature} and crafted from {productmaterial} for {productaudience} seeking {productbenefit}.", + "This {adjectivedescriptive} item, designed for {productaudience}, is built from {productmaterial} and includes {productfeature} to ensure {productbenefit} for {productusecase}.", + "Enjoy enhanced {productusecase} with this product, featuring {productfeature} and made with {adjectivedescriptive} {productmaterial}, delivering {productbenefit}.", + "Perfect for {productaudience}, this {adjectivedescriptive} product includes {productfeature} and is crafted from {productmaterial} to provide {productbenefit} during {productusecase}.", + "Take your {productusecase} to new heights with this product, made from {productmaterial} and featuring {productfeature} for {productaudience} who value {productbenefit}.", + "Crafted from premium {productmaterial}, this item is designed for {productaudience} to provide {productbenefit} with its {adjectivedescriptive} build and {productfeature}.", + "This {adjectivedescriptive} product, made from {productmaterial}, offers {productbenefit} through its {productfeature}, ideal for {productaudience} engaging in {productusecase}.", + "Elevate your {productusecase} with this {adjectivedescriptive} product. It features {productfeature} and is crafted from {productmaterial} for {productaudience}.", + "Designed for {productaudience}, this product includes {productfeature} and a {adjectivedescriptive} {productmaterial} construction, ensuring {productbenefit} during {productusecase}.", + "This {adjectivedescriptive} item, featuring {productfeature}, is crafted from {productmaterial} to provide {productbenefit} for {productusecase}, perfect for {productaudience}.", + "Achieve exceptional {productusecase} with this product, featuring advanced {productfeature} and made from durable {productmaterial}, delivering {productbenefit} for {productaudience}.", + "Whether it's for {productusecase} or daily use, this {adjectivedescriptive} item is crafted from {productmaterial} and offers {productfeature} to deliver {productbenefit} for {productaudience}.", + "This product, ideal for {productaudience}, features {adjectivedescriptive} {productmaterial} and incorporates {productfeature} to ensure {productbenefit} during {productusecase}.", + "Built with {productmaterial}, this {adjectivedescriptive} item is perfect for {productusecase} and features {productfeature} to provide {productbenefit} to {productaudience}.", + "With {productfeature} and made from {adjectivedescriptive} {productmaterial}, this product ensures {productbenefit} for {productaudience}, ideal for {productusecase}.", + "This {adjectivedescriptive} item is built for {productaudience}, providing {productbenefit} with its {productmaterial} construction and advanced {productfeature}, perfect for {productusecase}.", + "For {productusecase}, this product delivers {productbenefit} to {productaudience} with its {adjectivedescriptive} design and {productfeature}, made from quality {productmaterial}.", + "Experience the benefits of {productfeature} with this {adjectivedescriptive} item, crafted from {productmaterial} and ideal for {productaudience} seeking {productbenefit} during {productusecase}.", + "This {adjectivedescriptive} product is crafted from {productmaterial} and includes {productfeature}, making it perfect for {productusecase} and providing {productbenefit} for {productaudience}.", + "For those who value {productbenefit}, this product is made from {productmaterial} and features {adjectivedescriptive} {productfeature}, ideal for {productaudience} during {productusecase}.", + }, } diff --git a/product.go b/product.go index 1765a537..3179cc33 100644 --- a/product.go +++ b/product.go @@ -2,7 +2,6 @@ package gofakeit import ( "fmt" - "strings" ) type ProductInfo struct { @@ -110,12 +109,8 @@ func ProductDescription() string { return productDescription(GlobalFaker) } func (f *Faker) ProductDescription() string { return productDescription(f) } func productDescription(f *Faker) string { - desc := []string{} - for i := 0; i < number(f, 1, 3); i++ { - desc = append(desc, sentence(f, number(f, 5, 15))) - } - - return strings.Join(desc, " ") + desc, _ := generate(f, getRandValue(f, []string{"product", "description"})) + return desc } // ProductCategory will generate a random product category diff --git a/product_test.go b/product_test.go index 9cc316b4..7f5b0e49 100644 --- a/product_test.go +++ b/product_test.go @@ -2,6 +2,7 @@ package gofakeit import ( "fmt" + "strings" "testing" ) @@ -23,18 +24,18 @@ func ExampleProduct() { fmt.Println(product.Suffix) // Output: Wave Precision Lamp - // Since previously was that there a tennis occur why. Heels out can fire anyone sometimes. Leap whom troop now scarcely. + // This grieving product is crafted from rubber and includes ultra-lightweight, making it perfect for professional work and delivering improved productivity for [athletes]. // [cosmetics outdoor gear] - // 49.18 + // 32.91 // [touchscreen ultra-lightweight gps-enabled biometric] - // green - // brass - // 082447816155 - // [seniors] - // compact - // learning - // minimal maintenance - // dash + // blue + // felt + // 009410268940 + // [pet owners gamers] + // oversized + // office + // customizability + // nexus } func ExampleFaker_Product() { @@ -55,18 +56,18 @@ func ExampleFaker_Product() { fmt.Println(product.Suffix) // Output: Wave Precision Lamp - // Since previously was that there a tennis occur why. Heels out can fire anyone sometimes. Leap whom troop now scarcely. + // This grieving product is crafted from rubber and includes ultra-lightweight, making it perfect for professional work and delivering improved productivity for [athletes]. // [cosmetics outdoor gear] - // 49.18 + // 32.91 // [touchscreen ultra-lightweight gps-enabled biometric] - // green - // brass - // 082447816155 - // [seniors] - // compact - // learning - // minimal maintenance - // dash + // blue + // felt + // 009410268940 + // [pet owners gamers] + // oversized + // office + // customizability + // nexus } func TestProduct(t *testing.T) { @@ -156,14 +157,24 @@ func ExampleProductDescription() { Seed(11) fmt.Println(ProductDescription()) - // Output: Regularly quiver these sprint fight something am elsewhere since previously was that there a. Occur why depend heels out can fire anyone sometimes that leap whom troop now. + // Output: This product, ideal for [seniors families], features puzzled gold and incorporates gps-enabled to ensure robust construction during remote work. } func ExampleFaker_ProductDescription() { f := New(11) fmt.Println(f.ProductDescription()) - // Output: Regularly quiver these sprint fight something am elsewhere since previously was that there a. Occur why depend heels out can fire anyone sometimes that leap whom troop now. + // Output: This product, ideal for [seniors families], features puzzled gold and incorporates gps-enabled to ensure robust construction during remote work. +} + +// Runs 10,000 tests to ensure description doesnt have any { or } in it +func TestProductDescriptionReplacement(t *testing.T) { + for i := 0; i < 100000; i++ { + desc := ProductDescription() + if strings.ContainsAny(desc, "{") || strings.ContainsAny(desc, "}") { + t.Error("Description contains { or }") + } + } } func BenchmarkProductDescription(b *testing.B) {