File tree Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,30 @@ modes.forEach((logic) => {
4040 } )
4141 expect ( answer ) . toBe ( - 4 )
4242 } )
43+
44+ test ( 'it should be able to negate a single number' , async ( ) => {
45+ const answer = await logic . run ( {
46+ '-' : [ 1 ]
47+ } )
48+
49+ expect ( answer ) . toBe ( - 1 )
50+ } )
51+
52+ test ( 'it should be able to negate a single number in an array' , async ( ) => {
53+ const answer = await logic . run ( {
54+ '-' : 1
55+ } )
56+
57+ expect ( answer ) . toBe ( - 1 )
58+ } )
59+
60+ test ( 'it should be able to negate Infinity' , async ( ) => {
61+ const answer = await logic . run ( {
62+ '-' : Infinity
63+ } )
64+
65+ expect ( answer ) . toBe ( - Infinity )
66+ } )
4367 } )
4468
4569 describe ( '*' , ( ) => {
Original file line number Diff line number Diff line change @@ -40,12 +40,24 @@ function timeout (n, x) {
4040 expect ( await f ( ) ) . toEqual ( - 5 )
4141 } )
4242
43+ test ( 'Minus operator w/ Infinity' , async ( ) => {
44+ const f = await logic . build ( { '-' : Infinity } )
45+
46+ expect ( await f ( ) ) . toEqual ( - Infinity )
47+ } )
48+
4349 test ( 'Minus operator w/ array w/ variable input' , async ( ) => {
4450 const f = await logic . build ( { '-' : [ { preserve : 5 } ] } )
4551
4652 expect ( await f ( ) ) . toEqual ( - 5 )
4753 } )
4854
55+ test ( 'Minus operator w/ array w/ variable input (Infinity)' , async ( ) => {
56+ const f = await logic . build ( { '-' : [ { preserve : Infinity } ] } )
57+
58+ expect ( await f ( ) ) . toEqual ( - Infinity )
59+ } )
60+
4961 test ( 'Minus operator w/ variable input' , async ( ) => {
5062 const f = await logic . build ( { '-' : { preserve : '5' } } )
5163
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ import asyncIterators from './async_iterators.js'
3737 * @returns
3838 */
3939function isPrimitive ( x ) {
40+ if ( typeof x === 'number' && ( x === Infinity || x === - Infinity || Number . isNaN ( x ) ) ) return false
4041 return (
4142 x === null ||
4243 x === undefined ||
Original file line number Diff line number Diff line change 11{
22 "name" : " json-logic-engine" ,
3- "version" : " 1.1.21 " ,
3+ "version" : " 1.1.22 " ,
44 "description" : " Construct complex rules with JSON & process them." ,
55 "main" : " ./dist/cjs/index.js" ,
66 "module" : " ./dist/esm/index.js" ,
Original file line number Diff line number Diff line change @@ -44,6 +44,30 @@ modes.forEach((logic) => {
4444
4545 expect ( answer ) . toBe ( - 4 )
4646 } )
47+
48+ test ( 'it should be able to negate a single number' , ( ) => {
49+ const answer = logic . run ( {
50+ '-' : [ 1 ]
51+ } )
52+
53+ expect ( answer ) . toBe ( - 1 )
54+ } )
55+
56+ test ( 'it should be able to negate a single number in an array' , ( ) => {
57+ const answer = logic . run ( {
58+ '-' : 1
59+ } )
60+
61+ expect ( answer ) . toBe ( - 1 )
62+ } )
63+
64+ test ( 'it should be able to negate Infinity' , ( ) => {
65+ const answer = logic . run ( {
66+ '-' : Infinity
67+ } )
68+
69+ expect ( answer ) . toBe ( - Infinity )
70+ } )
4771 } )
4872
4973 describe ( '*' , ( ) => {
You can’t perform that action at this time.
0 commit comments