@@ -882,8 +882,8 @@ return /******/ (function(modules) { // webpackBootstrap
882882 var count = range ? ! range [ 2 ] ? parseInt ( range [ 1 ] , 10 ) : Random . integer ( min , max ) : undefined
883883
884884 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,
887887 // int || dmin-dmax || 0
888888 var dcount = decimal ? ! decimal [ 2 ] && parseInt ( decimal [ 1 ] , 10 ) || Random . integer ( dmin , dmax ) : undefined
889889
@@ -7664,7 +7664,8 @@ return /******/ (function(modules) { // webpackBootstrap
76647664 var schema = toJSONSchema ( template )
76657665 var result = Diff . diff ( schema , data )
76667666 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]))
76687669 }
76697670 return result
76707671 }
@@ -7733,10 +7734,24 @@ return /******/ (function(modules) { // webpackBootstrap
77337734 var length = result . length
77347735
77357736 switch ( schema . type ) {
7736- // 跳过含有『占位符』的属性值,因为『占位符』返回值的类型可能和模板不一致,例如 '@int' 会返回一个整形值
77377737 case 'string' :
7738+ // 跳过含有『占位符』的属性值,因为『占位符』返回值的类型可能和模板不一致,例如 '@int' 会返回一个整形值
77387739 if ( schema . template . match ( Constant . RE_PLACEHOLDER ) ) return true
77397740 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
77407755 }
77417756
77427757 Assert . equal ( 'type' , schema . path , Util . type ( data ) , schema . type , result )
@@ -7748,7 +7763,7 @@ return /******/ (function(modules) { // webpackBootstrap
77487763
77497764 var rule = schema . rule
77507765 var templateType = schema . type
7751- if ( templateType === 'object' || templateType === 'array' ) return
7766+ if ( templateType === 'object' || templateType === 'array' || templateType === 'function' ) return true
77527767
77537768 // 无生成规则
77547769 if ( ! rule . parameters ) {
@@ -7775,9 +7790,9 @@ return /******/ (function(modules) { // webpackBootstrap
77757790 // 整数部分
77767791 // |min-max
77777792 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 )
77797794 // , '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 )
77817796 }
77827797 // |count
77837798 if ( rule . min !== undefined && rule . max === undefined ) {
@@ -7805,7 +7820,7 @@ return /******/ (function(modules) { // webpackBootstrap
78057820 case 'string' :
78067821 // 'aaa'.match(/a/g)
78077822 actualRepeatCount = data . match ( new RegExp ( schema . template , 'g' ) )
7808- actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : actualRepeatCount
7823+ actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : 0
78097824
78107825 // |min-max
78117826 if ( rule . min !== undefined && rule . max !== undefined ) {
@@ -7821,7 +7836,7 @@ return /******/ (function(modules) { // webpackBootstrap
78217836
78227837 case 'regexp' :
78237838 actualRepeatCount = data . match ( new RegExp ( schema . template . source . replace ( / ^ \^ | \$ $ / g, '' ) , 'g' ) )
7824- actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : actualRepeatCount
7839+ actualRepeatCount = actualRepeatCount ? actualRepeatCount . length : 0
78257840
78267841 // |min-max
78277842 if ( rule . min !== undefined && rule . max !== undefined ) {
@@ -7851,12 +7866,13 @@ return /******/ (function(modules) { // webpackBootstrap
78517866 // 有生成规则
78527867 // |min-max
78537868 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 )
78567871 }
78577872 // |count
78587873 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 )
78607876 }
78617877 }
78627878
@@ -7866,7 +7882,13 @@ return /******/ (function(modules) { // webpackBootstrap
78667882 result . push . apply (
78677883 result ,
78687884 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+ } ( ) ,
78707892 data [ keys [ i ] ] ,
78717893 keys [ i ]
78727894 )
@@ -7889,15 +7911,19 @@ return /******/ (function(modules) { // webpackBootstrap
78897911 // 有生成规则
78907912 // |min-max
78917913 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 ,
78937915 '[{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 ,
78957917 '[{utype}] array is too long: {path} must have at most {expected} elements but instance has {actual} elements' )
78967918 }
78977919 // |count
78987920 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 )
79007924 }
7925+ // |+inc
7926+ if ( rule . parameters [ 2 ] ) return result . length === length
79017927 }
79027928
79037929 if ( result . length !== length ) return false
0 commit comments