packages
The Louise packages, each released on its own
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#35 · main · 4 min 07 s
0Étoiles
0Forks
3Issues
| 1 | // Fake data: words, sentences, names, emails and URLs, plausible enough to |
| 2 | // read in a failing test and the same for a seed. |
| 3 | |
| 4 | import fake |
| 5 | import std/list |
| 6 | import std/random.{type random} |
| 7 | import std/string |
| 8 | import std/test.{assert, assert_equal} |
| 9 | |
| 10 | fn sample :: generate: fn() -> a / <random> -> List<a> |
| 11 | { |
| 12 | random.with_seed 3 fn { list.map (list.range 1 100) fn _ { generate () } } |
| 13 | } |
| 14 | |
| 15 | fn lowercase :: text: String -> Bool |
| 16 | { |
| 17 | string.to_lower text == text |
| 18 | } |
| 19 | |
| 20 | @test |
| 21 | fn words_are_lowercase_letters :: |
| 22 | { |
| 23 | let words = sample fake.word |
| 24 | assert |
| 25 | (list.all words fn w { w != "" && lowercase w && !string.contains w " " }) |
| 26 | "one word" |
| 27 | } |
| 28 | |
| 29 | @test |
| 30 | fn words_keep_to_their_count :: |
| 31 | { |
| 32 | let texts = sample fn { fake.words ~min: 2 ~max: 4 } |
| 33 | assert |
| 34 | ( list.all |
| 35 | texts |
| 36 | fn t |
| 37 | { |
| 38 | let n = list.length (string.split t " ") |
| 39 | n >= 2 && n <= 4 |
| 40 | } |
| 41 | ) |
| 42 | "2 to 4 words" |
| 43 | } |
| 44 | |
| 45 | @test |
| 46 | fn a_sentence_ends_with_a_period :: |
| 47 | { |
| 48 | assert |
| 49 | (list.all (sample fake.sentence) fn s { string.ends_with s "." }) |
| 50 | "a period" |
| 51 | } |
| 52 | |
| 53 | @test |
| 54 | fn a_paragraph_is_sentences :: |
| 55 | { |
| 56 | assert |
| 57 | ( list.all |
| 58 | (sample fake.paragraph) |
| 59 | fn p { string.ends_with p "." && string.contains p ". " } |
| 60 | ) |
| 61 | "two or more sentences" |
| 62 | } |
| 63 | |
| 64 | @test |
| 65 | fn an_email_has_a_name_and_a_domain :: |
| 66 | { |
| 67 | assert |
| 68 | ( list.all |
| 69 | (sample fake.email) |
| 70 | fn e |
| 71 | { |
| 72 | lowercase e && string.ends_with e "@example.com" |
| 73 | && !string.contains e " " |
| 74 | } |
| 75 | ) |
| 76 | "name@example.com" |
| 77 | } |
| 78 | |
| 79 | @test |
| 80 | fn a_url_is_https_with_a_slug :: |
| 81 | { |
| 82 | assert |
| 83 | ( list.all |
| 84 | (sample fake.url) |
| 85 | fn u |
| 86 | { |
| 87 | string.starts_with u "https://example.com/" && !string.contains u " " |
| 88 | } |
| 89 | ) |
| 90 | "https://example.com/slug" |
| 91 | } |
| 92 | |
| 93 | @test |
| 94 | fn names_are_capitalised :: |
| 95 | { |
| 96 | let names = sample fake.full_name |
| 97 | assert |
| 98 | (list.all names fn n { list.length (string.split n " ") == 2 }) |
| 99 | "first and last" |
| 100 | assert (list.all names fn n { !lowercase n }) "capitalised" |
| 101 | } |
| 102 | |
| 103 | @test |
| 104 | fn a_seed_gives_the_same_data :: |
| 105 | { |
| 106 | assert_equal (sample fake.sentence) (sample fake.sentence) |
| 107 | } |