kwalify 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -1
- data/README.txt +1 -1
- data/bin/kwalify +1 -1
- data/doc/users-guide.html +108 -18
- data/examples/address-book/address-book.schema.yaml +2 -1
- data/examples/invoice/invoice.schema.yaml +3 -3
- data/examples/tapkit/tapkit.schema.yaml +5 -1
- data/lib/kwalify.rb +2 -2
- data/lib/kwalify/errors.rb +1 -1
- data/lib/kwalify/main-program.rb +1 -1
- data/lib/kwalify/messages.rb +20 -4
- data/lib/kwalify/meta-validator.rb +101 -47
- data/lib/kwalify/rule.rb +86 -14
- data/lib/kwalify/types.rb +1 -1
- data/lib/kwalify/util/assert-diff.rb +1 -1
- data/lib/kwalify/util/option-parser.rb +1 -1
- data/lib/kwalify/util/yaml-helper.rb +1 -1
- data/lib/kwalify/validator.rb +51 -5
- data/test/test-metavalidator.rb +172 -2
- data/test/test-metavalidator.rb.error +1 -1
- data/test/test-validator.rb +294 -2
- data/test/test.rb +1 -1
- data/todo.txt +4 -2
- metadata +2 -2
data/test/test-validator.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 21 $
|
3
|
+
### $Release: 0.3.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -400,6 +400,110 @@ error: |
|
|
400
400
|
:range_toolarge : [/max-only/1] '100.1': too large (> max 100).
|
401
401
|
#
|
402
402
|
---
|
403
|
+
name: range2
|
404
|
+
desc: range test (with max-ex and min-ex)
|
405
|
+
#
|
406
|
+
schema: |
|
407
|
+
type: map
|
408
|
+
mapping:
|
409
|
+
"max-ex-only":
|
410
|
+
type: seq
|
411
|
+
sequence:
|
412
|
+
- type: number
|
413
|
+
required: yes
|
414
|
+
range: { max-ex: 100 }
|
415
|
+
"min-ex-only":
|
416
|
+
type: seq
|
417
|
+
sequence:
|
418
|
+
- type: number
|
419
|
+
required: yes
|
420
|
+
range: { min-ex: 10.0 }
|
421
|
+
"max-ex-and-min-ex":
|
422
|
+
type: seq
|
423
|
+
sequence:
|
424
|
+
- type: number
|
425
|
+
required: yes
|
426
|
+
range: { max-ex: 100.0, min-ex: 10.0 }
|
427
|
+
#
|
428
|
+
valid: |
|
429
|
+
max-ex-only:
|
430
|
+
- 99
|
431
|
+
- 99.99999
|
432
|
+
min-ex-only:
|
433
|
+
- 11
|
434
|
+
- 10.00001
|
435
|
+
max-ex-and-min-ex:
|
436
|
+
- 99
|
437
|
+
- 11
|
438
|
+
- 99.99999
|
439
|
+
- 10.00001
|
440
|
+
#
|
441
|
+
invalid: |
|
442
|
+
max-ex-only:
|
443
|
+
- 100
|
444
|
+
- 100.0
|
445
|
+
min-ex-only:
|
446
|
+
- 10
|
447
|
+
- 10.0
|
448
|
+
max-ex-and-min-ex:
|
449
|
+
- 100
|
450
|
+
- 100.0
|
451
|
+
- 10
|
452
|
+
- 10.0
|
453
|
+
#
|
454
|
+
error: |
|
455
|
+
:range_toosmallex : [/min-ex-only/0] '10': too small (<= min 10.0).
|
456
|
+
:range_toosmallex : [/min-ex-only/1] '10.0': too small (<= min 10.0).
|
457
|
+
:range_toolargeex : [/max-ex-only/0] '100': too large (>= max 100).
|
458
|
+
:range_toolargeex : [/max-ex-only/1] '100.0': too large (>= max 100).
|
459
|
+
:range_toolargeex : [/max-ex-and-min-ex/0] '100': too large (>= max 100.0).
|
460
|
+
:range_toolargeex : [/max-ex-and-min-ex/1] '100.0': too large (>= max 100.0).
|
461
|
+
:range_toosmallex : [/max-ex-and-min-ex/2] '10': too small (<= min 10.0).
|
462
|
+
:range_toosmallex : [/max-ex-and-min-ex/3] '10.0': too small (<= min 10.0).
|
463
|
+
#
|
464
|
+
---
|
465
|
+
name: range3
|
466
|
+
desc: range test (with max, min, max-ex and min-ex)
|
467
|
+
#
|
468
|
+
schema: |
|
469
|
+
type: map
|
470
|
+
mapping:
|
471
|
+
"A":
|
472
|
+
type: seq
|
473
|
+
sequence:
|
474
|
+
- type: number
|
475
|
+
required: yes
|
476
|
+
range: { max: 100, min-ex: 10.0 }
|
477
|
+
"B":
|
478
|
+
type: seq
|
479
|
+
sequence:
|
480
|
+
- type: number
|
481
|
+
required: yes
|
482
|
+
range: { min: 10, max-ex: 100.0 }
|
483
|
+
#
|
484
|
+
valid: |
|
485
|
+
A:
|
486
|
+
- 100
|
487
|
+
- 10.00001
|
488
|
+
B:
|
489
|
+
- 10
|
490
|
+
- 99.99999
|
491
|
+
#
|
492
|
+
invalid: |
|
493
|
+
A:
|
494
|
+
- 100.00001
|
495
|
+
- 10.0
|
496
|
+
B:
|
497
|
+
- 9.99999
|
498
|
+
- 100.0
|
499
|
+
#
|
500
|
+
error: |
|
501
|
+
:range_toolarge : [/A/0] '100.00001': too large (> max 100).
|
502
|
+
:range_toosmallex : [/A/1] '10.0': too small (<= min 10.0).
|
503
|
+
:range_toosmall : [/B/0] '9.99999': too small (< min 10).
|
504
|
+
:range_toolargeex : [/B/1] '100.0': too large (>= max 100.0).
|
505
|
+
#
|
506
|
+
---
|
403
507
|
name: length1
|
404
508
|
desc: length test
|
405
509
|
#
|
@@ -455,6 +559,101 @@ error: |
|
|
455
559
|
:length_toolong : [/max-only/0] 'hogehoge!': too long (length 9 > max 8).
|
456
560
|
#
|
457
561
|
---
|
562
|
+
name: length2
|
563
|
+
desc: length test (with max-ex and min-ex)
|
564
|
+
#
|
565
|
+
schema: |
|
566
|
+
type: map
|
567
|
+
mapping:
|
568
|
+
"max-ex-only":
|
569
|
+
type: seq
|
570
|
+
sequence:
|
571
|
+
- type: text
|
572
|
+
length: { max-ex: 8 }
|
573
|
+
"min-ex-only":
|
574
|
+
type: seq
|
575
|
+
sequence:
|
576
|
+
- type: text
|
577
|
+
length: { min-ex: 4 }
|
578
|
+
"max-ex-and-min-ex":
|
579
|
+
type: seq
|
580
|
+
sequence:
|
581
|
+
- type: text
|
582
|
+
length: { max-ex: 8, min-ex: 4 }
|
583
|
+
#
|
584
|
+
valid: |
|
585
|
+
max-ex-only:
|
586
|
+
- hogehog
|
587
|
+
- 1234567
|
588
|
+
- a
|
589
|
+
-
|
590
|
+
min-ex-only:
|
591
|
+
- hoge!
|
592
|
+
- 1234!
|
593
|
+
- hogehogehogehogehoge
|
594
|
+
max-ex-and-min-ex:
|
595
|
+
- hogehog
|
596
|
+
- 1234567
|
597
|
+
- hoge!
|
598
|
+
- 1234!
|
599
|
+
#
|
600
|
+
invalid: |
|
601
|
+
max-ex-only:
|
602
|
+
- hogehoge
|
603
|
+
min-ex-only:
|
604
|
+
- foo!
|
605
|
+
-
|
606
|
+
max-ex-and-min-ex:
|
607
|
+
- foobarba
|
608
|
+
- foo!
|
609
|
+
#
|
610
|
+
error: |
|
611
|
+
:length_tooshortex : [/min-ex-only/0] 'foo!': too short (length 4 <= min 4).
|
612
|
+
:length_toolongex : [/max-ex-only/0] 'hogehoge': too long (length 8 >= max 8).
|
613
|
+
:length_toolongex : [/max-ex-and-min-ex/0] 'foobarba': too long (length 8 >= max 8).
|
614
|
+
:length_tooshortex : [/max-ex-and-min-ex/1] 'foo!': too short (length 4 <= min 4).
|
615
|
+
#
|
616
|
+
---
|
617
|
+
name: length3
|
618
|
+
desc: length test (with min, max, max-ex and min-ex)
|
619
|
+
#
|
620
|
+
schema: |
|
621
|
+
type: map
|
622
|
+
mapping:
|
623
|
+
"A":
|
624
|
+
type: seq
|
625
|
+
sequence:
|
626
|
+
- type: text
|
627
|
+
length: { max: 8, min-ex: 4 }
|
628
|
+
"B":
|
629
|
+
type: seq
|
630
|
+
sequence:
|
631
|
+
- type: text
|
632
|
+
length: { max-ex: 8, min: 4 }
|
633
|
+
#
|
634
|
+
valid: |
|
635
|
+
A:
|
636
|
+
- hogehoge
|
637
|
+
- 12345
|
638
|
+
B:
|
639
|
+
- hogehog
|
640
|
+
- 1234
|
641
|
+
#
|
642
|
+
invalid: |
|
643
|
+
A:
|
644
|
+
- hogehoge!
|
645
|
+
- 1234
|
646
|
+
B:
|
647
|
+
- hogehoge
|
648
|
+
- 123
|
649
|
+
#
|
650
|
+
error: |
|
651
|
+
:length_toolong : [/A/0] 'hogehoge!': too long (length 9 > max 8).
|
652
|
+
:length_tooshortex : [/A/1] '1234': too short (length 4 <= min 4).
|
653
|
+
:length_toolongex : [/B/0] 'hogehoge': too long (length 8 >= max 8).
|
654
|
+
:length_tooshort : [/B/1] '123': too short (length 3 < min 4).
|
655
|
+
#
|
656
|
+
---
|
458
657
|
name: assert1
|
459
658
|
desc: assert test
|
460
659
|
#
|
@@ -524,3 +723,96 @@ error: |
|
|
524
723
|
:type_unmatch : [/1/name] '3.14': not a string.
|
525
724
|
:type_unmatch : [/2/email] '2004-01-01': not a string.
|
526
725
|
#
|
726
|
+
---
|
727
|
+
name: ident1
|
728
|
+
desc: ident constraint test
|
729
|
+
#
|
730
|
+
schema: |
|
731
|
+
type: seq
|
732
|
+
sequence:
|
733
|
+
- type: map
|
734
|
+
mapping:
|
735
|
+
"name":
|
736
|
+
ident: yes
|
737
|
+
"age":
|
738
|
+
type: int
|
739
|
+
#
|
740
|
+
valid: |
|
741
|
+
- name: foo
|
742
|
+
age: 10
|
743
|
+
- name: bar
|
744
|
+
age: 10
|
745
|
+
- name: baz
|
746
|
+
age: 10
|
747
|
+
#
|
748
|
+
invalid: |
|
749
|
+
- name: foo
|
750
|
+
age: 10
|
751
|
+
- name: bar
|
752
|
+
age: 10
|
753
|
+
- name: bar
|
754
|
+
age: 10
|
755
|
+
#
|
756
|
+
error: |
|
757
|
+
:value_notunique : [/2/name] 'bar': is already used at '/1/name'.
|
758
|
+
#
|
759
|
+
---
|
760
|
+
name: unique1
|
761
|
+
desc: unique constraint test with map
|
762
|
+
#
|
763
|
+
schema: |
|
764
|
+
type: seq
|
765
|
+
sequence:
|
766
|
+
- type: map
|
767
|
+
mapping:
|
768
|
+
"name":
|
769
|
+
unique: yes
|
770
|
+
"age":
|
771
|
+
type: int
|
772
|
+
#
|
773
|
+
valid: |
|
774
|
+
- name: foo
|
775
|
+
age: 10
|
776
|
+
- name: bar
|
777
|
+
age: 10
|
778
|
+
- name: baz
|
779
|
+
age: 10
|
780
|
+
#
|
781
|
+
invalid: |
|
782
|
+
- name: foo
|
783
|
+
age: 10
|
784
|
+
- name: bar
|
785
|
+
age: 10
|
786
|
+
- name: bar
|
787
|
+
age: 10
|
788
|
+
#
|
789
|
+
error: |
|
790
|
+
:value_notunique : [/2/name] 'bar': is already used at '/1/name'.
|
791
|
+
#
|
792
|
+
---
|
793
|
+
name: unique2
|
794
|
+
desc: unique constraint test with seq
|
795
|
+
#
|
796
|
+
schema: |
|
797
|
+
type: seq
|
798
|
+
sequence:
|
799
|
+
- type: str
|
800
|
+
unique: yes
|
801
|
+
#
|
802
|
+
valid: |
|
803
|
+
- foo
|
804
|
+
- ~
|
805
|
+
- bar
|
806
|
+
- ~
|
807
|
+
- baz
|
808
|
+
#
|
809
|
+
invalid: |
|
810
|
+
- foo
|
811
|
+
- ~
|
812
|
+
- bar
|
813
|
+
- ~
|
814
|
+
- bar
|
815
|
+
#
|
816
|
+
error: |
|
817
|
+
:value_notunique : [/4] 'bar': is already used at '/2'.
|
818
|
+
#
|
data/test/test.rb
CHANGED
data/todo.txt
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
.- [v] users-guide
|
8
8
|
.- [v] examples
|
9
9
|
.- [v] gemspec
|
10
|
-
.- [
|
10
|
+
.- [v] 'unique:'
|
11
11
|
.- [-] 'not-null:'
|
12
12
|
.- [-] 'primary-key:'
|
13
13
|
.- [-] 'constraints:'
|
@@ -23,9 +23,11 @@
|
|
23
23
|
.- [v] 'length:' or 'width:'
|
24
24
|
.- [_] range 'max-ex' and 'min-ex' (or 'ceiling' and 'floor')
|
25
25
|
.- [_] range 'noteq'
|
26
|
-
.- [_] range 'reverse'
|
26
|
+
.- [_] range 'reverse' or 'complement'
|
27
27
|
.- [v] type 'scalar'
|
28
28
|
.- [_] type 'collection'
|
29
29
|
.- [_] 'multiple: yes'
|
30
30
|
.- [v] support validator hook method
|
31
31
|
.- [_] test for kwalify command
|
32
|
+
.- [_] error message customizatin
|
33
|
+
.- [_] data binding
|
metadata
CHANGED