diff --git a/README.md b/README.md index 0508e76..41fc9ec 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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)) } ``` diff --git a/jsondata.go b/jsondata.go index a42e5db..248e721 100644 --- a/jsondata.go +++ b/jsondata.go @@ -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" + ] }`) diff --git a/random_data.go b/random_data.go index 13031f3..a29b298 100644 --- a/random_data.go +++ b/random_data.go @@ -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 { @@ -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 +} diff --git a/random_data_test.go b/random_data_test.go index d97bb46..cdc9311 100644 --- a/random_data_test.go +++ b/random_data_test.go @@ -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) + } + } +}