diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-07-29 19:47:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-29 19:47:30 +0200 |
| commit | a010fd2c8f9c3b3bd4cec75022c50aac94c0cb02 (patch) | |
| tree | 9a297e0dffcafdac93f2f4a27b0bd34b5f529699 /tools | |
| parent | b994162b8a04175f5aae94fd59ce46f388c1f179 (diff) | |
| parent | 75a14dcc796c1f97a98660381b77828183c345e6 (diff) | |
Merge pull request #223 from flga/linebreak_control
Allow a little more line break control in composite literals
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/odinfmt/snapshot/snapshot.odin | 7 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/calls.odin | 111 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/comp_lit.odin | 49 | ||||
| -rw-r--r-- | tools/odinfmt/tests/calls.odin | 61 | ||||
| -rw-r--r-- | tools/odinfmt/tests/comp_lit.odin | 32 | ||||
| -rw-r--r-- | tools/odinfmt/tests/random/.snapshots/demo.odin | 93 | ||||
| -rw-r--r-- | tools/odinfmt/tests/random/.snapshots/document.odin | 24 |
7 files changed, 333 insertions, 44 deletions
diff --git a/tools/odinfmt/snapshot/snapshot.odin b/tools/odinfmt/snapshot/snapshot.odin index d5bdbd2..ef6239d 100644 --- a/tools/odinfmt/snapshot/snapshot.odin +++ b/tools/odinfmt/snapshot/snapshot.odin @@ -19,6 +19,7 @@ format_file :: proc( style := format.default_style style.character_width = 80 style.newline_style = .LF //We want to make sure it works on linux and windows. + style.multiline_composite_literals = true if data, ok := os.read_entire_file(filepath, allocator); ok { return format.format( @@ -79,9 +80,9 @@ snapshot_file :: proc(path: string) -> bool { if os.exists(snapshot_path) { if snapshot_data, ok := os.read_entire_file( - snapshot_path, - context.temp_allocator, - ); ok { + snapshot_path, + context.temp_allocator, + ); ok { snapshot_scanner := scanner.Scanner{} scanner.init(&snapshot_scanner, string(snapshot_data)) formatted_scanner := scanner.Scanner{} diff --git a/tools/odinfmt/tests/.snapshots/calls.odin b/tools/odinfmt/tests/.snapshots/calls.odin index 3e38331..919a5a0 100644 --- a/tools/odinfmt/tests/.snapshots/calls.odin +++ b/tools/odinfmt/tests/.snapshots/calls.odin @@ -39,6 +39,117 @@ calls :: proc() { ddddddddddddddddddddddddddddddddddddd, ), ) + result = vk.CreateInsance( + my_really_cool_call( + T{1, 2, 3}, + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{a = 1, b = 2, c = 3}, + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{1, 2, 3}, + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{a = 1, b = 2, c = 3}, + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + ), + ) + + + result = vk.CreateInsance( + my_really_cool_call( + T{ + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + }, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{ + a = aaaaaaaaaaaaaaaaaaaaa, + b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + c = cccccccccccccccccccccccccccccccc, + d = ddddddddddddddddddddddddddddddddddddd, + }, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{ + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + cccccccccccccccccccccccccccccccc, + ddddddddddddddddddddddddddddddddddddd, + }, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{ + a = aaaaaaaaaaaaaaaaaaaaa, + b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + c = cccccccccccccccccccccccccccccccc, + d = ddddddddddddddddddddddddddddddddddddd + + ddddddddddddddddddddddddddddddddddddd, + }, + ), + ) + result = vk.CreateInsance( + my_really_cool_call( + T{ + a = aaaaaaaaaaaaaaaaaaaaa, + b = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + c = cccccccccccccccccccccccccccccccc, + d = ddddddddddddddddddddddddddddddddddddd + 1, + }, + ), + ) + + _ = vk.CreateInsance(my_really_cool_call(1, 2, 3)) + _ = vk.CreateInsance(my_really_cool_call(1, 2, 3)) + _ = vk.CreateInsance(my_really_cool_call(1, 2, 3)) + _ = vk.CreateInsance(1, 2, 3) + _ = vk.CreateInsance(1, 2, 3) + _ = vk.CreateInsance(1) + _ = vk.CreateInsance(Composite{a = 1, b = 2}) + _ = vk.CreateInsance(Composite{a = 1, b = 2}) + _ = vk.CreateInsance(Composite{a = 1, b = 2}) + _ = vk.CreateInsance(Composite{1, 2, 3, 4}) + _ = vk.CreateInsance(Composite{1, 2, 3, 4}) + _ = vk.CreateInsance(matrix[2, 2]i32{ + 1, 2, + 3, 4, + }) + _ = vk.CreateInsance(matrix[2, 2]i32{ + 1, 2, + 3, 4, + }) test_2( Foo{ diff --git a/tools/odinfmt/tests/.snapshots/comp_lit.odin b/tools/odinfmt/tests/.snapshots/comp_lit.odin index 757b211..a2b8a29 100644 --- a/tools/odinfmt/tests/.snapshots/comp_lit.odin +++ b/tools/odinfmt/tests/.snapshots/comp_lit.odin @@ -2,7 +2,54 @@ package odinfmt_test main :: proc() { - sort.sort(sort.Interface { + T :: struct { + a, b, c, d: int, + } + _ = T{0, 0, 0, 0} + _ = T{ + 0, + 0, + 0, + 0, + } + _ = T{ + 0, + 0, + 0, + 0, + } + _ = T{ + 0, + 0, + 0, + 0, + } + _ = T{ + a = 0, + b = 0, + c = 0, + d = 0, + } + _ = T{ + a = 0, + b = 0, + c = 0, + d = 0, + } + _ = T{ + a = 0, + b = 0, + c = 0, + d = 0, + } + _ = T{ + a = 0, + b = 0, + c = 0, + d = 0, + } + + sort.sort(sort.Interface{ len = proc(it: sort.Interface) -> int { c := 2 }, diff --git a/tools/odinfmt/tests/calls.odin b/tools/odinfmt/tests/calls.odin index c9eb890..47295bd 100644 --- a/tools/odinfmt/tests/calls.odin +++ b/tools/odinfmt/tests/calls.odin @@ -9,6 +9,59 @@ calls :: proc() { result := vk.CreateInsance(my_really_cool_call(aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) result = vk.CreateInsance(my_really_cool_call(aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) + result = vk.CreateInsance(my_really_cool_call(T{1,2,3},aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) + result = vk.CreateInsance(my_really_cool_call(T{a=1,b=2,c=3},aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) + result = vk.CreateInsance(my_really_cool_call(T{ + 1,2,3},aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) + result = vk.CreateInsance(my_really_cool_call(T{ + a=1,b=2,c=3},aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd)) + + + result = vk.CreateInsance(my_really_cool_call(T{aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd})) + result = vk.CreateInsance(my_really_cool_call(T{a=aaaaaaaaaaaaaaaaaaaaa,b=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,c=cccccccccccccccccccccccccccccccc,d=ddddddddddddddddddddddddddddddddddddd})) + result = vk.CreateInsance(my_really_cool_call(T{ + aaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd, cccccccccccccccccccccccccccccccc, ddddddddddddddddddddddddddddddddddddd,})) + result = vk.CreateInsance(my_really_cool_call(T{ + a=aaaaaaaaaaaaaaaaaaaaa, + b=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,c=cccccccccccccccccccccccccccccccc,d=ddddddddddddddddddddddddddddddddddddd+ddddddddddddddddddddddddddddddddddddd})) + result = vk.CreateInsance(my_really_cool_call(T{ + a=aaaaaaaaaaaaaaaaaaaaa, + b=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,c=cccccccccccccccccccccccccccccccc,d=ddddddddddddddddddddddddddddddddddddd+1})) + + _ = vk.CreateInsance(my_really_cool_call(1,2,3)) + _ = vk.CreateInsance(my_really_cool_call(1, + 2,3)) + _ = vk.CreateInsance(my_really_cool_call(1, + 2,3,), +) + _ = vk.CreateInsance(1,2,3) + _ = vk.CreateInsance(1, + 2,3) + _ = vk.CreateInsance( + 1, + ) + _ = vk.CreateInsance( + Composite{a=1,b=2}, + ) + _ = vk.CreateInsance( Composite{a=1,b=2},) + _ = vk.CreateInsance( + Composite{ + a=1,b=2}, + ) + _ = vk.CreateInsance( + Composite{1,2,3,4}, + ) + _ = vk.CreateInsance( + Composite{ + 1,2, + 3,4}, + ) + _ = vk.CreateInsance(matrix[2, 2]i32 { + 1, 2, + 3, 4, + }) + _ = vk.CreateInsance(matrix[2, 2]i32 {1, 2, 3, 4}) test_2( Foo{field1 = 1, @@ -25,7 +78,7 @@ calls :: proc() { slice.sort_by(fis, proc(a, b: os.File_Info) -> bool { return a.name < b.name }) - + test3( Foo{field1 = 1, field2 = "hello", @@ -40,9 +93,9 @@ calls :: proc() { ab := short_call(10, false) or_return - resuuuuuuuuult := + resuuuuuuuuult := add_to_long_list_of_values( - fooooooooooooo, + fooooooooooooo, Foo{ field1 = 1, field2 = "hello", @@ -55,4 +108,4 @@ calls :: proc() { }, true, ) or_return -}
\ No newline at end of file +} diff --git a/tools/odinfmt/tests/comp_lit.odin b/tools/odinfmt/tests/comp_lit.odin index c8a4aff..8859cb0 100644 --- a/tools/odinfmt/tests/comp_lit.odin +++ b/tools/odinfmt/tests/comp_lit.odin @@ -2,6 +2,38 @@ package odinfmt_test main :: proc() { + T :: struct { + a, b, c, d: int, + } + _ = T{0,0,0,0} + _ = T{ + 0,0,0,0, + } + _ = T{ + 0, + 0, + 0, + 0, + } + _ = T{ + 0,0, + 0,0, + } + _ = T{a=0,b=0,c=0,d=0} + _ = T{ + a=0,b=0,c=0,d=0, + } + _ = T{ + a=0, + b=0, + c=0, + d=0, + } + _ = T{ + a=0,b=0, + c=0,d=0, + } + sort.sort(sort.Interface{len = proc(it: sort.Interface) -> int { c := 2 }, diff --git a/tools/odinfmt/tests/random/.snapshots/demo.odin b/tools/odinfmt/tests/random/.snapshots/demo.odin index 52f5b37..a55af51 100644 --- a/tools/odinfmt/tests/random/.snapshots/demo.odin +++ b/tools/odinfmt/tests/random/.snapshots/demo.odin @@ -203,7 +203,7 @@ control_flow :: proc() { } - some_map := map[string]int { + some_map := map[string]int{ "A" = 1, "C" = 9, "B" = 4, @@ -539,7 +539,7 @@ struct_type :: proc() { // You can list just a subset of the fields if you specify the // field by name (the order of the named fields does not matter): - v = Vector3 { + v = Vector3{ z = 1, y = 2, } @@ -688,7 +688,7 @@ union_type :: proc() { // See `parametric_polymorphism` procedure for details new_entity :: proc($T: typeid) -> ^Entity { t := new(Entity) - t.derived = T { + t.derived = T{ entity = t, } return t @@ -1131,15 +1131,29 @@ parametric_polymorphism :: proc() { return } - x := [2][3]f32{{1, 2, 3}, {3, 2, 1}} - y := [3][2]f32{{0, 8}, {6, 2}, {8, 4}} + x := [2][3]f32{ + {1, 2, 3}, + {3, 2, 1}, + } + y := [3][2]f32{ + {0, 8}, + {6, 2}, + {8, 4}, + } z := mul(x, y) assert(z == {{36, 24}, {20, 32}}) } } -prefix_table := [?]string{"White", "Red", "Green", "Blue", "Octarine", "Black"} +prefix_table := [?]string{ + "White", + "Red", + "Green", + "Blue", + "Octarine", + "Black", +} print_mutex := b64(false) @@ -1766,7 +1780,7 @@ ranged_fields_for_array_compound_literals :: proc() { fmt.println(foo) } { // Indexed - foo := [?]int { + foo := [?]int{ 3 = 16, 1 = 4, 2 = 9, @@ -1776,7 +1790,7 @@ ranged_fields_for_array_compound_literals :: proc() { } { // Ranges i := 2 - foo := [?]int { + foo := [?]int{ 0 = 123, 5 ..= 9 = 54, 10 ..< 16 = i * 3 + (i - 1) * 2, @@ -1786,7 +1800,7 @@ ranged_fields_for_array_compound_literals :: proc() { } { // Slice and Dynamic Array support i := 2 - foo_slice := []int { + foo_slice := []int{ 0 = 123, 5 ..= 9 = 54, 10 ..< 16 = i * 3 + (i - 1) * 2, @@ -1794,7 +1808,7 @@ ranged_fields_for_array_compound_literals :: proc() { assert(len(foo_slice) == 16) fmt.println(foo_slice) // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8] - foo_dynamic_array := [dynamic]int { + foo_dynamic_array := [dynamic]int{ 0 = 123, 5 ..= 9 = 54, 10 ..< 16 = i * 3 + (i - 1) * 2, @@ -2005,7 +2019,7 @@ constant_literal_expressions :: proc() { using c: Bar, } - FOO_CONST :: Foo { + FOO_CONST :: Foo{ b = 2, a = 1, c = {3, 4}, @@ -2022,7 +2036,7 @@ constant_literal_expressions :: proc() { fmt.println("-------") - ARRAY_CONST :: [3]int { + ARRAY_CONST :: [3]int{ 1 = 4, 2 = 9, 0 = 1, @@ -2045,7 +2059,7 @@ constant_literal_expressions :: proc() { C, D, } - ENUM_ARRAY_CONST :: [Baz]int { + ENUM_ARRAY_CONST :: [Baz]int{ .A ..= .C = 1, .D = 16, } @@ -2064,7 +2078,7 @@ constant_literal_expressions :: proc() { D = 16, } #assert(len(Sparse_Baz) < len(#sparse[Sparse_Baz]int)) - SPARSE_ENUM_ARRAY_CONST :: #sparse[Sparse_Baz]int { + SPARSE_ENUM_ARRAY_CONST :: #sparse[Sparse_Baz]int{ .A ..= .C = 1, .D = 16, } @@ -2390,7 +2404,7 @@ matrix_type :: proc() { // The following represents a matrix that has 2 rows and 3 columns m: matrix[2, 3]f32 - m = matrix[2, 3]f32 { + m = matrix[2, 3]f32{ 1, 9, -13, 20, 5, -6, } @@ -2417,12 +2431,12 @@ matrix_type :: proc() { } { // Matrices support multiplication between matrices - a := matrix[2, 3]f32 { + a := matrix[2, 3]f32{ 2, 3, 1, 4, 5, 0, } - b := matrix[3, 2]f32 { + b := matrix[3, 2]f32{ 1, 2, 3, 4, 5, 6, @@ -2437,7 +2451,7 @@ matrix_type :: proc() { } { // Matrices support multiplication between matrices and arrays - m := matrix[4, 4]f32 { + m := matrix[4, 4]f32{ 1, 2, 3, 4, 5, 5, 4, 2, 0, 1, 3, 0, @@ -2453,7 +2467,7 @@ matrix_type :: proc() { fmt.println("v * m", v * m) // Support with non-square matrices - s := matrix[2, 4]f32 { // [4][2]f32 + s := matrix[2, 4]f32{ // [4][2]f32 2, 4, 3, 1, 7, 8, 6, 5, } @@ -2467,12 +2481,12 @@ matrix_type :: proc() { // if the element type supports it // Not support for '/', '%', or '%%' operations - a := matrix[2, 2]i32 { + a := matrix[2, 2]i32{ 1, 2, 3, 4, } - b := matrix[2, 2]i32 { + b := matrix[2, 2]i32{ -5, 1, 9, -7, } @@ -2509,7 +2523,12 @@ matrix_type :: proc() { mat2 :: distinct matrix[2, 2]f32 mat4 :: distinct matrix[4, 4]f32 - m2 := mat2{1, 3, 2, 4} + m2 := mat2{ + 1, + 3, + 2, + 4, + } m4 := mat4(m2) assert(m4[2, 2] == 1) @@ -2519,7 +2538,24 @@ matrix_type :: proc() { fmt.println("mat2(m4)", mat2(m4)) assert(mat2(m4) == m2) - b4 := mat4{1, 2, 0, 0, 3, 4, 0, 0, 5, 0, 6, 0, 0, 7, 0, 8} + b4 := mat4{ + 1, + 2, + 0, + 0, + 3, + 4, + 0, + 0, + 5, + 0, + 6, + 0, + 0, + 7, + 0, + 8, + } fmt.println("b4", matrix_flatten(b4)) } @@ -2532,7 +2568,16 @@ matrix_type :: proc() { mat2x4 :: distinct matrix[2, 4]f32 mat4x2 :: distinct matrix[4, 2]f32 - x := mat2x4{1, 3, 5, 7, 2, 4, 6, 8} + x := mat2x4{ + 1, + 3, + 5, + 7, + 2, + 4, + 6, + 8, + } y := mat4x2(x) fmt.println("x", x) diff --git a/tools/odinfmt/tests/random/.snapshots/document.odin b/tools/odinfmt/tests/random/.snapshots/document.odin index e309517..10e13b0 100644 --- a/tools/odinfmt/tests/random/.snapshots/document.odin +++ b/tools/odinfmt/tests/random/.snapshots/document.odin @@ -81,7 +81,7 @@ empty :: proc(allocator := context.allocator) -> ^Document { text :: proc(value: string, allocator := context.allocator) -> ^Document { document := new(Document, allocator) - document^ = Document_Text { + document^ = Document_Text{ value = value, } return document @@ -89,7 +89,7 @@ text :: proc(value: string, allocator := context.allocator) -> ^Document { newline :: proc(amount: int, allocator := context.allocator) -> ^Document { document := new(Document, allocator) - document^ = Document_Newline { + document^ = Document_Newline{ amount = amount, } return document @@ -101,7 +101,7 @@ nest :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Nest { + document^ = Document_Nest{ indentation = level, document = nested_document, } @@ -115,7 +115,7 @@ nest_if_break :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Nest_If_Break { + document^ = Document_Nest_If_Break{ indentation = level, document = nested_document, group_id = group_id, @@ -129,7 +129,7 @@ hang :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Nest { + document^ = Document_Nest{ alignment = align, document = hanged_document, } @@ -141,7 +141,7 @@ enforce_fit :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Group { + document^ = Document_Group{ document = fitted_document, mode = .Fit, } @@ -153,7 +153,7 @@ enforce_break :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Group { + document^ = Document_Group{ document = fitted_document, mode = .Break, } @@ -165,7 +165,7 @@ align :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Align { + document^ = Document_Align{ document = aligned_document, } return document @@ -173,7 +173,7 @@ align :: proc( if_break :: proc(value: string, allocator := context.allocator) -> ^Document { document := new(Document, allocator) - document^ = Document_If_Break { + document^ = Document_If_Break{ value = value, } return document @@ -185,7 +185,7 @@ break_with :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Break { + document^ = Document_Break{ value = value, newline = newline, } @@ -206,7 +206,7 @@ group :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Group { + document^ = Document_Group{ document = grouped_document, options = options, } @@ -219,7 +219,7 @@ cons :: proc( allocator := context.allocator, ) -> ^Document { document := new(Document, allocator) - document^ = Document_Cons { + document^ = Document_Cons{ lhs = lhs, rhs = rhs, } |