Skip to content

Commit 99f5b8d

Browse files
Fix extreme values test and add REAL formatting test
- Set SQLCMDMAXVARTYPEWIDTH in TestFormatterFloatFormattingExtremeValues to enable fallback behavior testing - Add TestFormatterRealFormatting to test float32 (REAL) column formatting with both typical and extreme values Co-authored-by: dlevy-msft-sql <[email protected]>
1 parent 9a407bb commit 99f5b8d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

pkg/sqlcmd/format_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func TestFormatterFloatFormattingExtremeValues(t *testing.T) {
201201
s, buf := setupSqlCmdWithMemoryOutput(t)
202202
defer buf.Close()
203203

204+
// Set SQLCMDMAXVARTYPEWIDTH to a non-zero value so FLOAT columns use the 24-char display width
205+
// This allows the fallback behavior to be tested
206+
s.vars.Set(SQLCMDMAXVARTYPEWIDTH, "256")
207+
204208
// Test query with extreme float values that would exceed the 24-char display width
205209
query := `SELECT
206210
CAST(1e100 AS FLOAT) as VeryLarge,
@@ -218,3 +222,29 @@ func TestFormatterFloatFormattingExtremeValues(t *testing.T) {
218222
// Verify that extremely small values use scientific notation with negative exponent
219223
assert.Contains(t, output, "e-", "Output should contain scientific notation (e-) for very small values")
220224
}
225+
226+
func TestFormatterRealFormatting(t *testing.T) {
227+
// Test that REAL (float32) values use decimal notation for typical values
228+
// and fall back to scientific notation for extreme values
229+
s, buf := setupSqlCmdWithMemoryOutput(t)
230+
defer buf.Close()
231+
232+
// Set SQLCMDMAXVARTYPEWIDTH to a non-zero value so REAL columns use the 14-char display width
233+
s.vars.Set(SQLCMDMAXVARTYPEWIDTH, "256")
234+
235+
// Test query with REAL values (both typical and extreme)
236+
query := `SELECT
237+
CAST(123.456789 AS REAL) as TypicalValue,
238+
CAST(1e30 AS REAL) as ExtremeValue`
239+
240+
err := runSqlCmd(t, s, []string{query, "GO"})
241+
assert.NoError(t, err, "runSqlCmd returned error")
242+
243+
output := buf.buf.String()
244+
245+
// Verify that typical REAL values use decimal notation
246+
assert.Contains(t, output, "123.456", "Output should contain decimal representation of typical REAL value")
247+
248+
// Verify that extreme REAL values use scientific notation
249+
assert.Contains(t, output, "e+", "Output should contain scientific notation for extreme REAL value")
250+
}

0 commit comments

Comments
 (0)