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