// Fake data: words, sentences, names, emails and URLs, plausible enough to // read in a failing test and the same for a seed. import fake import std/list import std/random.{type random} import std/string import std/test.{assert, assert_equal} fn sample :: generate: fn() -> a / -> List { random.with_seed 3 fn { list.map (list.range 1 100) fn _ { generate () } } } fn lowercase :: text: String -> Bool { string.to_lower text == text } @test fn words_are_lowercase_letters :: { let words = sample fake.word assert (list.all words fn w { w != "" && lowercase w && !string.contains w " " }) "one word" } @test fn words_keep_to_their_count :: { let texts = sample fn { fake.words ~min: 2 ~max: 4 } assert ( list.all texts fn t { let n = list.length (string.split t " ") n >= 2 && n <= 4 } ) "2 to 4 words" } @test fn a_sentence_ends_with_a_period :: { assert (list.all (sample fake.sentence) fn s { string.ends_with s "." }) "a period" } @test fn a_paragraph_is_sentences :: { assert ( list.all (sample fake.paragraph) fn p { string.ends_with p "." && string.contains p ". " } ) "two or more sentences" } @test fn an_email_has_a_name_and_a_domain :: { assert ( list.all (sample fake.email) fn e { lowercase e && string.ends_with e "@example.com" && !string.contains e " " } ) "name@example.com" } @test fn a_url_is_https_with_a_slug :: { assert ( list.all (sample fake.url) fn u { string.starts_with u "https://example.com/" && !string.contains u " " } ) "https://example.com/slug" } @test fn names_are_capitalised :: { let names = sample fake.full_name assert (list.all names fn n { list.length (string.split n " ") == 2 }) "first and last" assert (list.all names fn n { !lowercase n }) "capitalised" } @test fn a_seed_gives_the_same_data :: { assert_equal (sample fake.sentence) (sample fake.sentence) }