vfmt: fix array_init line wrapping (#14154)
parent
6690dfa208
commit
745e75ab25
|
@ -32,8 +32,7 @@ const (
|
|||
|
||||
struct App {
|
||||
minutes_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
|
||||
tp +
|
||||
1 * th, center - tw, tp + 1 * th]
|
||||
tp + 1 * th, center - tw, tp + 1 * th]
|
||||
hours_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 2 * th,
|
||||
center - tw, tp + 2 * th]
|
||||
hours3_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 3 * th,
|
||||
|
|
|
@ -51,8 +51,7 @@ const (
|
|||
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
|
||||
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
|
||||
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd],
|
||||
'Test With Truncation'.bytes(),
|
||||
'Test Using Larger Than Block-Size Key - Hash Key First'.bytes(),
|
||||
'Test With Truncation'.bytes(), 'Test Using Larger Than Block-Size Key - Hash Key First'.bytes(),
|
||||
'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data'.bytes()]
|
||||
)
|
||||
|
||||
|
|
|
@ -242,8 +242,7 @@ const (
|
|||
cookie: [&http.Cookie{
|
||||
name: 'cookie-1'
|
||||
value: 'v1'
|
||||
},
|
||||
&http.Cookie{
|
||||
}, &http.Cookie{
|
||||
name: 'cookie-2'
|
||||
value: 'v2'
|
||||
},
|
||||
|
@ -294,8 +293,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['ASP.NET_SessionId=foo; path=/; HttpOnly']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'ASP.NET_SessionId'
|
||||
value: 'foo'
|
||||
path: '/'
|
||||
|
@ -307,8 +305,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['samesitedefault=foo; SameSite']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'samesitedefault'
|
||||
value: 'foo'
|
||||
same_site: .same_site_default_mode
|
||||
|
@ -319,8 +316,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['samesitelax=foo; SameSite=Lax']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'samesitelax'
|
||||
value: 'foo'
|
||||
same_site: .same_site_lax_mode
|
||||
|
@ -331,8 +327,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['samesitestrict=foo; SameSite=Strict']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'samesitestrict'
|
||||
value: 'foo'
|
||||
same_site: .same_site_strict_mode
|
||||
|
@ -343,8 +338,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['samesitenone=foo; SameSite=None']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'samesitenone'
|
||||
value: 'foo'
|
||||
same_site: .same_site_none_mode
|
||||
|
@ -357,8 +351,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-1=a z']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-1'
|
||||
value: 'a z'
|
||||
raw: 'special-1=a z'
|
||||
|
@ -368,8 +361,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-2=" z"']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-2'
|
||||
value: ' z'
|
||||
raw: 'special-2=" z"'
|
||||
|
@ -379,8 +371,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-3="a "']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-3'
|
||||
value: 'a '
|
||||
raw: 'special-3="a "'
|
||||
|
@ -390,8 +381,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-4=" "']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-4'
|
||||
value: ' '
|
||||
raw: 'special-4=" "'
|
||||
|
@ -401,8 +391,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-5=a,z']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-5'
|
||||
value: 'a,z'
|
||||
raw: 'special-5=a,z'
|
||||
|
@ -412,8 +401,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-6=",z"']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-6'
|
||||
value: ',z'
|
||||
raw: 'special-6=",z"'
|
||||
|
@ -423,8 +411,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-7=","']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-7'
|
||||
value: ','
|
||||
raw: 'special-8=","'
|
||||
|
|
|
@ -3683,8 +3683,8 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
|
|||
for mut expr is ast.ParExpr {
|
||||
expr = expr.expr
|
||||
}
|
||||
if expr in [ast.BoolLiteral, ast.CallExpr, ast.CharLiteral, ast.FloatLiteral,
|
||||
ast.IntegerLiteral, ast.InfixExpr, ast.StringLiteral, ast.StringInterLiteral] {
|
||||
if expr in [ast.BoolLiteral, ast.CallExpr, ast.CharLiteral, ast.FloatLiteral, ast.IntegerLiteral,
|
||||
ast.InfixExpr, ast.StringLiteral, ast.StringInterLiteral] {
|
||||
c.error('cannot take the address of $expr', node.pos)
|
||||
}
|
||||
if mut node.right is ast.IndexExpr {
|
||||
|
|
|
@ -1462,7 +1462,7 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||
|| f.line_len + expr.pos().len > fmt.max_len[3]
|
||||
}
|
||||
}
|
||||
line_break := f.array_init_break[f.array_init_depth - 1]
|
||||
mut line_break := f.array_init_break[f.array_init_depth - 1]
|
||||
mut penalty := if line_break { 0 } else { 4 }
|
||||
if penalty > 0 {
|
||||
if i == 0
|
||||
|
@ -1480,14 +1480,26 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||
}
|
||||
single_line_expr := expr_is_single_line(expr)
|
||||
if single_line_expr {
|
||||
estr := f.node_str(expr)
|
||||
if !is_new_line && !f.buffering && f.line_len + estr.len > fmt.max_len.last() {
|
||||
mut estr := ''
|
||||
if !is_new_line && !f.buffering && f.line_len + expr.pos().len > fmt.max_len.last() {
|
||||
if inc_indent {
|
||||
estr = f.node_str(expr)
|
||||
}
|
||||
f.writeln('')
|
||||
is_new_line = true
|
||||
if !inc_indent {
|
||||
f.indent++
|
||||
inc_indent = true
|
||||
f.write_indent()
|
||||
f.empty_line = false
|
||||
estr = f.node_str(expr)
|
||||
}
|
||||
if i == 0 {
|
||||
f.array_init_break[f.array_init_depth - 1] = true
|
||||
line_break = true
|
||||
}
|
||||
} else {
|
||||
estr = f.node_str(expr)
|
||||
}
|
||||
if !is_new_line && i > 0 {
|
||||
f.write(' ')
|
||||
|
|
|
@ -6,8 +6,7 @@ const (
|
|||
header: {
|
||||
'Set-Cookie': ['special-7=","']
|
||||
}
|
||||
cookies: [
|
||||
&http.Cookie{
|
||||
cookies: [&http.Cookie{
|
||||
name: 'special-7'
|
||||
value: ','
|
||||
raw: 'special-8=","'
|
||||
|
|
|
@ -12,6 +12,13 @@ fn wrapping_tests() {
|
|||
'elit. Donec varius purus leo, vel maximus diam',
|
||||
'finibus sed. Etiam eu urna ante. Nunc quis vehicula',
|
||||
'velit. Sed at mauris et quam ornare tristique.']
|
||||
multi_level := [
|
||||
[1, 2, 3],
|
||||
[
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius purus leo, vel maximus diam',
|
||||
'finibus sed. Etiam eu urna ante. Nunc quis vehicula velit. Sed at mauris et quam ornare tristique.',
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
fn array_init_without_commas() {
|
||||
|
|
|
@ -9,6 +9,10 @@ fn main() {
|
|||
|
||||
fn wrapping_tests() {
|
||||
my_arr := ['Lorem ipsum dolor sit amet, consectetur adipiscing', 'elit. Donec varius purus leo, vel maximus diam', 'finibus sed. Etiam eu urna ante. Nunc quis vehicula', 'velit. Sed at mauris et quam ornare tristique.']
|
||||
multi_level := [
|
||||
[1, 2, 3],
|
||||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius purus leo, vel maximus diam', 'finibus sed. Etiam eu urna ante. Nunc quis vehicula velit. Sed at mauris et quam ornare tristique.'],
|
||||
]
|
||||
}
|
||||
|
||||
fn array_init_without_commas() {
|
||||
|
|
|
@ -61,8 +61,7 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
|
|||
}
|
||||
g.inside_match_optional = true
|
||||
}
|
||||
if node.cond in [ast.Ident, ast.SelectorExpr, ast.IntegerLiteral, ast.StringLiteral,
|
||||
ast.FloatLiteral] {
|
||||
if node.cond in [ast.Ident, ast.SelectorExpr, ast.IntegerLiteral, ast.StringLiteral, ast.FloatLiteral] {
|
||||
cond_var = g.expr_string(node.cond)
|
||||
} else {
|
||||
line := if is_expr {
|
||||
|
|
|
@ -2426,8 +2426,8 @@ fn (mut g JsGen) match_expr(node ast.MatchExpr) {
|
|||
g.inside_ternary = true
|
||||
}
|
||||
|
||||
if node.cond in [ast.Ident, ast.SelectorExpr, ast.IntegerLiteral, ast.StringLiteral,
|
||||
ast.FloatLiteral, ast.CallExpr, ast.EnumVal] {
|
||||
if node.cond in [ast.Ident, ast.SelectorExpr, ast.IntegerLiteral, ast.StringLiteral, ast.FloatLiteral,
|
||||
ast.CallExpr, ast.EnumVal] {
|
||||
cond_var = CondExpr{node.cond}
|
||||
} else {
|
||||
s := g.new_tmp_var()
|
||||
|
|
Loading…
Reference in New Issue