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