v

Зеркало из https://github.com/vlang/v
Форк
0
/x
/
count_test.v 
99 строк · 1.6 Кб
1
module json2
2

3
import time
4

5
const fixed_time = time.new(
6
	year:   2022
7
	month:  3
8
	day:    11
9
	hour:   13
10
	minute: 54
11
	second: 25
12
)
13

14
type StringAlias = string
15
type BoolAlias = bool
16
type IntAlias = int
17
type TimeAlias = time.Time
18
type StructAlias = StructType[int]
19
type EnumAlias = Enumerates
20

21
type SumTypes = StructType[string] | []SumTypes | []string | bool | int | string | time.Time
22

23
enum Enumerates {
24
	a
25
	b
26
	c
27
	d
28
	e = 99
29
	f
30
}
31

32
struct StructType[T] {
33
mut:
34
	val T
35
}
36

37
struct StructTypeOption[T] {
38
mut:
39
	val ?T
40
}
41

42
struct StructTypePointer[T] {
43
mut:
44
	val &T
45
}
46

47
fn count_test[T](value T) {
48
	mut count := Count{0}
49

50
	count.count_chars(value)
51
	assert encode(value).len == count.get_total()
52
}
53

54
fn test_empty() {
55
	count_test(map[string]string{})
56

57
	count_test([]string{})
58

59
	count_test(StructType[bool]{})
60

61
	count_test(map[string]string{})
62
}
63

64
fn test_types() {
65
	count_test(StructType[string]{})
66

67
	count_test(StructType[string]{ val: '' })
68

69
	count_test(StructType[string]{ val: 'abcd' })
70

71
	count_test(StructType[bool]{ val: false })
72

73
	count_test(StructType[bool]{ val: true })
74

75
	count_test(StructType[int]{ val: 26 })
76

77
	count_test(StructType[int]{ val: 1 })
78

79
	count_test(StructType[int]{ val: -125 })
80

81
	count_test(StructType[u64]{ val: u64(-1) })
82

83
	count_test(StructType[time.Time]{})
84

85
	count_test(StructType[time.Time]{ val: fixed_time })
86

87
	count_test(StructType[StructType[int]]{
88
		val: StructType[int]{
89
			val: 1
90
		}
91
	})
92

93
	count_test(StructType[Enumerates]{})
94
	count_test(StructType[Enumerates]{})
95
	count_test(StructType[Enumerates]{ val: Enumerates.f })
96
	count_test(StructType[[]int]{})
97
	count_test(StructType[[]int]{ val: [0] })
98
	count_test(StructType[[]int]{ val: [0, 1, 0, 2, 3, 2, 5, 1] })
99
}
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.