@@ -815,11 +815,11 @@ var JSONResponse = {
815815 var guess = target . guess ;
816816 log ( 'compareWithStandard guess = target.guess = ' + guess + ' >>' ) ;
817817
818- var notnull = target . notnull ;
819- log ( 'compareWithStandard notnull = target.notnull = ' + notnull + ' >>' ) ;
818+ var notNull = target . notNull ;
819+ log ( 'compareWithStandard notNull = target.notNull = ' + notNull + ' >>' ) ;
820820
821- var notempty = target . notempty ;
822- log ( 'compareWithStandard notempty = target.notempty = ' + notempty + ' >>' ) ;
821+ var notEmpty = target . notEmpty ;
822+ log ( 'compareWithStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>' ) ;
823823
824824 var type = target . type ;
825825 log ( 'compareWithStandard type = target.type = ' + type + ' >>' ) ;
@@ -832,8 +832,8 @@ var JSONResponse = {
832832 var firstVal = values == null || values . length <= 0 ? null : values [ 0 ] ;
833833
834834 if ( firstVal == null && ( type == 'object' || type == 'array' ) ) {
835- if ( notnull == true ) { // values{} values&{}
836- throw new Error ( 'Standard 在 ' + folder + ' 语法错误,Object 或 Array 在 notnull : true 时 values 必须为有值的数组 !' ) ;
835+ if ( notNull == true ) { // values{} values&{}
836+ throw new Error ( 'Standard 在 ' + folder + ' 语法错误,Object 或 Array 在 notNull : true 时 values 必须为有值的数组 !' ) ;
837837 }
838838
839839 log ( 'compareWithStandard values == null; real ' + ( real == null ? '=' : '!' ) + '= null >> return ' + ( real == null ? 'COMPARE_EQUAL' : 'COMPARE_KEY_MORE' ) ) ;
@@ -846,17 +846,17 @@ var JSONResponse = {
846846 }
847847
848848 if ( real == null ) { //少了key
849- log ( 'compareWithStandard real == null >> return ' + ( notnull == true ? 'COMPARE_KEY_LESS' : 'COMPARE_EQUAL' ) ) ;
849+ log ( 'compareWithStandard real == null >> return ' + ( notNull == true ? 'COMPARE_KEY_LESS' : 'COMPARE_EQUAL' ) ) ;
850850 return {
851- code : notnull == true ? JSONResponse . COMPARE_KEY_LESS : JSONResponse . COMPARE_EQUAL ,
852- msg : notnull == true ? '是缺少的' : '结果正确' ,
853- path : notnull == true ? folder : '' ,
851+ code : notNull == true ? JSONResponse . COMPARE_KEY_LESS : JSONResponse . COMPARE_EQUAL ,
852+ msg : notNull == true ? '是缺少的' : '结果正确' ,
853+ path : notNull == true ? folder : '' ,
854854 value : real
855855 } ;
856856 }
857857
858- if ( notempty == true && typeof real != 'boolean' && typeof real != 'number' && StringUtil . isEmpty ( real , true ) ) { // 空
859- log ( 'compareWithStandard notempty == true && StringUtil.isEmpty(real, true) >> return COMPARE_VALUE_EMPTY' ) ;
858+ if ( notEmpty == true && typeof real != 'boolean' && typeof real != 'number' && StringUtil . isEmpty ( real , true ) ) { // 空
859+ log ( 'compareWithStandard notEmpty == true && StringUtil.isEmpty(real, true) >> return COMPARE_VALUE_EMPTY' ) ;
860860 return {
861861 code : JSONResponse . COMPARE_VALUE_EMPTY ,
862862 msg : '是空的' ,
@@ -1162,18 +1162,30 @@ var JSONResponse = {
11621162
11631163 getType : function ( o ) { //typeof [] = 'object'
11641164 if ( o == null ) {
1165- return 'object' ;
1165+ return 'object' ; // FIXME return null
11661166 }
1167+
11671168 if ( o instanceof Array ) {
11681169 return 'array' ;
11691170 }
11701171
1171- var t = typeof o ;
1172- if ( t == 'number' && Number . isInteger ( o ) ) {
1172+ if ( JSONResponse . isBoolean ( o ) ) {
1173+ return 'boolean' ;
1174+ }
1175+
1176+ if ( JSONResponse . isInteger ( o ) ) {
11731177 return 'integer' ;
11741178 }
11751179
1176- return t ;
1180+ if ( JSONResponse . isNumber ( o ) ) {
1181+ return 'number' ;
1182+ }
1183+
1184+ if ( JSONResponse . isString ( o ) ) {
1185+ return 'string' ;
1186+ }
1187+
1188+ return typeof o ;
11771189 } ,
11781190
11791191 isObject : function ( o ) {
@@ -1184,16 +1196,16 @@ var JSONResponse = {
11841196 return o instanceof Array ;
11851197 } ,
11861198 isString : function ( o ) {
1187- return typeof o == 'string' ;
1199+ return typeof o == 'string' || o instanceof String ;
11881200 } ,
11891201 isNumber : function ( o ) {
1190- return typeof o == 'number' ;
1202+ return typeof o == 'number' || o instanceof Number ;
11911203 } ,
11921204 isInteger : function ( o ) {
1193- return JSONResponse . getType ( o ) == 'integer' ;
1205+ return Number . isInteger ( o ) ;
11941206 } ,
11951207 isBoolean : function ( o ) {
1196- return typeof o == 'boolean' ;
1208+ return typeof o == 'boolean' || o instanceof Boolean ;
11971209 } ,
11981210
11991211
@@ -1282,16 +1294,16 @@ var JSONResponse = {
12821294 log ( '\n\n\n\n\nupdateStandard <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n' +
12831295 ' \ntarget = ' + JSON . stringify ( target , null , ' ' ) + '\n\n\nreal = ' + JSON . stringify ( real , null , ' ' ) ) ;
12841296
1285- var notnull = target . notnull ;
1286- log ( 'updateStandard notnull = target.notnull = ' + notnull + ' >>' ) ;
1287- if ( notnull == null ) {
1288- notnull = target . notnull = real != null ;
1297+ var notNull = target . notNull ;
1298+ log ( 'updateStandard notNull = target.notNull = ' + notNull + ' >>' ) ;
1299+ if ( notNull == null ) {
1300+ notNull = target . notNull = real != null ;
12891301 }
12901302
1291- var notempty = target . notempty ;
1292- log ( 'updateStandard notempty = target.notempty = ' + notempty + ' >>' ) ;
1303+ var notEmpty = target . notEmpty ;
1304+ log ( 'updateStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>' ) ;
12931305 if ( real != null && typeof real != 'boolean' && typeof real != 'number' ) {
1294- notempty = target . notempty = StringUtil . isNotEmpty ( real , true ) ;
1306+ notEmpty = target . notEmpty = StringUtil . isNotEmpty ( real , true ) ;
12951307 }
12961308
12971309 var type = target . type ;
@@ -1470,10 +1482,10 @@ var JSONResponse = {
14701482 // 解决总是报错缺少字段 delete real[k2]; // 解决总是多出来 key: null real[k2] = null;
14711483
14721484 if ( firstVal [ k2 ] == null ) {
1473- firstVal [ k2 ] = { notnull : false } ;
1485+ firstVal [ k2 ] = { notNull : false } ;
14741486 }
14751487 else {
1476- firstVal [ k2 ] . notnull = false ;
1488+ firstVal [ k2 ] . notNull = false ;
14771489 }
14781490 }
14791491 }
@@ -1559,6 +1571,71 @@ var JSONResponse = {
15591571 return target ;
15601572 } ,
15611573
1574+ /**根据 APIJSON 引用赋值路径精准地获取值
1575+ */
1576+ getValByPath : function ( target , pathKeys , isTry ) {
1577+ if ( target == null ) {
1578+ return null ;
1579+ }
1580+
1581+ var tgt = target ;
1582+ var depth = pathKeys == null ? 0 : pathKeys . length
1583+ if ( depth <= 0 ) {
1584+ return target ;
1585+ }
1586+
1587+ for ( var i = 0 ; i < depth ; i ++ ) {
1588+ if ( tgt == null ) {
1589+ return null ;
1590+ }
1591+
1592+ var k = pathKeys [ i ] ;
1593+ if ( k == null ) {
1594+ return null ;
1595+ }
1596+ k = decodeURI ( k )
1597+
1598+ if ( tgt instanceof Object ) {
1599+ if ( k == '' ) {
1600+ if ( tgt instanceof Array ) {
1601+ k = 0 ;
1602+ } else {
1603+ ks = Object . keys ( tgt ) ;
1604+ k = ks == null ? null : ks [ 0 ] ;
1605+ if ( k == null ) {
1606+ return null ;
1607+ }
1608+ }
1609+ }
1610+ else {
1611+ k = decodeURI ( k )
1612+ if ( tgt instanceof Array ) {
1613+ try {
1614+ var n = Number . parseInt ( k ) ;
1615+ if ( Number . isSafeInteger ( n ) ) {
1616+ k = n >= 0 ? n : n + tgt . length ;
1617+ }
1618+ } catch ( e ) {
1619+ }
1620+ }
1621+ }
1622+
1623+ tgt = tgt [ k ] ;
1624+
1625+ continue ;
1626+ }
1627+
1628+ if ( isTry != true ) {
1629+ throw new Error ( 'getValByPath 语法错误,' + k + ': value 中 value 类型应该是 Object 或 Array !' ) ;
1630+ }
1631+
1632+ return null ;
1633+ }
1634+
1635+ return tgt ;
1636+ } ,
1637+
1638+
15621639 /**根据路径精准地更新测试标准中的键值对
15631640 */
15641641 getStandardByPath : function ( target , pathKeys ) {
@@ -1590,12 +1667,15 @@ var JSONResponse = {
15901667 k = 0 ;
15911668 }
15921669 else {
1593- try {
1594- var n = Number . parseInt ( k ) ;
1595- if ( Number . isSafeInteger ( n ) ) {
1596- k = 0 ;
1597- }
1598- } catch ( e ) {
1670+ k = decodeURI ( k )
1671+ if ( tgt instanceof Array ) {
1672+ try {
1673+ var n = Number . parseInt ( k ) ;
1674+ if ( Number . isSafeInteger ( n ) ) {
1675+ k = n > 0 ? n : n + tgt . length ;
1676+ }
1677+ } catch ( e ) {
1678+ }
15991679 }
16001680 }
16011681
@@ -1664,7 +1744,7 @@ var JSONResponse = {
16641744 if ( child == null ) {
16651745 child = { } ;
16661746 child . type = typeof k == 'number' ? 'array' : 'number' ; // TODO 没看懂为啥是 array
1667- child . notnull = false ;
1747+ child . notNull = false ;
16681748 tgt . values [ 0 ] = child ;
16691749 }
16701750
@@ -1686,7 +1766,7 @@ var JSONResponse = {
16861766 }
16871767 var startsWithQuestion = comment . startsWith ( '?' )
16881768 tgt . type = JSONResponse . getType ( real ) ;
1689- tgt . notnull = real != null && startsWithQuestion != true
1769+ tgt . notNull = real != null && startsWithQuestion != true
16901770 tgt . comment = startsWithQuestion ? comment . substring ( 1 ) : comment
16911771
16921772 return target ;
0 commit comments