File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -51,4 +51,12 @@ export class Expression {
51
51
matches ( schema ) {
52
52
return this . validate ( schema ) . valid
53
53
}
54
+
55
+ add ( expression ) {
56
+ if ( this . schema . maxItems ) {
57
+ return Expression . build ( { All : [ this , expression ] } )
58
+ } else {
59
+ return this . clone ( { args : [ ...this . args , expression ] } )
60
+ }
61
+ }
54
62
}
Original file line number Diff line number Diff line change @@ -85,4 +85,21 @@ describe('Expression', () => {
85
85
expect ( expression . validate ( ) . valid ) . toBe ( false )
86
86
} )
87
87
} )
88
+
89
+ describe ( 'add' , ( ) => {
90
+ test ( 'Any returns new expression with added arg' , ( ) => {
91
+ const expression = Expression . build ( { Any : [ ] } ) . add ( true )
92
+ expect ( expression . value ) . toEqual ( { Any : [ true ] } )
93
+ } )
94
+
95
+ test ( 'Max returns new expression with added arg' , ( ) => {
96
+ const expression = Expression . build ( { Max : [ 1 ] } ) . add ( 2 )
97
+ expect ( expression . value ) . toEqual ( { Max : [ 1 , 2 ] } )
98
+ } )
99
+
100
+ test ( 'Equal returns new expression wrapped in All' , ( ) => {
101
+ const expression = Expression . build ( { Equal : [ 1 , 1 ] } ) . add ( false )
102
+ expect ( expression . value ) . toEqual ( { All : [ { Equal : [ 1 , 1 ] } , false ] } )
103
+ } )
104
+ } )
88
105
} )
You can’t perform that action at this time.
0 commit comments