v / vlib / strings / lorem / lorem_test.v
66 lines · 60 sloc · 1.38 KB · 7677d768bb3954fde7c1523f34d894e44856492c
Raw
1module lorem
2
3fn test_lorem_generate_basic() {
4 output := generate(LoremCfg{
5 paragraphs: 2
6 sentences_per_paragraph: 3
7 words_per_sentence: 5
8 })
9 assert output.len > 0
10 // 2 paragraphs should be separated by "\n\n"
11 assert output.count('\n\n') == 1
12}
13
14fn test_lorem_generate_deterministic() {
15 cfg := LoremCfg{
16 rng_seed: 12345
17 paragraphs: 1
18 }
19 out1 := generate(cfg)
20 out2 := generate(cfg)
21 assert out1 == out2
22}
23
24fn test_lorem_generate_counts() {
25 cfg := LoremCfg{
26 paragraphs: 3
27 }
28 output := generate(cfg)
29 // There should be 2 separators for 3 paragraphs
30 assert output.count('\n\n') == 2
31}
32
33fn test_lorem_custom_corpus() {
34 // 'bard' is shakespeare
35 cfg := LoremCfg{
36 corpus_name: 'bard'
37 rng_seed: 999
38 paragraphs: 1
39 }
40 output := generate(cfg)
41 assert output.len > 0
42 // Hard to check exact content due to randomness, but it should not crash
43}
44
45fn test_lorem_vary() {
46 // lorem_vary is private, effectively testing internal logic
47 // base 10, min 5
48 // delta = 10 * 0.2 = 2
49 // range = [-2, 2]
50 // result = 10 + [-2, 2] -> [8, 12]
51 // We can't guarantee a specific value, but we can check bounds
52 mut rng := LorumRNG{
53 seed: 12345
54 }
55 for _ in 0 .. 100 {
56 val := lorem_vary(mut rng, 10, 5)
57 assert val >= 8
58 assert val <= 12
59 }
60}
61
62fn test_lorem_tokenize() {
63 text := 'Hello\nWorld Test'
64 tokens := lorem_tokenize(text)
65 assert tokens == ['Hello', 'World', 'Test']
66}
67