aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/v/tests/string_interpolation_floats_test.v
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/vlib/v/tests/string_interpolation_floats_test.v')
-rw-r--r--v_windows/v/vlib/v/tests/string_interpolation_floats_test.v29
1 files changed, 29 insertions, 0 deletions
diff --git a/v_windows/v/vlib/v/tests/string_interpolation_floats_test.v b/v_windows/v/vlib/v/tests/string_interpolation_floats_test.v
new file mode 100644
index 0000000..5809f68
--- /dev/null
+++ b/v_windows/v/vlib/v/tests/string_interpolation_floats_test.v
@@ -0,0 +1,29 @@
+fn test_f32_widths_and_precision() {
+ x := f32(200.43)
+ assert '|${x:10.4f}|' == '| 200.4300|'
+ assert '|${x:-10.4f}|' == '|200.4300 |'
+ assert '|${x:10.0f}|' == '| 200|'
+ assert '|${x:-10.0f}|' == '|200 |'
+ //
+ assert '|${x:0.4f}|' == '|200.4300|'
+ assert '|${x:.3f}|' == '|200.430|'
+ assert '|${x:.0f}|' == '|200|'
+ //
+ y := f32(200.90)
+ assert '|${y:.0f}|' == '|201|'
+}
+
+fn test_f64_widths_and_precision() {
+ x := f64(200.43)
+ assert '|${x:10.4f}|' == '| 200.4300|'
+ assert '|${x:-10.4f}|' == '|200.4300 |'
+ assert '|${x:10.0f}|' == '| 200|'
+ assert '|${x:-10.0f}|' == '|200 |'
+ //
+ assert '|${x:0.4f}|' == '|200.4300|'
+ assert '|${x:.3f}|' == '|200.430|'
+ assert '|${x:.0f}|' == '|200|'
+ //
+ y := f64(200.90)
+ assert '|${y:.0f}|' == '|201|'
+}