Skip to content

Commit 9bc7b47

Browse files
committed
Add decimal binding tests
1 parent 65e1826 commit 9bc7b47

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

Tests/StructuredQueriesTests/BindingTests.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,114 @@ extension SnapshotTests {
8888
"""
8989
}
9090
}
91+
92+
@Test func decimals() throws {
93+
assertQuery(
94+
SimpleSelect {
95+
Decimal(123.45).in([Decimal(100), Decimal(200)])
96+
}
97+
) {
98+
"""
99+
SELECT ('123.45' IN ('100', '200'))
100+
"""
101+
} results: {
102+
"""
103+
┌───────┐
104+
│ false │
105+
└───────┘
106+
"""
107+
}
108+
}
109+
110+
@Test func decimalPrecision() throws {
111+
assertQuery(
112+
SimpleSelect {
113+
Decimal(string: "123.456789")!
114+
}
115+
) {
116+
"""
117+
SELECT '123.456789'
118+
"""
119+
} results: {
120+
"""
121+
┌─────────────┐
122+
│ 123.456789 │
123+
└─────────────┘
124+
"""
125+
}
126+
}
127+
128+
@Test func decimalZero() throws {
129+
assertQuery(
130+
SimpleSelect {
131+
Decimal.zero
132+
}
133+
) {
134+
"""
135+
SELECT '0'
136+
"""
137+
} results: {
138+
"""
139+
┌───┐
140+
│ 0 │
141+
└───┘
142+
"""
143+
}
144+
}
145+
146+
@Test func decimalNegative() throws {
147+
assertQuery(
148+
SimpleSelect {
149+
Decimal(string: "-999.123")!
150+
}
151+
) {
152+
"""
153+
SELECT '-999.123'
154+
"""
155+
} results: {
156+
"""
157+
┌──────────┐
158+
│ -999.123 │
159+
└──────────┘
160+
"""
161+
}
162+
}
163+
164+
@Test func decimalHighPrecision() throws {
165+
assertQuery(
166+
SimpleSelect {
167+
Decimal(string: "123456789012345678901234567890.123456789")!
168+
}
169+
) {
170+
"""
171+
SELECT '123456789012345678901234567890.123456789'
172+
"""
173+
} results: {
174+
"""
175+
┌─────────────────────────────────────────────┐
176+
│ 123456789012345678901234567890.123456789 │
177+
└─────────────────────────────────────────────┘
178+
"""
179+
}
180+
}
181+
182+
@Test func decimalRepeatingFraction() throws {
183+
assertQuery(
184+
SimpleSelect {
185+
Decimal(string: "0.333333333333333333333333333333333333")!
186+
}
187+
) {
188+
"""
189+
SELECT '0.333333333333333333333333333333333333'
190+
"""
191+
} results: {
192+
"""
193+
┌────────────────────────────────────────┐
194+
│ 0.333333333333333333333333333333333333 │
195+
└────────────────────────────────────────┘
196+
"""
197+
}
198+
}
91199
}
92200
}
93201

0 commit comments

Comments
 (0)