@@ -882,8 +882,8 @@ return /******/ (function(modules) { // webpackBootstrap
882
882
var count = range ? ! range [ 2 ] ? parseInt ( range [ 1 ] , 10 ) : Random . integer ( min , max ) : undefined
883
883
884
884
var decimal = parameters && parameters [ 4 ] && parameters [ 4 ] . match ( Constant . RE_RANGE )
885
- var dmin = decimal && parseInt ( decimal [ 1 ] , 10 ) // || 0,
886
- var dmax = decimal && parseInt ( decimal [ 2 ] , 10 ) // || 0,
885
+ var dmin = decimal && decimal [ 1 ] && parseInt ( decimal [ 1 ] , 10 ) // || 0,
886
+ var dmax = decimal && decimal [ 2 ] && parseInt ( decimal [ 2 ] , 10 ) // || 0,
887
887
// int || dmin-dmax || 0
888
888
var dcount = decimal ? ! decimal [ 2 ] && parseInt ( decimal [ 1 ] , 10 ) || Random . integer ( dmin , dmax ) : undefined
889
889
@@ -7664,7 +7664,8 @@ return /******/ (function(modules) { // webpackBootstrap
7664
7664
var schema = toJSONSchema ( template )
7665
7665
var result = Diff . diff ( schema , data )
7666
7666
for ( var i = 0 ; i < result . length ; i ++ ) {
7667
- // console.log(Assert.message(result[i]))
7667
+ // console.log(template, data)
7668
+ // console.warn(Assert.message(result[i]))
7668
7669
}
7669
7670
return result
7670
7671
}
@@ -7733,10 +7734,24 @@ return /******/ (function(modules) { // webpackBootstrap
7733
7734
var length = result . length
7734
7735
7735
7736
switch ( schema . type ) {
7736
- // 跳过含有『占位符』的属性值,因为『占位符』返回值的类型可能和模板不一致,例如 '@int' 会返回一个整形值
7737
7737
case 'string' :
7738
+ // 跳过含有『占位符』的属性值,因为『占位符』返回值的类型可能和模板不一致,例如 '@int' 会返回一个整形值
7738
7739
if ( schema . template . match ( Constant . RE_PLACEHOLDER ) ) return true
7739
7740
break
7741
+ case 'array' :
7742
+ if ( schema . rule . parameters ) {
7743
+ // name|count: array
7744
+ if ( schema . rule . min !== undefined && schema . rule . max === undefined ) {
7745
+ // 跳过 name|1: array,因为最终值的类型(很可能)不是数组,也不一定与 `array` 中的类型一致
7746
+ if ( schema . rule . count === 1 ) return true
7747
+ }
7748
+ // 跳过 name|+inc: array
7749
+ if ( schema . rule . parameters [ 2 ] ) return true
7750
+ }
7751
+ break
7752
+ case 'function' :
7753
+ // 跳过 `'name': function`,因为函数可以返回任何类型的值。
7754
+ return true
7740
7755
}
7741
7756
7742
7757
Assert . equal ( 'type' , schema . path , Util . type ( data ) , schema . type , result )
@@ -7748,7 +7763,7 @@ return /******/ (function(modules) { // webpackBootstrap
7748
7763
7749
7764
var rule = schema . rule
7750
7765
var templateType = schema . type
7751
- if ( templateType === 'object' || templateType === 'array' ) return
7766
+ if ( templateType === 'object' || templateType === 'array' || templateType === 'function' ) return true
7752
7767
7753
7768
// 无生成规则
7754
7769
if ( ! rule . parameters ) {
@@ -7775,9 +7790,9 @@ return /******/ (function(modules) { // webpackBootstrap
7775
7790
// 整数部分
7776
7791
// |min-max
7777
7792
if ( rule . min !== undefined && rule . max !== undefined ) {
7778
- Assert . greaterThanOrEqualTo ( 'value' , schema . path , parts [ 0 ] , rule . min , result )
7793
+ Assert . greaterThanOrEqualTo ( 'value' , schema . path , parts [ 0 ] , Math . min ( rule . min , rule . max ) , result )
7779
7794
// , 'numeric instance is lower than the required minimum (minimum: {expected}, found: {actual})')
7780
- Assert . lessThanOrEqualTo ( 'value' , schema . path , parts [ 0 ] , rule . max , result )
7795
+ Assert . lessThanOrEqualTo ( 'value' , schema . path , parts [ 0 ] , Math . max ( rule . min , rule . max ) , result )
7781
7796
}
7782
7797
// |count
7783
7798
if ( rule . min !== undefined && rule . max === undefined ) {
@@ -7805,7 +7820,7 @@ return /******/ (function(modules) { // webpackBootstrap
7805
7820
case 'string' :
7806
7821
// 'aaa'.match(/a/g)
7807
7822
actualRepeatCount = data . match ( new RegExp ( schema . template , 'g' ) )
7808
- actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : actualRepeatCount
7823
+ actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : 0
7809
7824
7810
7825
// |min-max
7811
7826
if ( rule . min !== undefined && rule . max !== undefined ) {
@@ -7821,7 +7836,7 @@ return /******/ (function(modules) { // webpackBootstrap
7821
7836
7822
7837
case 'regexp' :
7823
7838
actualRepeatCount = data . match ( new RegExp ( schema . template . source . replace ( / ^ \^ | \$ $ / g, '' ) , 'g' ) )
7824
- actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : actualRepeatCount
7839
+ actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : 0
7825
7840
7826
7841
// |min-max
7827
7842
if ( rule . min !== undefined && rule . max !== undefined ) {
@@ -7851,12 +7866,13 @@ return /******/ (function(modules) { // webpackBootstrap
7851
7866
// 有生成规则
7852
7867
// |min-max
7853
7868
if ( rule . min !== undefined && rule . max !== undefined ) {
7854
- Assert . greaterThanOrEqualTo ( 'properties length' , schema . path , keys . length , rule . min , result )
7855
- Assert . lessThanOrEqualTo ( 'properties length' , schema . path , keys . length , rule . max , result )
7869
+ Assert . greaterThanOrEqualTo ( 'properties length' , schema . path , keys . length , Math . min ( rule . min , rule . max ) , result )
7870
+ Assert . lessThanOrEqualTo ( 'properties length' , schema . path , keys . length , Math . max ( rule . min , rule . max ) , result )
7856
7871
}
7857
7872
// |count
7858
7873
if ( rule . min !== undefined && rule . max === undefined ) {
7859
- Assert . equal ( 'properties length' , schema . path , keys . length , rule . min , result )
7874
+ // |1, |>1
7875
+ if ( rule . count !== 1 ) Assert . equal ( 'properties length' , schema . path , keys . length , rule . min , result )
7860
7876
}
7861
7877
}
7862
7878
@@ -7866,7 +7882,13 @@ return /******/ (function(modules) { // webpackBootstrap
7866
7882
result . push . apply (
7867
7883
result ,
7868
7884
this . diff (
7869
- schema . properties [ i ] ,
7885
+ function ( ) {
7886
+ var property
7887
+ Util . each ( schema . properties , function ( item /*, index*/ ) {
7888
+ if ( item . name === keys [ i ] ) property = item
7889
+ } )
7890
+ return property || schema . properties [ i ]
7891
+ } ( ) ,
7870
7892
data [ keys [ i ] ] ,
7871
7893
keys [ i ]
7872
7894
)
@@ -7889,15 +7911,19 @@ return /******/ (function(modules) { // webpackBootstrap
7889
7911
// 有生成规则
7890
7912
// |min-max
7891
7913
if ( rule . min !== undefined && rule . max !== undefined ) {
7892
- Assert . greaterThanOrEqualTo ( 'items' , schema . path , data . length , ( rule . min * schema . items . length ) , result ,
7914
+ Assert . greaterThanOrEqualTo ( 'items' , schema . path , data . length , ( Math . min ( rule . min , rule . max ) * schema . items . length ) , result ,
7893
7915
'[{utype}] array is too short: {path} must have at least {expected} elements but instance has {actual} elements' )
7894
- Assert . lessThanOrEqualTo ( 'items' , schema . path , data . length , ( rule . max * schema . items . length ) , result ,
7916
+ Assert . lessThanOrEqualTo ( 'items' , schema . path , data . length , ( Math . max ( rule . min , rule . max ) * schema . items . length ) , result ,
7895
7917
'[{utype}] array is too long: {path} must have at most {expected} elements but instance has {actual} elements' )
7896
7918
}
7897
7919
// |count
7898
7920
if ( rule . min !== undefined && rule . max === undefined ) {
7899
- Assert . equal ( 'items length' , schema . path , data . length , ( rule . min * schema . items . length ) , result )
7921
+ // |1, |>1
7922
+ if ( rule . count === 1 ) return result . length === length
7923
+ else Assert . equal ( 'items length' , schema . path , data . length , ( rule . min * schema . items . length ) , result )
7900
7924
}
7925
+ // |+inc
7926
+ if ( rule . parameters [ 2 ] ) return result . length === length
7901
7927
}
7902
7928
7903
7929
if ( result . length !== length ) return false
0 commit comments