/
tests.go
105 lines (86 loc) · 1.58 KB
/
tests.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
// Original work Copyright (c) 2016 Jonas Obrist (https://github.com/ojii/gettext.go)
// Modified work Copyright (c) 2018 DeineAgentur UG https://www.deineagentur.com
// Modified work Copyright (c) 2018-present gotext maintainers (https://github.com/leonelquinteros/gotext)
//
// Licensed under the BSD License. See License.txt in the project root for license information.
package plurals
type equal struct {
value uint32
}
func (e equal) test(n uint32) bool {
return n == e.value
}
type notequal struct {
value uint32
}
func (e notequal) test(n uint32) bool {
return n != e.value
}
type gt struct {
value uint32
flipped bool
}
func (e gt) test(n uint32) bool {
if e.flipped {
return e.value > n
} else {
return n > e.value
}
}
type lt struct {
value uint32
flipped bool
}
func (e lt) test(n uint32) bool {
if e.flipped {
return e.value < n
}
return n < e.value
}
type gte struct {
value uint32
flipped bool
}
func (e gte) test(n uint32) bool {
if e.flipped {
return e.value >= n
}
return n >= e.value
}
type lte struct {
value uint32
flipped bool
}
func (e lte) test(n uint32) bool {
if e.flipped {
return e.value <= n
}
return n <= e.value
}
type and struct {
left test
right test
}
func (e and) test(n uint32) bool {
if !e.left.test(n) {
return false
}
return e.right.test(n)
}
type or struct {
left test
right test
}
func (e or) test(n uint32) bool {
if e.left.test(n) {
return true
}
return e.right.test(n)
}
type pipe struct {
modifier math
action test
}
func (e pipe) test(n uint32) bool {
return e.action.test(e.modifier.calc(n))
}