forked from flyingmutant/rapid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_example_go121_test.go
143 lines (123 loc) · 2.75 KB
/
strings_example_go121_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2023 Gregory Petrosyan <pgregory@pgregory.net>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//go:build go1.21
package rapid_test
import (
"fmt"
"unicode"
"github.com/MadTyres/rapid"
)
func ExampleRune() {
gen := rapid.Rune()
for i := 0; i < 25; i++ {
if i%5 == 0 {
fmt.Println()
} else {
fmt.Print(" ")
}
fmt.Printf("%q", gen.Example(i))
}
// Output:
// '\n' '\x1b' 'A' 'a' '*'
// '0' '@' '?' '\'' '\ue05d'
// '<' '%' '!' '\u0604' 'A'
// '%' '╷' '~' '!' '/'
// '\u00ad' '𝅾' '@' '҈' ' '
}
func ExampleRuneFrom() {
gens := []*rapid.Generator[rune]{
rapid.RuneFrom([]rune{'A', 'B', 'C'}),
rapid.RuneFrom(nil, unicode.Cyrillic, unicode.Greek),
rapid.RuneFrom([]rune{'⌘'}, &unicode.RangeTable{
R32: []unicode.Range32{{0x1F600, 0x1F64F, 1}},
}),
}
for _, gen := range gens {
for i := 0; i < 5; i++ {
if i > 0 {
fmt.Print(" ")
}
fmt.Printf("%q", gen.Example(i))
}
fmt.Println()
}
// Output:
// 'A' 'A' 'A' 'B' 'A'
// 'Ͱ' 'Ѥ' 'Ͱ' 'ͱ' 'Ϳ'
// '😀' '⌘' '😀' '😁' '😋'
}
func ExampleString() {
gen := rapid.String()
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "\n߾⃝?\rA�֍"
// "\u2006𑨳"
// "A$\u0603ᾢ"
// "+^#.[#৲"
// ""
}
func ExampleStringOf() {
gen := rapid.StringOf(rapid.RuneFrom(nil, unicode.Tibetan))
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "༁༭༇ཬ༆༐༖ༀྸ༁༆༎ༀ༁ཱི༂༨ༀ༂"
// "༂༁ༀ༂༴ༀ༁ྵ"
// "ༀ༴༁༅ན༃༁༎ྼ༄༽"
// "༎༂༎ༀༀༀཌྷ༂ༀྥ"
// ""
}
func ExampleStringN() {
gen := rapid.StringN(5, 5, -1)
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "\n߾⃝?\r"
// "\u2006𑨳#`\x1b"
// "A$\u0603ᾢÉ"
// "+^#.["
// ".A<a¤"
}
func ExampleStringOfN() {
gen := rapid.StringOfN(rapid.RuneFrom(nil, unicode.ASCII_Hex_Digit), 6, 6, -1)
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "1D7B6a"
// "2102e0"
// "0e15c3"
// "E2E000"
// "aEd623"
}
func ExampleStringMatching() {
gen := rapid.StringMatching(`\(?([0-9]{3})\)?([ .-]?)([0-9]{3})([ .-]?)([0-9]{4})`)
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "(532) 649-9610"
// "901)-5783983"
// "914.444.1575"
// "(316 696.3584"
// "816)0861080"
}
func ExampleSliceOfBytesMatching() {
gen := rapid.SliceOfBytesMatching(`[CAGT]+`)
for i := 0; i < 5; i++ {
fmt.Printf("%q\n", gen.Example(i))
}
// Output:
// "CCTTGAGAGCGATACGGAAG"
// "GCAGAACT"
// "AACCGTCGAG"
// "GGGAAAAGAT"
// "AGTG"
}