Skip to content

Commit bb87efd

Browse files
committed
add tests
1 parent 38deb73 commit bb87efd

File tree

3 files changed

+347
-28
lines changed

3 files changed

+347
-28
lines changed

Firestore/Swift/Source/ExprImpl.swift

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ public extension Expr {
2525

2626
// MARK: Arithmetic Operators
2727

28-
func add(_ second: Expr, _ others: Expr...) -> FunctionExpr {
29-
return FunctionExpr("add", [self, second] + others)
28+
func add(_ values: Expr) -> FunctionExpr {
29+
return FunctionExpr("add", [self, Helper.array([values])])
3030
}
3131

32-
func add(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
33-
let exprs = [self] + [Helper.sendableToExpr(second)] + others
34-
.map { Helper.sendableToExpr($0) }
35-
return FunctionExpr("add", exprs)
32+
func add(_ values: Sendable) -> FunctionExpr {
33+
return FunctionExpr("add", [self, Helper.array([values])])
34+
}
35+
36+
func add(_ values: [Expr]) -> FunctionExpr {
37+
return FunctionExpr("add", [self, Helper.array(values)])
38+
}
39+
40+
func add(_ values: [Sendable]) -> FunctionExpr {
41+
return FunctionExpr("add", [self, Helper.array(values)])
3642
}
3743

3844
func subtract(_ other: Expr) -> FunctionExpr {
@@ -43,14 +49,20 @@ public extension Expr {
4349
return FunctionExpr("subtract", [self, Helper.sendableToExpr(other)])
4450
}
4551

46-
func multiply(_ second: Expr, _ others: Expr...) -> FunctionExpr {
47-
return FunctionExpr("multiply", [self, second] + others)
52+
func multiply(_ values: Expr) -> FunctionExpr {
53+
return FunctionExpr("multiply", [self, Helper.array([values])])
4854
}
4955

50-
func multiply(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
51-
let exprs = [self] + [Helper.sendableToExpr(second)] + others
52-
.map { Helper.sendableToExpr($0) }
53-
return FunctionExpr("multiply", exprs)
56+
func multiply(_ values: Sendable) -> FunctionExpr {
57+
return FunctionExpr("multiply", [self, Helper.array([values])])
58+
}
59+
60+
func multiply(_ values: [Expr]) -> FunctionExpr {
61+
return FunctionExpr("multiply", [self, Helper.array(values)])
62+
}
63+
64+
func multiply(_ values: [Sendable]) -> FunctionExpr {
65+
return FunctionExpr("multiply", [self, Helper.array(values)])
5466
}
5567

5668
func divide(_ other: Expr) -> FunctionExpr {
@@ -170,12 +182,12 @@ public extension Expr {
170182
return BooleanExpr("eq", [self, exprOther])
171183
}
172184

173-
func neq(_ others: [Expr]) -> BooleanExpr {
174-
return BooleanExpr("neq", [self, Helper.array(others)])
185+
func neq(_ other: Expr) -> BooleanExpr {
186+
return BooleanExpr("neq", [self, other])
175187
}
176188

177-
func neq(_ others: [Sendable]) -> BooleanExpr {
178-
return BooleanExpr("neq", [self, Helper.array(others)])
189+
func neq(_ other: Sendable) -> BooleanExpr {
190+
return BooleanExpr("neq", [self, Helper.sendableToExpr(other)])
179191
}
180192

181193
func eqAny(_ others: [Expr]) -> BooleanExpr {

Firestore/Swift/Source/SwiftAPI/Pipeline/Expr.swift

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public protocol Expr: Sendable {
4949
/// Field("subtotal").add(Field("tax"), Field("shipping"))
5050
/// ```
5151
///
52-
/// - Parameter second: An `Expr` to add to this expression.
53-
/// - Parameter others: Optional additional `Expr` values to add.
52+
/// - Parameter value: Expr` values to add.
5453
/// - Returns: A new `FunctionExpr` representing the addition operation.
55-
func add(_ second: Expr, _ others: Expr...) -> FunctionExpr
54+
func add(_ value: Expr) -> FunctionExpr
5655

5756
/// Creates an expression that adds this expression to one or more literal values.
5857
/// Assumes `self` and all parameters evaluate to compatible types for addition.
@@ -65,10 +64,40 @@ public protocol Expr: Sendable {
6564
/// Field("score").add(10, 20, -5)
6665
/// ```
6766
///
68-
/// - Parameter second: A `Sendable` literal value to add to this expression.
69-
/// - Parameter others: Optional additional `Sendable` literal values to add.
67+
/// - Parameter value: Expr` value to add.
7068
/// - Returns: A new `FunctionExpr` representing the addition operation.
71-
func add(_ second: Sendable, _ others: Sendable...) -> FunctionExpr
69+
func add(_ value: Sendable) -> FunctionExpr
70+
71+
/// Creates an expression that adds this expression to one or more other expressions.
72+
/// Assumes `self` and all parameters evaluate to compatible types for addition (e.g., numbers, or
73+
/// string/array concatenation if supported by the specific "add" implementation).
74+
///
75+
/// ```swift
76+
/// // Add the value of the 'quantity' field and the 'reserve' field.
77+
/// Field("quantity").add(Field("reserve"))
78+
///
79+
/// // Add multiple numeric fields
80+
/// Field("subtotal").add(Field("tax"), Field("shipping"))
81+
/// ```
82+
///
83+
/// - Parameter values: Expr` values to add.
84+
/// - Returns: A new `FunctionExpr` representing the addition operation.
85+
func add(_ values: [Expr]) -> FunctionExpr
86+
87+
/// Creates an expression that adds this expression to one or more literal values.
88+
/// Assumes `self` and all parameters evaluate to compatible types for addition.
89+
///
90+
/// ```swift
91+
/// // Add 5 to the 'count' field
92+
/// Field("count").add(5)
93+
///
94+
/// // Add multiple literal numbers
95+
/// Field("score").add(10, 20, -5)
96+
/// ```
97+
///
98+
/// - Parameter values: Expr` values to add.
99+
/// - Returns: A new `FunctionExpr` representing the addition operation.
100+
func add(_ values: [Sendable]) -> FunctionExpr
72101

73102
/// Creates an expression that subtracts another expression from this expression.
74103
/// Assumes `self` and `other` evaluate to numeric types.
@@ -105,10 +134,39 @@ public protocol Expr: Sendable {
105134
/// Field("rate").multiply(Field("time"), Field("conversionFactor"))
106135
/// ```
107136
///
108-
/// - Parameter second: An `Expr` to multiply by.
109-
/// - Parameter others: Optional additional `Expr` values to multiply by.
137+
/// - Parameter value: `Expr` value to multiply by.
138+
/// - Returns: A new `FunctionExpr` representing the multiplication operation.
139+
func multiply(_ value: Expr) -> FunctionExpr
140+
141+
/// Creates an expression that multiplies this expression by one or more literal values.
142+
/// Assumes `self` evaluates to a numeric type.
143+
///
144+
/// ```swift
145+
/// // Multiply the 'score' by 1.1
146+
/// Field("score").multiply(1.1)
147+
///
148+
/// // Multiply 'base' by 2 and then by 3.0
149+
/// Field("base").multiply(2, 3.0)
150+
/// ```
151+
///
152+
/// - Parameter value: `Sendable` literal value to multiply by.
153+
/// - Returns: A new `FunctionExpr` representing the multiplication operation.
154+
func multiply(_ value: Sendable) -> FunctionExpr
155+
156+
/// Creates an expression that multiplies this expression by one or more other expressions.
157+
/// Assumes `self` and all parameters evaluate to numeric types.
158+
///
159+
/// ```swift
160+
/// // Multiply the 'quantity' field by the 'price' field
161+
/// Field("quantity").multiply(Field("price"))
162+
///
163+
/// // Multiply 'rate' by 'time' and 'conversionFactor' fields
164+
/// Field("rate").multiply(Field("time"), Field("conversionFactor"))
165+
/// ```
166+
///
167+
/// - Parameter values: `Expr` values to multiply by.
110168
/// - Returns: A new `FunctionExpr` representing the multiplication operation.
111-
func multiply(_ second: Expr, _ others: Expr...) -> FunctionExpr
169+
func multiply(_ values: [Expr]) -> FunctionExpr
112170

113171
/// Creates an expression that multiplies this expression by one or more literal values.
114172
/// Assumes `self` evaluates to a numeric type.
@@ -121,10 +179,9 @@ public protocol Expr: Sendable {
121179
/// Field("base").multiply(2, 3.0)
122180
/// ```
123181
///
124-
/// - Parameter second: A `Sendable` literal value to multiply by.
125-
/// - Parameter others: Optional additional `Sendable` literal values to multiply by.
182+
/// - Parameter values: `Sendable` literal values to multiply by.
126183
/// - Returns: A new `FunctionExpr` representing the multiplication operation.
127-
func multiply(_ second: Sendable, _ others: Sendable...) -> FunctionExpr
184+
func multiply(_ values: [Sendable]) -> FunctionExpr
128185

129186
/// Creates an expression that divides this expression by another expression.
130187
/// Assumes `self` and `other` evaluate to numeric types.

0 commit comments

Comments
 (0)