v
Зеркало из https://github.com/vlang/v
1module json2
2
3import time
4
5const fixed_time = time.new(
6year: 2022
7month: 3
8day: 11
9hour: 13
10minute: 54
11second: 25
12)
13
14type StringAlias = string
15type BoolAlias = bool
16type IntAlias = int
17type TimeAlias = time.Time
18type StructAlias = StructType[int]
19type EnumAlias = Enumerates
20
21type SumTypes = StructType[string] | []SumTypes | []string | bool | int | string | time.Time
22
23enum Enumerates {
24a
25b
26c
27d
28e = 99
29f
30}
31
32struct StructType[T] {
33mut:
34val T
35}
36
37struct StructTypeOption[T] {
38mut:
39val ?T
40}
41
42struct StructTypePointer[T] {
43mut:
44val &T
45}
46
47fn count_test[T](value T) {
48mut count := Count{0}
49
50count.count_chars(value)
51assert encode(value).len == count.get_total()
52}
53
54fn test_empty() {
55count_test(map[string]string{})
56
57count_test([]string{})
58
59count_test(StructType[bool]{})
60
61count_test(map[string]string{})
62}
63
64fn test_types() {
65count_test(StructType[string]{})
66
67count_test(StructType[string]{ val: '' })
68
69count_test(StructType[string]{ val: 'abcd' })
70
71count_test(StructType[bool]{ val: false })
72
73count_test(StructType[bool]{ val: true })
74
75count_test(StructType[int]{ val: 26 })
76
77count_test(StructType[int]{ val: 1 })
78
79count_test(StructType[int]{ val: -125 })
80
81count_test(StructType[u64]{ val: u64(-1) })
82
83count_test(StructType[time.Time]{})
84
85count_test(StructType[time.Time]{ val: fixed_time })
86
87count_test(StructType[StructType[int]]{
88val: StructType[int]{
89val: 1
90}
91})
92
93count_test(StructType[Enumerates]{})
94count_test(StructType[Enumerates]{})
95count_test(StructType[Enumerates]{ val: Enumerates.f })
96count_test(StructType[[]int]{})
97count_test(StructType[[]int]{ val: [0] })
98count_test(StructType[[]int]{ val: [0, 1, 0, 2, 3, 2, 5, 1] })
99}
100