Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ randomdata is a tiny help suite for generating random data such as
* random full profile
* random date inside range
* random phone number
* random lorem ipsum words

## Installation

Expand Down Expand Up @@ -181,6 +182,9 @@ func main() {
fmt.Println(randomdata.ProvinceForCountry("GB"))
// Get a random country-localised province for USA
fmt.Println(randomdata.ProvinceForCountry("US"))

// Get 5 random lorem ipsum words
fmt.Println(randomdata.LoremIpsumWords(5))
}

```
Expand Down
100 changes: 99 additions & 1 deletion jsondata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2892,5 +2892,103 @@ var data = []byte(`{
"Park",
"Gate",
"Court"
]
],
"loremIpsumWords": [
"lorem",
"ipsum",
"semper",
"habeo",
"duo",
"ut",
"vis",
"aliquyam",
"eu",
"splendide",
"Ut",
"mei",
"eteu",
"nec",
"antiopam",
"corpora",
"kasd",
"pretium",
"cetero",
"qui",
"arcu",
"assentior",
"ei",
"his",
"usu",
"invidunt",
"kasd",
"justo",
"ne",
"eleifend",
"per",
"ut",
"eam",
"graeci",
"tincidunt",
"impedit",
"temporibus",
"duo",
"et",
"facilisis",
"insolens",
"consequat",
"cursus",
"partiendo",
"ullamcorper",
"Vulputate",
"facilisi",
"donec",
"aliquam",
"labore",
"inimicus",
"voluptua",
"penatibus",
"sea",
"vel",
"amet",
"his",
"ius",
"audire",
"in",
"mea",
"repudiandae",
"nullam",
"sed",
"assentior",
"takimata",
"eos",
"at",
"odio",
"consequat",
"iusto",
"imperdiet",
"dicunt",
"abhorreant",
"adipisci",
"officiis",
"rhoncus",
"leo",
"dicta",
"vitae",
"clita",
"elementum",
"mauris",
"definiebas",
"uonsetetur",
"te",
"inimicus",
"nec",
"mus",
"usu",
"duo",
"aenean",
"corrumpit",
"aliquyam",
"est",
"eum"
]
}`)
15 changes: 15 additions & 0 deletions random_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type jsonContent struct {
ProvincesGB []string `json:"provincesGB"`
StreetNameGB []string `json:"streetNameGB"`
StreetTypesGB []string `json:"streetTypesGB"`
LoremIpsumWords []string `json:"loremIpsumWords"`
}

type pRand struct {
Expand Down Expand Up @@ -441,3 +442,17 @@ func PhoneNumber() string {
str += " " + Digits(privateRand.Intn(remaining-1)+1)
}
}

func LoremIpsumWords(length int) string {
if length <= 1 {
return randomFrom(jsonData.LoremIpsumWords)
}

// Needs to start with lorem
result := "Lorem"
for i := 0; i < length-1; i++ {
result += " " + randomFrom(jsonData.LoremIpsumWords)
}

return result
}
16 changes: 16 additions & 0 deletions random_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,19 @@ func TestStreetForCountry(t *testing.T) {
t.Errorf("did not return empty street for unknown country")
}
}

func TestLoremIpsumWords(t *testing.T) {
expectedLen := Number(5)
loremIpsumWords := strings.Split(LoremIpsumWords(expectedLen), " ")

if expectedLen != len(loremIpsumWords) {
t.Errorf("expected %d words, got %d insted: %s", expectedLen, len(loremIpsumWords), loremIpsumWords)
}

for _, w := range loremIpsumWords {
w = strings.ToLower(w)
if !findInSlice(jsonData.LoremIpsumWords, w) {
t.Errorf("%s is not in the lorem ipsum word list", w)
}
}
}