|
| 1 | +# from c_formatter_42.formatters.line_breaker import line_breaker, indent_level |
| 2 | +from c_formatter_42.formatters.line_breaker import * |
| 3 | + |
| 4 | +def test_line_indent_depth_basic_1(): |
| 5 | + input = """\ |
| 6 | +\t\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 7 | +""" |
| 8 | + assert 3 == indent_level(input) |
| 9 | + |
| 10 | +def test_line_indent_depth_basic_2(): |
| 11 | + input = """\ |
| 12 | +looooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 13 | +""" |
| 14 | + assert 0 == indent_level(input) |
| 15 | + |
| 16 | +def test_line_indent_depth_basic_3(): |
| 17 | + input = """\ |
| 18 | +\t\t\t + 2 + 2 + 2\t |
| 19 | +""" |
| 20 | + assert 7 == indent_level(input) |
| 21 | + |
| 22 | + |
| 23 | +def test_insert_line_break_basic_1(): |
| 24 | + output = """\ |
| 25 | +\t\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 26 | +\t\t\t\t+ 2 + 2 + 2; |
| 27 | +""" |
| 28 | + assert output == line_breaker("""\ |
| 29 | +\t\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 30 | +""") |
| 31 | + |
| 32 | +def test_insert_line_break_basic_2(): |
| 33 | + output = """\ |
| 34 | +looooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 35 | +""" |
| 36 | + assert output == line_breaker("""\ |
| 37 | +looooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 38 | +""") |
| 39 | + |
| 40 | +def test_insert_line_break_basic_3(): |
| 41 | + output = """\ |
| 42 | +\t\t\t\treturn (fooooooooooooooooooooooooo(a, b, cccccccccccc, |
| 43 | +\t\t\t\t\tddddddddddddd, eeeeeeeeeeeeeeee, fffffffffffffff, |
| 44 | +\t\t\t\t\tgggggggggggg, hhhhhhhhhhhhhhhhhh)); |
| 45 | +""" |
| 46 | + assert output == line_breaker("""\ |
| 47 | +\t\t\t\treturn (fooooooooooooooooooooooooo(a, b, cccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, fffffffffffffff, gggggggggggg, hhhhhhhhhhhhhhhhhh)); |
| 48 | +""") |
| 49 | + |
| 50 | +def test_insert_line_break_basic_4(): |
| 51 | + output = """\ |
| 52 | +void\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 53 | +\t\t\t\t+ 2 + 2 + 2; |
| 54 | +""" |
| 55 | + assert output == line_breaker("""\ |
| 56 | +void\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 57 | +""") |
| 58 | + |
| 59 | +def test_insert_line_break_basic_5(): |
| 60 | + output = """\ |
| 61 | +int\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 62 | +\t\t\t+ 2 + 2; |
| 63 | +""" |
| 64 | + assert output == line_breaker("""\ |
| 65 | +int\t\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 66 | +""") |
| 67 | + |
| 68 | +def test_insert_line_break_basic_6(): |
| 69 | + output = """\ |
| 70 | +int\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 |
| 71 | +\t\t+ 2 + 2; |
| 72 | +""" |
| 73 | + assert output == line_breaker("""\ |
| 74 | +int\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; |
| 75 | +""") |
| 76 | + |
| 77 | +def test_insert_line_break_basic_7(): |
| 78 | + output = """\ |
| 79 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhh |
| 80 | +""" |
| 81 | + assert output == line_breaker("""\ |
| 82 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhh |
| 83 | +""") |
| 84 | + |
| 85 | +def test_insert_line_break_basic_8(): |
| 86 | + output = """\ |
| 87 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhh |
| 88 | +""" |
| 89 | + assert output == line_breaker("""\ |
| 90 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhh |
| 91 | +""") |
| 92 | + |
| 93 | +def test_insert_line_break_basic_9(): |
| 94 | + output = """\ |
| 95 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh |
| 96 | +\t+ hhhhhhhhhhhhhh |
| 97 | +""" |
| 98 | + assert output == line_breaker("""\ |
| 99 | +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh + hhhhhhhhhhhhhh |
| 100 | +""") |
| 101 | + |
| 102 | +def test_insert_line_break_basic_10(): |
| 103 | + output = "aaaa\n\t+ b" |
| 104 | + assert output == line_breaker("aaaa + b", 7) |
| 105 | + |
| 106 | +def test_insert_line_break_basic_11(): |
| 107 | + output = "aaaa\n\t- b" |
| 108 | + assert output == line_breaker("aaaa - b", 7) |
| 109 | + |
| 110 | +def test_insert_line_break_basic_12(): |
| 111 | + output = "aaaa\n\t* b" |
| 112 | + assert output == line_breaker("aaaa * b", 7) |
| 113 | + |
| 114 | +def test_insert_line_break_basic_13(): |
| 115 | + output = "aaaa\n\t/ b" |
| 116 | + assert output == line_breaker("aaaa / b", 7) |
| 117 | + |
| 118 | +def test_insert_line_break_basic_14(): |
| 119 | + output = "aaaa\n\t% b" |
| 120 | + assert output == line_breaker("aaaa % b", 7) |
| 121 | + |
| 122 | +def test_insert_line_break_basic_15(): |
| 123 | + output = "aaaa\n\t+ *b" |
| 124 | + assert output == line_breaker("aaaa + *b", 7) |
| 125 | + |
| 126 | +def test_insert_line_break_basic_16(): |
| 127 | + output = "aaaa\n\t+ b*" |
| 128 | + assert output == line_breaker("aaaa + b*", 7) |
| 129 | + |
| 130 | +def test_insert_line_break_basic_17(): |
| 131 | + output = "aaaa\n\t* *b" |
| 132 | + assert output == line_breaker("aaaa * *b", 7) |
| 133 | + |
| 134 | +def test_insert_line_break_basic_18(): |
| 135 | + output = "aaaa\n\t* b*" |
| 136 | + assert output == line_breaker("aaaa * b*", 7) |
| 137 | + |
| 138 | +def test_insert_line_break_basic_19(): |
| 139 | + output = "aaaa*\n\t* b" |
| 140 | + assert output == line_breaker("aaaa* * b", 7) |
| 141 | + |
| 142 | +def test_insert_line_break_basic_20(): |
| 143 | + output = "*aaaa\n\t* b" |
| 144 | + assert output == line_breaker("*aaaa * b", 7) |
| 145 | + |
| 146 | +def test_insert_line_break_basic_21(): |
| 147 | + output = ",\n\taaaa *b" |
| 148 | + assert output == line_breaker(", aaaa *b", 7) |
| 149 | + |
| 150 | +def test_insert_line_break_basic_22(): |
| 151 | + output = ",\n\taaaa* b" |
| 152 | + assert output == line_breaker(", aaaa* b", 7) |
| 153 | + |
0 commit comments