# Changeset View

Changeset View

# Standalone View

Standalone View

# cfe/trunk/unittests/Format/FormatTestComments.cpp

Show First 20 Lines • Show All 830 Lines • ▼ Show 20 Line(s) | 824 | EXPECT_EQ("void f() {\n" | |||
---|---|---|---|---|---|

831 | format("void f() {\n" | 831 | format("void f() {\n" | ||

832 | " int i;\n" | 832 | " int i;\n" | ||

833 | " /* comment */\n" | 833 | " /* comment */\n" | ||

834 | "\n" | 834 | "\n" | ||

835 | "#ifdef A\n" | 835 | "#ifdef A\n" | ||

836 | " int j;\n" | 836 | " int j;\n" | ||

837 | "}")); | 837 | "}")); | ||

838 | 838 | | |||

839 | EXPECT_EQ("int f(int i) {\n" | ||||

840 | " if (true) {\n" | ||||

841 | " ++i;\n" | ||||

842 | " }\n" | ||||

843 | " // comment\n" | ||||

844 | "#ifdef A\n" | ||||

845 | " int j;\n" | ||||

846 | "#endif\n" | ||||

847 | "}", | ||||

848 | format("int f(int i) {\n" | ||||

849 | " if (true) {\n" | ||||

850 | " ++i;\n" | ||||

851 | " }\n" | ||||

852 | " // comment\n" | ||||

853 | "#ifdef A\n" | ||||

854 | "int j;\n" | ||||

855 | "#endif\n" | ||||

856 | "}")); | ||||

857 | | ||||

839 | // Keep the current level if there is an empty line between the comment and | 858 | // Keep the current level if there is an empty line between the comment and | ||

840 | // the preprocessor directive. | 859 | // the preprocessor directive. | ||

841 | EXPECT_EQ("void f() {\n" | 860 | EXPECT_EQ("void f() {\n" | ||

842 | " int i;\n" | 861 | " int i;\n" | ||

843 | " /* comment */\n" | 862 | " /* comment */\n" | ||

844 | "\n" | 863 | "\n" | ||

845 | "#ifdef A\n" | 864 | "#ifdef A\n" | ||

846 | " int j;\n" | 865 | " int j;\n" | ||

847 | "}", | 866 | "}", | ||

848 | format("void f() {\n" | 867 | format("void f() {\n" | ||

849 | " int i;\n" | 868 | " int i;\n" | ||

850 | "/* comment */\n" | 869 | "/* comment */\n" | ||

851 | "\n" | 870 | "\n" | ||

852 | "#ifdef A\n" | 871 | "#ifdef A\n" | ||

853 | " int j;\n" | 872 | " int j;\n" | ||

854 | "}")); | 873 | "}")); | ||

855 | 874 | | |||

875 | EXPECT_EQ("void f() {\n" | ||||

876 | " int i;\n" | ||||

877 | " return i;\n" | ||||

878 | "}\n" | ||||

879 | "// comment\n" | ||||

880 | "\n" | ||||

881 | "#ifdef A\n" | ||||

882 | "int i;\n" | ||||

883 | "#endif // A", | ||||

884 | format("void f() {\n" | ||||

885 | " int i;\n" | ||||

886 | " return i;\n" | ||||

887 | "}\n" | ||||

888 | "// comment\n" | ||||

889 | "\n" | ||||

890 | "#ifdef A\n" | ||||

891 | "int i;\n" | ||||

892 | "#endif // A")); | ||||

893 | | ||||

894 | EXPECT_EQ("int f(int i) {\n" | ||||

895 | " if (true) {\n" | ||||

896 | " ++i;\n" | ||||

897 | " }\n" | ||||

898 | " // comment\n" | ||||

899 | "\n" | ||||

900 | "#ifdef A\n" | ||||

901 | " int j;\n" | ||||

902 | "#endif\n" | ||||

903 | "}", | ||||

904 | format("int f(int i) {\n" | ||||

905 | " if (true) {\n" | ||||

906 | " ++i;\n" | ||||

907 | " }\n" | ||||

908 | " // comment\n" | ||||

909 | "\n" | ||||

910 | "#ifdef A\n" | ||||

911 | " int j;\n" | ||||

912 | "#endif\n" | ||||

913 | "}")); | ||||

914 | | ||||

856 | // Align with the preprocessor directive if the comment was originally aligned | 915 | // Align with the preprocessor directive if the comment was originally aligned | ||

857 | // with the preprocessor directive. | 916 | // with the preprocessor directive. | ||

858 | EXPECT_EQ("void f() {\n" | 917 | EXPECT_EQ("void f() {\n" | ||

859 | " int i;\n" | 918 | " int i;\n" | ||

860 | "/* comment */\n" | 919 | "/* comment */\n" | ||

861 | "#ifdef A\n" | 920 | "#ifdef A\n" | ||

862 | " int j;\n" | 921 | " int j;\n" | ||

863 | "}", | 922 | "}", | ||

864 | format("void f() {\n" | 923 | format("void f() {\n" | ||

865 | " int i;\n" | 924 | " int i;\n" | ||

866 | "/* comment */\n" | 925 | "/* comment */\n" | ||

867 | "#ifdef A\n" | 926 | "#ifdef A\n" | ||

868 | " int j;\n" | 927 | " int j;\n" | ||

869 | "}")); | 928 | "}")); | ||

929 | | ||||

930 | EXPECT_EQ("int f(int i) {\n" | ||||

931 | " if (true) {\n" | ||||

932 | " ++i;\n" | ||||

933 | " }\n" | ||||

934 | "// comment\n" | ||||

935 | "#ifdef A\n" | ||||

936 | " int j;\n" | ||||

937 | "#endif\n" | ||||

938 | "}", | ||||

939 | format("int f(int i) {\n" | ||||

940 | " if (true) {\n" | ||||

941 | " ++i;\n" | ||||

942 | " }\n" | ||||

943 | "// comment\n" | ||||

944 | "#ifdef A\n" | ||||

945 | " int j;\n" | ||||

946 | "#endif\n" | ||||

947 | "}")); | ||||

870 | } | 948 | } | ||

871 | 949 | | |||

872 | TEST_F(FormatTestComments, SplitsLongLinesInComments) { | 950 | TEST_F(FormatTestComments, SplitsLongLinesInComments) { | ||

873 | EXPECT_EQ("/* This is a long\n" | 951 | EXPECT_EQ("/* This is a long\n" | ||

874 | " * comment that\n" | 952 | " * comment that\n" | ||

875 | " * doesn't\n" | 953 | " * doesn't\n" | ||

876 | " * fit on one line.\n" | 954 | " * fit on one line.\n" | ||

877 | " */", | 955 | " */", | ||

▲ Show 20 Lines • Show All 1699 Lines • Show Last 20 Lines |