v2 / vlib / v / fmt / tests / infix_expr_input.vv
32 lines · 29 sloc · 1.41 KB · 9051ac8921da3e2dcbf1785ceffa7f11fea36f5c
Raw
1fn grouped_cond_single_line() {
2 // fmt tries to keep grouped conditions together...
3 _ := one_condition_before && another_condition && (inside_paren || is_kept_together || if_possible) && end_cond
4}
5
6fn unwrap_grouped_conds() {
7 // ...but sometimes they have to be split
8 _ := one_condition && before_condition && (conds_inside_paren || are_kept_together || if_possible || but_this_is_really_too_much || for_one_line)
9 _ := (also_inside_parens || just_as_above || but_this_is_also_more || than_a_single_line_could_fit) && end_cond
10 fields = fields.filter((it.typ in [string_type, int_type, bool_type] || c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
11}
12
13fn main() {
14 clean_struct_v_type_name = clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') + '>'
15 {
16 {
17 {
18 {
19 // Indent this much to force a break after the assign (`:=`).
20 // Check that the trailing space is removed
21 should_cast := (g.table.type_kind(stmt.left_types.first()) in js.shallow_equatables) && (g.cast_stack.len <= 0 || stmt.left_types.first() != g.cast_stack.last())
22 }
23 }
24 }
25 }
26}
27
28if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
29 && fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`] {
30 c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`',
31 node.fmt_poss[i])
32}
33