-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
basicvalidators_test.go
141 lines (110 loc) · 3.46 KB
/
basicvalidators_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
package fiskalhrgo
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 L. D. T. d.o.o.
// Copyright (c) contributors for their respective contributions. See https://github.com/l-d-t/fiskalhrgo/graphs/contributors
import "testing"
func TestCheckCurrency(t *testing.T) {
t.Logf("Testing currency validation...")
// Test a valid currency
if !IsValidCurrencyFormat("100.00") {
t.Fatalf("Expected currency 100.00 to be valid")
}
// Test a valid currency
if !IsValidCurrencyFormat("13.12") {
t.Fatalf("Expected currency 13.12 to be valid")
}
// Test a valid currency
if !IsValidCurrencyFormat("1.12") {
t.Fatalf("Expected currency 1.12 to be valid")
}
// Test a valid currency
if !IsValidCurrencyFormat("134876348653847632687.99") {
t.Fatalf("Expected currency 134876348653847632687.99 to be valid")
}
// Test an invalid currency
if IsValidCurrencyFormat("100.001") {
t.Fatalf("Expected currency 100.001 to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("100,00") {
t.Fatalf("Expected currency 100,00 to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("100") {
t.Fatalf("Expected currency 100 to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("abc") {
t.Fatalf("Expected currency abc to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("abc.fg") {
t.Fatalf("Expected currency abc.fg to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("abc.23") {
t.Fatalf("Expected currency abc.23 to be invalid")
}
// Test an invalid currency
if IsValidCurrencyFormat("100.ab") {
t.Fatalf("Expected currency 100.ab to be invalid")
}
// Test negative currency
if !IsValidCurrencyFormat("-100.00") {
t.Fatalf("Expected currency -100.00 to be valid")
}
//Test zero
if !IsValidCurrencyFormat("0.00") {
t.Fatalf("Expected currency 0.00 to be valid")
}
//Test zero
if IsValidCurrencyFormat("0.0") {
t.Fatalf("Expected currency 0.0 to be invalid")
}
//Test zero
if IsValidCurrencyFormat("0") {
t.Fatalf("Expected currency 0 to be invalid")
}
}
func TestValidateLocationID(t *testing.T) {
t.Logf("Testing location ID validation...")
if !ValidateLocationID("12345678") {
t.Fatalf("Expected location ID 12345678 to be valid")
}
if !ValidateLocationID("TEST3") {
t.Fatalf("Expected location ID TEST3 to be valid")
}
if !ValidateLocationID("POS1") {
t.Fatalf("Expected location ID POS1 to be valid")
}
if !ValidateLocationID("1") {
t.Fatalf("Expected location ID 1 to be valid")
}
if !ValidateLocationID("1234567a") {
t.Fatalf("Expected location ID 1234567a to be valid")
}
if ValidateLocationID("1234567!") {
t.Fatalf("Expected location ID 1234567! to be invalid")
}
if ValidateLocationID("1234567.") {
t.Fatalf("Expected location ID 1234567. to be invalid")
}
if ValidateLocationID("POS 1") {
t.Fatalf("Expected location ID POS 1 to be invalid")
}
if ValidateLocationID("fdkjhfdhjfdshfshfdkhfd87549549875kjfhhfdshfjhjdshkjdfsk7554875kjgfkjgfsssssssssssssssssssssssss") {
t.Fatalf("Expected location ID fdkjhfdhjfdshfshfdkhfd87549549875kjfhhfdshfjhjdshkjdfsk7554875kjgfkjgfsssssssssssssssssssssssss to be invalid")
}
}
// Test check OIB
func TestCheckOIB(t *testing.T) {
t.Logf("Testing OIB validation...")
// Test a valid OIB
if !ValidateOIB("65049901548") {
t.Fatalf("Expected OIB 65049901548 to be valid")
}
// Test an invalid OIB
if ValidateOIB("12345678900") {
t.Fatalf("Expected OIB 12345678900 to be invalid")
}
}