1- package go_codes_validator
1+ package ru_doc_code
22
33import (
44 "errors"
@@ -41,7 +41,7 @@ func TestIsBIKValid(t *testing.T) {
4141 }
4242 for _ , test := range testCases {
4343 isValid , err := IsBIKValid (test .Code )
44- assert .Equal (t , isValid , test .IsValid , test .Code )
44+ assert .Equal (t , test .IsValid , isValid , test .Code )
4545 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
4646 }
4747 })
@@ -81,7 +81,7 @@ func TestIsBIKValid(t *testing.T) {
8181 }
8282 for _ , test := range testCases {
8383 isValid , err := IsBIKValid (test .Code )
84- assert .Equal (t , isValid , test .IsValid , test .Code , test .IsValid )
84+ assert .Equal (t , test .IsValid , isValid , test .Code , test .IsValid )
8585 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
8686 }
8787 })
@@ -115,7 +115,7 @@ func TestIsINNValid(t *testing.T) {
115115 }
116116 for _ , test := range testCases {
117117 isValid , err := IsINNValid (test .Code )
118- assert .Equal (t , isValid , test .IsValid , test .Code )
118+ assert .Equal (t , test .IsValid , isValid , test .Code )
119119 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
120120 }
121121 })
@@ -150,7 +150,7 @@ func TestIsINNValid(t *testing.T) {
150150 }
151151 for _ , test := range testCases {
152152 isValid , err := IsINNValid (test .Code )
153- assert .Equal (t , isValid , test .IsValid , test .Code )
153+ assert .Equal (t , test .IsValid , isValid , test .Code )
154154 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
155155 }
156156 })
@@ -184,7 +184,7 @@ func TestValidateOGRN(t *testing.T) {
184184 }
185185 for _ , test := range testCases {
186186 isValid , err := IsOGRNValid (test .Code )
187- assert .Equal (t , isValid , test .IsValid , test .Code )
187+ assert .Equal (t , test .IsValid , isValid , test .Code )
188188 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
189189 }
190190 })
@@ -219,7 +219,7 @@ func TestValidateOGRN(t *testing.T) {
219219 }
220220 for _ , test := range testCases {
221221 isValid , err := IsOGRNValid (test .Code )
222- assert .Equal (t , isValid , test .IsValid , test .Code , test .IsValid )
222+ assert .Equal (t , test .IsValid , isValid , test .Code , test .IsValid )
223223 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
224224 }
225225 })
@@ -228,16 +228,143 @@ func TestValidateOGRN(t *testing.T) {
228228func TestValidateOGRNIP (t * testing.T ) {
229229 t .Parallel ()
230230
231- t .Run ("" , func (t * testing.T ) {
231+ t .Run ("invalid ogrnip length" , func (t * testing.T ) {
232+ testCases := []TestCodeCase {
233+ TestCodeCase {
234+ Code : "304500116000157" ,
235+ Error : nil ,
236+ IsValid : true ,
237+ },
238+ TestCodeCase {
239+ Code : "312502904600034" ,
240+ Error : nil ,
241+ IsValid : true ,
242+ },
243+ TestCodeCase {
244+ Code : "31250290460" ,
245+ Error : ErrInvalidOGRNIPLength ,
246+ IsValid : false ,
247+ },
248+ TestCodeCase {
249+ Code : "3045001111236000157" ,
250+ Error : ErrInvalidOGRNIPLength ,
251+ IsValid : false ,
252+ },
253+ }
254+ for _ , test := range testCases {
255+ isValid , err := IsOGRNIPValid (test .Code )
256+ assert .Equal (t , test .IsValid , isValid , test .Code )
257+ assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
258+ }
259+ })
232260
261+ t .Run ("invalid ogrnip value" , func (t * testing.T ) {
262+ testCases := []TestCodeCase {
263+ TestCodeCase {
264+ Code : "312502??4600034" ,
265+ Error : ErrInvalidValue ,
266+ IsValid : false ,
267+ },
268+ TestCodeCase {
269+ Code : "304500116000158" ,
270+ Error : nil ,
271+ IsValid : false ,
272+ },
273+ TestCodeCase {
274+ Code : "512502904600034" ,
275+ Error : ErrInvalidValue ,
276+ IsValid : false ,
277+ },
278+ TestCodeCase {
279+ Code : "304500116000157" ,
280+ Error : nil ,
281+ IsValid : true ,
282+ },
283+ TestCodeCase {
284+ Code : "312502904600034" ,
285+ Error : nil ,
286+ IsValid : true ,
287+ },
288+ }
289+ for _ , test := range testCases {
290+ isValid , err := IsOGRNIPValid (test .Code )
291+ assert .Equal (t , test .IsValid , isValid , test .Code , test .IsValid )
292+ assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
293+ }
233294 })
234295}
235296
236297func TestValidateSNILS (t * testing.T ) {
237298 t .Parallel ()
238299
239- t .Run ("" , func (t * testing.T ) {
300+ t .Run ("invalid snils length" , func (t * testing.T ) {
301+ testCases := []TestCodeCase {
302+ TestCodeCase {
303+ Code : "112-233-445 95" ,
304+ Error : nil ,
305+ IsValid : true ,
306+ },
307+ TestCodeCase {
308+ Code : "646-663-083 23" ,
309+ Error : nil ,
310+ IsValid : true ,
311+ },
312+ TestCodeCase {
313+ Code : "112-233-445 951213" ,
314+ Error : ErrInvalidSNILSLength ,
315+ IsValid : false ,
316+ },
317+ TestCodeCase {
318+ Code : "112-233 95" ,
319+ Error : ErrInvalidSNILSLength ,
320+ IsValid : false ,
321+ },
322+ }
323+ for _ , test := range testCases {
324+ isValid , err := IsSNILSValid (test .Code )
325+ assert .Equal (t , test .IsValid , isValid , test .Code )
326+ assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
327+ }
328+ })
240329
330+ t .Run ("invalid snils value" , func (t * testing.T ) {
331+ testCases := []TestCodeCase {
332+ TestCodeCase {
333+ Code : "112-233?445 95" ,
334+ Error : ErrInvalidFormattedSNILSLength ,
335+ IsValid : false ,
336+ },
337+ TestCodeCase {
338+ Code : "1M2-234-445 95" ,
339+ Error : ErrInvalidValue ,
340+ IsValid : false ,
341+ },
342+ TestCodeCase {
343+ Code : "112-233-445 98" ,
344+ Error : nil ,
345+ IsValid : false ,
346+ },
347+ TestCodeCase {
348+ Code : "112-233-445#95" ,
349+ Error : ErrInvalidFormattedSNILSLength ,
350+ IsValid : false ,
351+ },
352+ TestCodeCase {
353+ Code : "112-233-445 95" ,
354+ Error : nil ,
355+ IsValid : true ,
356+ },
357+ TestCodeCase {
358+ Code : "646-663-083 23" ,
359+ Error : nil ,
360+ IsValid : true ,
361+ },
362+ }
363+ for _ , test := range testCases {
364+ isValid , err := IsSNILSValid (test .Code )
365+ assert .Equal (t , test .IsValid , isValid , test .Code , test .IsValid )
366+ assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
367+ }
241368 })
242369}
243370
@@ -273,4 +400,34 @@ func TestValidateKPP(t *testing.T) {
273400 assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
274401 }
275402 })
403+
404+ t .Run ("invalid kpp value" , func (t * testing.T ) {
405+ testCases := []TestCodeCase {
406+ TestCodeCase {
407+ Code : "773$N3301" ,
408+ Error : ErrInvalidValue ,
409+ IsValid : false ,
410+ },
411+ TestCodeCase {
412+ Code : "7736#3&01" ,
413+ Error : ErrInvalidValue ,
414+ IsValid : false ,
415+ },
416+ TestCodeCase {
417+ Code : "773643301" ,
418+ Error : nil ,
419+ IsValid : true ,
420+ },
421+ TestCodeCase {
422+ Code : "773643001" ,
423+ Error : nil ,
424+ IsValid : true ,
425+ },
426+ }
427+ for _ , test := range testCases {
428+ isValid , err := IsKPPValid (test .Code )
429+ assert .Equal (t , isValid , test .IsValid , test .Code )
430+ assert .Equal (t , true , errors .Is (test .Error , err ), test .Code )
431+ }
432+ })
276433}
0 commit comments