@@ -815,11 +815,11 @@ var JSONResponse = {
815
815
var guess = target . guess ;
816
816
log ( 'compareWithStandard guess = target.guess = ' + guess + ' >>' ) ;
817
817
818
- var notnull = target . notnull ;
819
- log ( 'compareWithStandard notnull = target.notnull = ' + notnull + ' >>' ) ;
818
+ var notNull = target . notNull ;
819
+ log ( 'compareWithStandard notNull = target.notNull = ' + notNull + ' >>' ) ;
820
820
821
- var notempty = target . notempty ;
822
- log ( 'compareWithStandard notempty = target.notempty = ' + notempty + ' >>' ) ;
821
+ var notEmpty = target . notEmpty ;
822
+ log ( 'compareWithStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>' ) ;
823
823
824
824
var type = target . type ;
825
825
log ( 'compareWithStandard type = target.type = ' + type + ' >>' ) ;
@@ -832,8 +832,8 @@ var JSONResponse = {
832
832
var firstVal = values == null || values . length <= 0 ? null : values [ 0 ] ;
833
833
834
834
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 必须为有值的数组 !' ) ;
837
837
}
838
838
839
839
log ( 'compareWithStandard values == null; real ' + ( real == null ? '=' : '!' ) + '= null >> return ' + ( real == null ? 'COMPARE_EQUAL' : 'COMPARE_KEY_MORE' ) ) ;
@@ -846,17 +846,17 @@ var JSONResponse = {
846
846
}
847
847
848
848
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' ) ) ;
850
850
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 : '' ,
854
854
value : real
855
855
} ;
856
856
}
857
857
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' ) ;
860
860
return {
861
861
code : JSONResponse . COMPARE_VALUE_EMPTY ,
862
862
msg : '是空的' ,
@@ -1162,18 +1162,30 @@ var JSONResponse = {
1162
1162
1163
1163
getType : function ( o ) { //typeof [] = 'object'
1164
1164
if ( o == null ) {
1165
- return 'object' ;
1165
+ return 'object' ; // FIXME return null
1166
1166
}
1167
+
1167
1168
if ( o instanceof Array ) {
1168
1169
return 'array' ;
1169
1170
}
1170
1171
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 ) ) {
1173
1177
return 'integer' ;
1174
1178
}
1175
1179
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 ;
1177
1189
} ,
1178
1190
1179
1191
isObject : function ( o ) {
@@ -1184,16 +1196,16 @@ var JSONResponse = {
1184
1196
return o instanceof Array ;
1185
1197
} ,
1186
1198
isString : function ( o ) {
1187
- return typeof o == 'string' ;
1199
+ return typeof o == 'string' || o instanceof String ;
1188
1200
} ,
1189
1201
isNumber : function ( o ) {
1190
- return typeof o == 'number' ;
1202
+ return typeof o == 'number' || o instanceof Number ;
1191
1203
} ,
1192
1204
isInteger : function ( o ) {
1193
- return JSONResponse . getType ( o ) == 'integer' ;
1205
+ return Number . isInteger ( o ) ;
1194
1206
} ,
1195
1207
isBoolean : function ( o ) {
1196
- return typeof o == 'boolean' ;
1208
+ return typeof o == 'boolean' || o instanceof Boolean ;
1197
1209
} ,
1198
1210
1199
1211
@@ -1282,16 +1294,16 @@ var JSONResponse = {
1282
1294
log ( '\n\n\n\n\nupdateStandard <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n' +
1283
1295
' \ntarget = ' + JSON . stringify ( target , null , ' ' ) + '\n\n\nreal = ' + JSON . stringify ( real , null , ' ' ) ) ;
1284
1296
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 ;
1289
1301
}
1290
1302
1291
- var notempty = target . notempty ;
1292
- log ( 'updateStandard notempty = target.notempty = ' + notempty + ' >>' ) ;
1303
+ var notEmpty = target . notEmpty ;
1304
+ log ( 'updateStandard notEmpty = target.notEmpty = ' + notEmpty + ' >>' ) ;
1293
1305
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 ) ;
1295
1307
}
1296
1308
1297
1309
var type = target . type ;
@@ -1470,10 +1482,10 @@ var JSONResponse = {
1470
1482
// 解决总是报错缺少字段 delete real[k2]; // 解决总是多出来 key: null real[k2] = null;
1471
1483
1472
1484
if ( firstVal [ k2 ] == null ) {
1473
- firstVal [ k2 ] = { notnull : false } ;
1485
+ firstVal [ k2 ] = { notNull : false } ;
1474
1486
}
1475
1487
else {
1476
- firstVal [ k2 ] . notnull = false ;
1488
+ firstVal [ k2 ] . notNull = false ;
1477
1489
}
1478
1490
}
1479
1491
}
@@ -1559,6 +1571,71 @@ var JSONResponse = {
1559
1571
return target ;
1560
1572
} ,
1561
1573
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
+
1562
1639
/**根据路径精准地更新测试标准中的键值对
1563
1640
*/
1564
1641
getStandardByPath : function ( target , pathKeys ) {
@@ -1590,12 +1667,15 @@ var JSONResponse = {
1590
1667
k = 0 ;
1591
1668
}
1592
1669
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
+ }
1599
1679
}
1600
1680
}
1601
1681
@@ -1664,7 +1744,7 @@ var JSONResponse = {
1664
1744
if ( child == null ) {
1665
1745
child = { } ;
1666
1746
child . type = typeof k == 'number' ? 'array' : 'number' ; // TODO 没看懂为啥是 array
1667
- child . notnull = false ;
1747
+ child . notNull = false ;
1668
1748
tgt . values [ 0 ] = child ;
1669
1749
}
1670
1750
@@ -1686,7 +1766,7 @@ var JSONResponse = {
1686
1766
}
1687
1767
var startsWithQuestion = comment . startsWith ( '?' )
1688
1768
tgt . type = JSONResponse . getType ( real ) ;
1689
- tgt . notnull = real != null && startsWithQuestion != true
1769
+ tgt . notNull = real != null && startsWithQuestion != true
1690
1770
tgt . comment = startsWithQuestion ? comment . substring ( 1 ) : comment
1691
1771
1692
1772
return target ;
0 commit comments