@@ -122,6 +122,208 @@ type ScriptTestAssertion struct {
122122// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
123123// the tests.
124124var ScriptTests = []ScriptTest {
125+ {
126+ // https://github.com/dolthub/dolt/issues/9916
127+ Name : "TRUNCATE(X,D) function behavior" ,
128+ SetUpScript : []string {},
129+ Assertions : []ScriptTestAssertion {
130+ {
131+ Query : "SELECT TRUNCATE(1.223,1)" ,
132+ Expected : []sql.Row {
133+ {"1.2" },
134+ },
135+ },
136+ {
137+ Query : "SELECT TRUNCATE(1.999,1)" ,
138+ Expected : []sql.Row {
139+ {"1.9" },
140+ },
141+ },
142+ {
143+ Query : "SELECT TRUNCATE(1.999,0)" ,
144+ Expected : []sql.Row {
145+ {"1" },
146+ },
147+ },
148+ {
149+ Query : "SELECT TRUNCATE(-1.999,1)" ,
150+ Expected : []sql.Row {
151+ {"-1.9" },
152+ },
153+ },
154+ {
155+ Query : "SELECT TRUNCATE(122,-2)" ,
156+ Expected : []sql.Row {
157+ {100 },
158+ },
159+ },
160+ {
161+ Query : "SELECT TRUNCATE(10.28*100,0)" ,
162+ Expected : []sql.Row {
163+ {"1028" },
164+ },
165+ },
166+ {
167+ Query : "SELECT TRUNCATE(NULL,1)" ,
168+ Expected : []sql.Row {
169+ {nil },
170+ },
171+ },
172+ {
173+ Query : "SELECT TRUNCATE(1.223,NULL)" ,
174+ Expected : []sql.Row {
175+ {nil },
176+ },
177+ },
178+ {
179+ Query : "SELECT TRUNCATE(0.5,0)" ,
180+ Expected : []sql.Row {
181+ {"0" },
182+ },
183+ },
184+ {
185+ Query : "SELECT TRUNCATE(-0.5,0)" ,
186+ Expected : []sql.Row {
187+ {"0" },
188+ },
189+ },
190+ {
191+ Query : "SELECT TRUNCATE(1.223,100)" ,
192+ Expected : []sql.Row {
193+ {"1.223" },
194+ },
195+ },
196+ {
197+ Query : "SELECT TRUNCATE(1.223,-100)" ,
198+ Expected : []sql.Row {
199+ {"0" },
200+ },
201+ },
202+ {
203+ Query : "SELECT TRUNCATE('abc',1)" ,
204+ Expected : []sql.Row {
205+ {0.0 },
206+ },
207+ },
208+ {
209+ Query : "SELECT TRUNCATE(1.223,'xyz')" ,
210+ Expected : []sql.Row {
211+ {"1" },
212+ },
213+ },
214+ {
215+ Query : "SELECT TRUNCATE(1.223,1.5)" ,
216+ Expected : []sql.Row {
217+ {"1.22" },
218+ },
219+ },
220+ {
221+ Query : "SELECT TRUNCATE(1.223,1.7)" ,
222+ Expected : []sql.Row {
223+ {"1.22" },
224+ },
225+ },
226+ {
227+ Query : "SELECT TRUNCATE(1.223,0.1)" ,
228+ Expected : []sql.Row {
229+ {"1" },
230+ },
231+ },
232+ {
233+ Query : "SELECT TRUNCATE(1.223,0.9)" ,
234+ Expected : []sql.Row {
235+ {"1.2" },
236+ },
237+ },
238+ {
239+ Query : "SELECT TRUNCATE(1.223,-0.5)" ,
240+ Expected : []sql.Row {
241+ {"0" },
242+ },
243+ },
244+ {
245+ Query : "SELECT TRUNCATE(1.223,-0.9)" ,
246+ Expected : []sql.Row {
247+ {"0" },
248+ },
249+ },
250+ {
251+ Query : "SELECT TRUNCATE('123abc',1)" ,
252+ Expected : []sql.Row {
253+ {123.0 },
254+ },
255+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
256+ ExpectedWarningsCount : 1 ,
257+ ExpectedWarningMessageSubstring : "Truncated incorrect DOUBLE value" ,
258+ },
259+ {
260+ Query : "SELECT TRUNCATE('1.5abc',1)" ,
261+ Expected : []sql.Row {
262+ {1.5 },
263+ },
264+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
265+ ExpectedWarningsCount : 1 ,
266+ ExpectedWarningMessageSubstring : "Truncated incorrect DOUBLE value" ,
267+ },
268+ {
269+ Query : "SELECT TRUNCATE('999xyz',2)" ,
270+ Expected : []sql.Row {
271+ {999.0 },
272+ },
273+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
274+ ExpectedWarningsCount : 1 ,
275+ ExpectedWarningMessageSubstring : "Truncated incorrect DOUBLE value" ,
276+ },
277+ {
278+ Query : "SELECT TRUNCATE(1.223,'1.5abc')" ,
279+ Expected : []sql.Row {
280+ {"1.2" },
281+ },
282+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
283+ ExpectedWarningsCount : 2 , // Both input and precision conversions generate warnings
284+ ExpectedWarningMessageSubstring : "Truncated incorrect int value" ,
285+ },
286+ {
287+ Query : "SELECT TRUNCATE(1.223,'0.5')" ,
288+ Expected : []sql.Row {
289+ {"1" },
290+ },
291+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
292+ ExpectedWarningsCount : 2 , // Both input and precision conversions generate warnings
293+ ExpectedWarningMessageSubstring : "Truncated incorrect int value" ,
294+ },
295+ {
296+ Query : "SELECT TRUNCATE(1.223,'2.7')" ,
297+ Expected : []sql.Row {
298+ {"1.22" },
299+ },
300+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
301+ ExpectedWarningsCount : 2 , // Both input and precision conversions generate warnings
302+ ExpectedWarningMessageSubstring : "Truncated incorrect int value" ,
303+ },
304+ {
305+ Query : "SELECT TRUNCATE(1.223,'invalid_precision')" ,
306+ Expected : []sql.Row {
307+ {"1" },
308+ },
309+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
310+ ExpectedWarningsCount : 2 , // Both input and precision conversions generate warnings
311+ ExpectedWarningMessageSubstring : "Truncated incorrect int value" ,
312+ },
313+ {
314+ Query : "SELECT TRUNCATE()" ,
315+ ExpectedErrStr : "syntax error" ,
316+ },
317+ {
318+ Query : "SELECT TRUNCATE(1)" ,
319+ ExpectedErrStr : "syntax error" ,
320+ },
321+ {
322+ Query : "SELECT TRUNCATE(1,2,3)" ,
323+ ExpectedErrStr : "syntax error" ,
324+ },
325+ },
326+ },
125327 {
126328 // https://github.com/dolthub/dolt/issues/9865
127329 Name : "Stored procedure containing a transaction does not return EOF" ,
0 commit comments