From 39372efb1272ea96a1a75cc3abfaf79cdb8204f6 Mon Sep 17 00:00:00 2001 From: brianvoe Date: Fri, 25 Oct 2024 21:36:59 -0500 Subject: [PATCH] product - fixed product description --- product.go | 10 +++++++++- product_test.go | 44 ++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/product.go b/product.go index 63dfd73f..23f8c8b7 100644 --- a/product.go +++ b/product.go @@ -2,6 +2,7 @@ package gofakeit import ( "fmt" + "strings" ) type ProductInfo struct { @@ -109,7 +110,14 @@ func ProductDescription() string { return productDescription(GlobalFaker) } func (f *Faker) ProductDescription() string { return productDescription(f) } func productDescription(f *Faker) string { - desc, _ := generate(f, getRandValue(f, []string{"product", "description"})) + prodDesc := getRandValue(f, []string{"product", "description"}) + + // Replace all {productaudience} with join "and" + for strings.Contains(prodDesc, "{productaudience}") { + prodDesc = strings.Replace(prodDesc, "{productaudience}", strings.Join(productAudience(f), " and "), 1) + } + + desc, _ := generate(f, prodDesc) return desc } diff --git a/product_test.go b/product_test.go index 7f5b0e49..4766e378 100644 --- a/product_test.go +++ b/product_test.go @@ -24,18 +24,18 @@ func ExampleProduct() { fmt.Println(product.Suffix) // Output: Wave Precision Lamp - // This grieving product is crafted from rubber and includes ultra-lightweight, making it perfect for professional work and delivering improved productivity for [athletes]. + // This upset product is crafted from wood and includes wireless, making it perfect for personal grooming and delivering comfort for travelers and professionals. // [cosmetics outdoor gear] - // 32.91 + // 73.93 // [touchscreen ultra-lightweight gps-enabled biometric] - // blue - // felt - // 009410268940 - // [pet owners gamers] - // oversized - // office - // customizability - // nexus + // maroon + // silver + // 041026894059 + // [gamers musicians] + // heavy + // learning + // efficiency + // dash } func ExampleFaker_Product() { @@ -56,18 +56,18 @@ func ExampleFaker_Product() { fmt.Println(product.Suffix) // Output: Wave Precision Lamp - // This grieving product is crafted from rubber and includes ultra-lightweight, making it perfect for professional work and delivering improved productivity for [athletes]. + // This upset product is crafted from wood and includes wireless, making it perfect for personal grooming and delivering comfort for travelers and professionals. // [cosmetics outdoor gear] - // 32.91 + // 73.93 // [touchscreen ultra-lightweight gps-enabled biometric] - // blue - // felt - // 009410268940 - // [pet owners gamers] - // oversized - // office - // customizability - // nexus + // maroon + // silver + // 041026894059 + // [gamers musicians] + // heavy + // learning + // efficiency + // dash } func TestProduct(t *testing.T) { @@ -157,14 +157,14 @@ func ExampleProductDescription() { Seed(11) fmt.Println(ProductDescription()) - // Output: This product, ideal for [seniors families], features puzzled gold and incorporates gps-enabled to ensure robust construction during remote work. + // Output: This product, ideal for seniors and 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: This product, ideal for [seniors families], features puzzled gold and incorporates gps-enabled to ensure robust construction during remote work. + // Output: This product, ideal for seniors and 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