v.fmt: keep `[ ... \n 123, // end of line comment \n ... ]` as is
parent
9f6ddb4c21
commit
5dff8dc097
|
@ -1,9 +1,9 @@
|
|||
import strconv
|
||||
/**********************************************************************
|
||||
*
|
||||
* Float to string Test
|
||||
*
|
||||
**********************************************************************/
|
||||
import strconv
|
||||
import math
|
||||
|
||||
union Ufloat32 {
|
||||
|
@ -57,26 +57,26 @@ fn test_float_to_str() {
|
|||
]
|
||||
|
||||
exp_result_f32 := [
|
||||
"0e+00",
|
||||
"-0e+00",
|
||||
"nan",
|
||||
"nan",
|
||||
"+inf",
|
||||
"-inf",
|
||||
"1.e+00",
|
||||
"-1.e+00",
|
||||
"1.e+01",
|
||||
"-1.e+01",
|
||||
"3.e-01",
|
||||
"-3.e-01",
|
||||
"1.e+06",
|
||||
"1.234567e+05",
|
||||
"1.23e+37",
|
||||
"-1.2345e+02",
|
||||
"1.e+23",
|
||||
"1.1754944e-38", // aprox from 1.1754943508 × 10−38,
|
||||
"3.4028235e+38",
|
||||
"3.8326058e+17",
|
||||
'0e+00',
|
||||
'-0e+00',
|
||||
'nan',
|
||||
'nan',
|
||||
'+inf',
|
||||
'-inf',
|
||||
'1.e+00',
|
||||
'-1.e+00',
|
||||
'1.e+01',
|
||||
'-1.e+01',
|
||||
'3.e-01',
|
||||
'-3.e-01',
|
||||
'1.e+06',
|
||||
'1.234567e+05',
|
||||
'1.23e+37',
|
||||
'-1.2345e+02',
|
||||
'1.e+23',
|
||||
'1.1754944e-38', // aprox from 1.1754943508 × 10−38,
|
||||
'3.4028235e+38',
|
||||
'3.8326058e+17',
|
||||
]
|
||||
|
||||
test_cases_f64 := [
|
||||
|
@ -109,32 +109,31 @@ fn test_float_to_str() {
|
|||
]
|
||||
|
||||
exp_result_f64 := [
|
||||
"0e+00",
|
||||
"-0e+00",
|
||||
"nan",
|
||||
"nan",
|
||||
"+inf",
|
||||
"-inf",
|
||||
"1.e+00",
|
||||
"-1.e+00",
|
||||
"1.e+01",
|
||||
"-1.e+01",
|
||||
"3.e-01",
|
||||
"-3.e-01",
|
||||
"1.e+06",
|
||||
"1.234567e+05",
|
||||
"1.23e+47",
|
||||
"-1.2345e+02",
|
||||
"1.e+23",
|
||||
"2.2250738585072014e-308",
|
||||
"3.4028234663852886e+38",
|
||||
"3.8326057576481645e+17",
|
||||
"3.8326057576481645e+17",
|
||||
|
||||
"1.23e+302", // this test is failed from C sprintf!!
|
||||
"1.23e-298",
|
||||
"5.e-324",
|
||||
"-5.e-324",
|
||||
'0e+00',
|
||||
'-0e+00',
|
||||
'nan',
|
||||
'nan',
|
||||
'+inf',
|
||||
'-inf',
|
||||
'1.e+00',
|
||||
'-1.e+00',
|
||||
'1.e+01',
|
||||
'-1.e+01',
|
||||
'3.e-01',
|
||||
'-3.e-01',
|
||||
'1.e+06',
|
||||
'1.234567e+05',
|
||||
'1.23e+47',
|
||||
'-1.2345e+02',
|
||||
'1.e+23',
|
||||
'2.2250738585072014e-308',
|
||||
'3.4028234663852886e+38',
|
||||
'3.8326057576481645e+17',
|
||||
'3.8326057576481645e+17',
|
||||
'1.23e+302', // this test is failed from C sprintf!!
|
||||
'1.23e-298',
|
||||
'5.e-324',
|
||||
'-5.e-324',
|
||||
]
|
||||
|
||||
// test f32
|
||||
|
@ -156,11 +155,11 @@ fn test_float_to_str() {
|
|||
|
||||
// test long format
|
||||
for exp := 1; exp < 120; exp++ {
|
||||
a := strconv.f64_to_str_l(("1e"+exp.str()).f64())
|
||||
a := strconv.f64_to_str_l(('1e' + exp.str()).f64())
|
||||
// println(a)
|
||||
assert a.len == exp + 1
|
||||
|
||||
b := strconv.f64_to_str_l(("1e-"+exp.str()).f64())
|
||||
b := strconv.f64_to_str_l(('1e-' + exp.str()).f64())
|
||||
// println(b)
|
||||
assert b.len == exp + 2
|
||||
}
|
||||
|
|
|
@ -1516,14 +1516,33 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||
set_comma = true
|
||||
}
|
||||
}
|
||||
mut next_pos := expr_pos
|
||||
if i + 1 < node.exprs.len {
|
||||
next_pos = node.exprs[i + 1].position()
|
||||
}
|
||||
if cmt.pos.line_nr > expr_pos.last_line {
|
||||
embed := i + 1 < node.exprs.len
|
||||
&& node.exprs[i + 1].position().line_nr == cmt.pos.last_line
|
||||
embed := i + 1 < node.exprs.len && next_pos.line_nr == cmt.pos.last_line
|
||||
f.writeln('')
|
||||
f.comment(cmt, iembed: embed)
|
||||
} else {
|
||||
if cmt.is_inline {
|
||||
f.write(' ')
|
||||
f.comment(cmt, iembed: true)
|
||||
if cmt.pos.line_nr == expr_pos.last_line && cmt.pos.pos < expr_pos.pos {
|
||||
f.write(',')
|
||||
set_comma = true
|
||||
} else {
|
||||
if !cmt.is_inline {
|
||||
// a // comment, transformed to a /**/ one, needs a comma too
|
||||
f.write(',')
|
||||
set_comma = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
f.write(', ')
|
||||
f.comment(cmt, iembed: false)
|
||||
set_comma = true
|
||||
}
|
||||
}
|
||||
last_comment_was_inline = cmt.is_inline
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
fn abc() {
|
||||
test_cases_f32 := [
|
||||
f32_from_bits1(0x0000_0000), // +0
|
||||
f32_from_bits1(0x8000_0000), // -0
|
||||
f32_from_bits1(0xFFC0_0001), // sNan
|
||||
f32_from_bits1(0xFF80_0001), // qNan
|
||||
f32_from_bits1(0x7F80_0000), // +inf
|
||||
f32_from_bits1(0xFF80_0000), // -inf
|
||||
1,
|
||||
-1,
|
||||
10,
|
||||
-10,
|
||||
0.3,
|
||||
-0.3,
|
||||
1000000,
|
||||
123456.7,
|
||||
123e35,
|
||||
-123.45,
|
||||
1e23,
|
||||
f32_from_bits1(0x0080_0000), // smallest float32
|
||||
math.max_f32,
|
||||
383260575764816448.,
|
||||
]
|
||||
|
||||
exp_result_f32 := [
|
||||
'0e+00',
|
||||
'-0e+00',
|
||||
'nan',
|
||||
'nan',
|
||||
'+inf',
|
||||
'-inf',
|
||||
'1.e+00',
|
||||
'-1.e+00',
|
||||
'1.e+01',
|
||||
'-1.e+01',
|
||||
'3.e-01',
|
||||
'-3.e-01',
|
||||
'1.e+06',
|
||||
'1.234567e+05',
|
||||
'1.23e+37',
|
||||
'-1.2345e+02',
|
||||
'1.e+23',
|
||||
'1.1754944e-38', // aprox from 1.1754943508 × 10−38,
|
||||
'3.4028235e+38',
|
||||
'3.8326058e+17',
|
||||
]
|
||||
|
||||
test_cases_f64 := [
|
||||
f64_from_bits1(0x0000_0000_0000_0000), // +0
|
||||
f64_from_bits1(0x8000_0000_0000_0000), // -0
|
||||
f64_from_bits1(0x7FF0_0000_0000_0001), // sNan
|
||||
f64_from_bits1(0x7FF8_0000_0000_0001), // qNan
|
||||
f64_from_bits1(0x7FF0_0000_0000_0000), // +inf
|
||||
f64_from_bits1(0xFFF0_0000_0000_0000), // -inf
|
||||
1,
|
||||
-1,
|
||||
10,
|
||||
-10,
|
||||
0.3,
|
||||
-0.3,
|
||||
1000000,
|
||||
123456.7,
|
||||
123e45,
|
||||
-123.45,
|
||||
1e23,
|
||||
f64_from_bits1(0x0010_0000_0000_0000), // smallest float64
|
||||
math.max_f32,
|
||||
383260575764816448,
|
||||
383260575764816448,
|
||||
// C failing cases
|
||||
123e300,
|
||||
123e-300,
|
||||
5.e-324,
|
||||
-5.e-324,
|
||||
]
|
||||
|
||||
exp_result_f64 := [
|
||||
'0e+00',
|
||||
'-0e+00',
|
||||
'nan',
|
||||
'nan',
|
||||
'+inf',
|
||||
'-inf',
|
||||
'1.e+00',
|
||||
'-1.e+00',
|
||||
'1.e+01',
|
||||
'-1.e+01',
|
||||
'3.e-01',
|
||||
'-3.e-01',
|
||||
'1.e+06',
|
||||
'1.234567e+05',
|
||||
'1.23e+47',
|
||||
'-1.2345e+02',
|
||||
'1.e+23',
|
||||
'2.2250738585072014e-308',
|
||||
'3.4028234663852886e+38',
|
||||
'3.8326057576481645e+17',
|
||||
'3.8326057576481645e+17',
|
||||
'1.23e+302', // this test is failed from C sprintf!!
|
||||
'1.23e-298',
|
||||
'5.e-324',
|
||||
'-5.e-324',
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue