This repository was archived by the owner on Apr 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed
Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,51 @@ abstract class Expression implements Spec {
142142 );
143143 }
144144
145+ /// Returns the result of `this` `+` [other] .
146+ Expression operatorAdd (Expression other) {
147+ return new BinaryExpression ._(
148+ expression,
149+ other,
150+ '+' ,
151+ );
152+ }
153+
154+ /// Returns the result of `this` `-` [other] .
155+ Expression operatorSubstract (Expression other) {
156+ return new BinaryExpression ._(
157+ expression,
158+ other,
159+ '-' ,
160+ );
161+ }
162+
163+ /// Returns the result of `this` `/` [other] .
164+ Expression operatorDivide (Expression other) {
165+ return new BinaryExpression ._(
166+ expression,
167+ other,
168+ '/' ,
169+ );
170+ }
171+
172+ /// Returns the result of `this` `*` [other] .
173+ Expression operatorMultiply (Expression other) {
174+ return new BinaryExpression ._(
175+ expression,
176+ other,
177+ '*' ,
178+ );
179+ }
180+
181+ /// Returns the result of `this` `%` [other] .
182+ Expression operatorEuclideanModulo (Expression other) {
183+ return new BinaryExpression ._(
184+ expression,
185+ other,
186+ '%' ,
187+ );
188+ }
189+
145190 Expression conditional (Expression whenTrue, Expression whenFalse) {
146191 return new BinaryExpression ._(
147192 expression,
Original file line number Diff line number Diff line change @@ -412,4 +412,28 @@ void main() {
412412 equalsDart ('foo ? 1 : 2' ),
413413 );
414414 });
415+
416+ test ('should emit an operator add call' , () {
417+ expect (refer ('foo' ).operatorAdd (refer ('foo2' )), equalsDart ('foo + foo2' ));
418+ });
419+
420+ test ('should emit an operator substract call' , () {
421+ expect (refer ('foo' ).operatorSubstract (refer ('foo2' )),
422+ equalsDart ('foo - foo2' ));
423+ });
424+
425+ test ('should emit an operator divide call' , () {
426+ expect (
427+ refer ('foo' ).operatorDivide (refer ('foo2' )), equalsDart ('foo / foo2' ));
428+ });
429+
430+ test ('should emit an operator multiply call' , () {
431+ expect (
432+ refer ('foo' ).operatorMultiply (refer ('foo2' )), equalsDart ('foo * foo2' ));
433+ });
434+
435+ test ('should emit an euclidean modulo operator call' , () {
436+ expect (refer ('foo' ).operatorEuclideanModulo (refer ('foo2' )),
437+ equalsDart ('foo % foo2' ));
438+ });
415439}
You can’t perform that action at this time.
0 commit comments