Skip to content

Commit

Permalink
product - fixed product description
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Oct 26, 2024
1 parent 70cb028 commit 39372ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
10 changes: 9 additions & 1 deletion product.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gofakeit

import (
"fmt"
"strings"
)

type ProductInfo struct {
Expand Down Expand Up @@ -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
}

Expand Down
44 changes: 22 additions & 22 deletions product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39372ef

Please sign in to comment.