-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsample.py
executable file
·52 lines (42 loc) · 1.12 KB
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 Ivan Grokhotkov <[email protected]>
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import textwrap
from astyle_py import Astyle
def main():
# Create the formatter, optionally specifying the version of Astyle
formatter = Astyle(version='3.4.7')
# Get the version of Astyle
version: str = formatter.version()
print(f'Formatted with Astyle v{version}:')
# Set formatting options
formatter.set_options('--style=mozilla --mode=c')
# Original source to format
source = textwrap.dedent(
'''
int main(int argc, char** argv) {
if (argc == 0) {
return 1;
}
return 0;
}
'''
).strip()
# Format!
result: str = formatter.format(source)
print(result)
# This should be the result
expected = textwrap.dedent(
'''
int main(int argc, char** argv)
{
if (argc == 0) {
return 1;
}
return 0;
}
'''
).strip()
assert result == expected
if __name__ == '__main__':
main()