Source Code Cross Referenced for CCNewFormatterUnitTestCase.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » editor » cplusplus » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » cnd » org.netbeans.modules.cnd.editor.cplusplus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * Portions Copyrighted 2007 Sun Microsystems, Inc.
0027:         */
0028:
0029:        package org.netbeans.modules.cnd.editor.cplusplus;
0030:
0031:        import javax.swing.text.BadLocationException;
0032:        import org.netbeans.modules.cnd.editor.api.CodeStyle;
0033:        import org.netbeans.modules.cnd.editor.options.EditorOptions;
0034:        import org.netbeans.modules.cnd.editor.reformat.Reformatter;
0035:
0036:        /**
0037:         * Class was taken from java
0038:         * Links point to java IZ.
0039:         * C/C++ specific tests begin from testReformatSimpleClass
0040:         *
0041:         * @author Alexander Simon
0042:         */
0043:        public class CCNewFormatterUnitTestCase extends
0044:                CCFormatterBaseUnitTestCase {
0045:
0046:            public CCNewFormatterUnitTestCase(String testMethodName) {
0047:                super (testMethodName);
0048:            }
0049:
0050:            /**
0051:             * Perform reformatting of the whole document's text.
0052:             */
0053:            @Override
0054:            protected void reformat() {
0055:                Reformatter f = new Reformatter(getDocument(), CodeStyle
0056:                        .getDefault(getDocument()));
0057:                try {
0058:                    f.reformat();
0059:                } catch (BadLocationException e) {
0060:                    e.printStackTrace(getLog());
0061:                    fail(e.getMessage());
0062:                }
0063:            }
0064:
0065:            private void setDefaultsOptions() {
0066:                EditorOptions.resetToDefault(CodeStyle
0067:                        .getDefault(CodeStyle.Language.CPP));
0068:            }
0069:
0070:            // -------- Reformat tests -----------
0071:
0072:            public void testReformatMultiLineSystemOutPrintln() {
0073:                setDefaultsOptions();
0074:                setLoadDocumentText("void m() {\n" + "    printf(\n"
0075:                        + "    \"haf\");\n" + "}\n");
0076:                reformat();
0077:                assertDocumentText("Incorrect new-line indent", "void m()\n"
0078:                        + "{\n" + "    printf(\n" + "            \"haf\");\n"
0079:                        + "}\n");
0080:            }
0081:
0082:            public void testReformatMultiLineSystemOutPrintln2() {
0083:                setDefaultsOptions();
0084:                EditorOptions.getPreferences(
0085:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0086:                        EditorOptions.newLineBeforeBraceDeclaration,
0087:                        CodeStyle.BracePlacement.SAME_LINE.name());
0088:                setLoadDocumentText("void m() {\n" + "    printf(\n"
0089:                        + "    \"haf\");\n" + "}\n");
0090:                reformat();
0091:                assertDocumentText("Incorrect new-line indent", "void m() {\n"
0092:                        + "    printf(\n" + "            \"haf\");\n" + "}\n");
0093:            }
0094:
0095:            public void testReformatMultiLineSystemOutPrintln3() {
0096:                setDefaultsOptions();
0097:                EditorOptions.getPreferences(
0098:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0099:                        EditorOptions.newLineBeforeBraceDeclaration,
0100:                        CodeStyle.BracePlacement.SAME_LINE.name());
0101:                EditorOptions.getPreferences(
0102:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0103:                        .putBoolean(EditorOptions.alignMultilineCallArgs, true);
0104:                setLoadDocumentText("void m() {\n" + "    printf(\n"
0105:                        + "    \"haf\");\n" + "}\n");
0106:                reformat();
0107:                assertDocumentText("Incorrect new-line indent", "void m() {\n"
0108:                        + "    printf(\n" + "           \"haf\");\n" + "}\n");
0109:            }
0110:
0111:            public void testReformatMultiLineClassDeclaration() {
0112:                setDefaultsOptions();
0113:                setLoadDocumentText("public class C\n"
0114:                        + ": public Runnable {\n" + "int printf(int);\n"
0115:                        + "};\n");
0116:                reformat();
0117:                assertDocumentText("Incorrect new-line indent",
0118:                        "public class C\n" + ": public Runnable\n" + "{\n"
0119:                                + "    int printf(int);\n" + "};\n");
0120:
0121:            }
0122:
0123:            // tests for regressions
0124:
0125:            /**
0126:             * Tests reformatting of new on two lines
0127:             * @see http://www.netbeans.org/issues/show_bug.cgi?id6065
0128:             */
0129:            public void testReformatNewOnTwoLines() {
0130:                setDefaultsOptions();
0131:                setLoadDocumentText("javax::swing::JPanel* panel =\n"
0132:                        + "new java::swing::JPanel();");
0133:                reformat();
0134:                assertDocumentText("Incorrect new on two lines reformating",
0135:                        "javax::swing::JPanel* panel =\n"
0136:                                + "        new java::swing::JPanel();");
0137:            }
0138:
0139:            /**
0140:             * Tests reformatting of ternary conditional operators on multiple lines
0141:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=23508
0142:             */
0143:            public void testReformatTernaryConditionalOperator() {
0144:                setDefaultsOptions();
0145:                setLoadDocumentText("void foo()\n" + "{\n"
0146:                        + "something = (someComplicatedExpression != null) ?\n"
0147:                        + "(aComplexCalculation) :\n"
0148:                        + "(anotherComplexCalculation);\n" + "}\n");
0149:                reformat();
0150:                assertDocumentText(
0151:                        "Incorrect ternary conditional operator reformatting",
0152:                        "void foo()\n"
0153:                                + "{\n"
0154:                                + "    something = (someComplicatedExpression != null) ?\n"
0155:                                + "            (aComplexCalculation) :\n"
0156:                                + "            (anotherComplexCalculation);\n"
0157:                                + "}\n");
0158:            }
0159:
0160:            /**
0161:             * Test reformatting of array initializer with newlines on
0162:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
0163:             */
0164:            public void testReformatArrayInitializerWithNewline() {
0165:                setDefaultsOptions();
0166:                setLoadDocumentText("int[] foo =  {1, 2, 3};\n"
0167:                        + "int[] foo2 =  {1,\n" + "2, 3};\n"
0168:                        + "int[] foo3 = {\n" + "1, 2, 3\n" + "};\n" + "\n");
0169:                reformat();
0170:                assertDocumentText(
0171:                        "Incorrect array initializer with newline reformatting",
0172:                        "int[] foo = {1, 2, 3};\n" + "int[] foo2 = {1,\n"
0173:                                + "    2, 3};\n" + "int[] foo3 = {\n"
0174:                                + "    1, 2, 3\n" + "};\n" + "\n");
0175:            }
0176:
0177:            /**
0178:             * Test reformatting of array initializer with newlines on
0179:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
0180:             */
0181:            public void testReformatArrayInitializerWithNewline2() {
0182:                setDefaultsOptions();
0183:                setLoadDocumentText("int[][] foo4 =  {\n" + "{1, 2, 3},\n"
0184:                        + "{3,4,5},\n" + "{7,8,9}\n" + "};\n" + "\n");
0185:                reformat();
0186:                assertDocumentText(
0187:                        "Incorrect array initializer with newline reformatting",
0188:                        "int[][] foo4 = {\n" + "    {1, 2, 3},\n"
0189:                                + "    {3, 4, 5},\n" + "    {7, 8, 9}\n"
0190:                                + "};\n" + "\n");
0191:            }
0192:
0193:            /**
0194:             * Test reformatting of newline braces to normal ones
0195:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=48926
0196:             */
0197:            public void testReformatNewlineBracesToNormalOnes() {
0198:                setDefaultsOptions();
0199:                EditorOptions.getPreferences(
0200:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0201:                        .putBoolean(EditorOptions.newLineCatch, true);
0202:                setLoadDocumentText("try\n" + "{\n" + "printf(\"test\");\n"
0203:                        + "}\n" + "catch (Exception e)\n" + "{\n"
0204:                        + "printf(\"exception\");\n" + "}");
0205:                reformat();
0206:                assertDocumentText("Incorrect try-catch reformatting",
0207:                        "try {\n" + "    printf(\"test\");\n" + "}\n"
0208:                                + "catch (Exception e) {\n"
0209:                                + "    printf(\"exception\");\n" + "}");
0210:            }
0211:
0212:            public void testReformatNewlineBracesToNormalOnes1() {
0213:                setDefaultsOptions();
0214:                EditorOptions.getPreferences(
0215:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0216:                        .putBoolean(EditorOptions.newLineCatch, true);
0217:                setLoadDocumentText("try\n" + "{\n" + "printf(\"test\");\n"
0218:                        + "}\n" + "catch (Exception e)\n" + "{\n"
0219:                        + "printf(\"exception\");\n" + "}");
0220:                reformat();
0221:                assertDocumentText("Incorrect try-catch reformatting",
0222:                        "try {\n" + "    printf(\"test\");\n" + "}\n"
0223:                                + "catch (Exception e) {\n"
0224:                                + "    printf(\"exception\");\n" + "}");
0225:            }
0226:
0227:            public void testReformatNewlineBracesToNormalOnes2() {
0228:                setDefaultsOptions();
0229:                setLoadDocumentText("	void testError(CuTest *tc){\n"
0230:                        + "		IndexReader* reader = NULL;\n"
0231:                        + "		try{\n"
0232:                        + "			RAMDirectory dir;\n"
0233:                        + "		}catch(CLuceneError& a){\n"
0234:                        + "			_CLDELETE(reader);\n"
0235:                        + "		}catch(...){\n"
0236:                        + "			CuAssert(tc,_T(\"Error did not catch properly\"),false);\n"
0237:                        + "		}\n" + "	}\n" + "\n");
0238:                reformat();
0239:                assertDocumentText(
0240:                        "Incorrect try-catch reformatting",
0241:                        "void testError(CuTest *tc)\n"
0242:                                + "{\n"
0243:                                + "    IndexReader* reader = NULL;\n"
0244:                                + "    try {\n"
0245:                                + "        RAMDirectory dir;\n"
0246:                                + "    } catch (CLuceneError& a) {\n"
0247:                                + "        _CLDELETE(reader);\n"
0248:                                + "    } catch (...) {\n"
0249:                                + "        CuAssert(tc, _T(\"Error did not catch properly\"), false);\n"
0250:                                + "    }\n" + "}\n" + "\n");
0251:            }
0252:
0253:            public void testReformatNewlineBracesToNormalOnes3() {
0254:                setDefaultsOptions();
0255:                setDefaultsOptions();
0256:                setLoadDocumentText("try {\n"
0257:                        + "    printf(\"test\");\n"
0258:                        + "}\n"
0259:                        + "catch ( IllegalStateException illegalStateException  ) {\n"
0260:                        + "    illegalStateException.printStackTrace();\n"
0261:                        + "}\n");
0262:                reformat();
0263:                assertDocumentText(
0264:                        "Incorrect tabbed catch reformatting",
0265:                        "try {\n"
0266:                                + "    printf(\"test\");\n"
0267:                                + "} catch (IllegalStateException illegalStateException) {\n"
0268:                                + "    illegalStateException.printStackTrace();\n"
0269:                                + "}\n");
0270:            }
0271:
0272:            /**
0273:             * Test reformatting of multiline constructors
0274:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
0275:             */
0276:            public void testReformatMultilineConstructor() {
0277:                setDefaultsOptions();
0278:                EditorOptions.getPreferences(
0279:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0280:                        EditorOptions.newLineBeforeBraceClass,
0281:                        CodeStyle.BracePlacement.SAME_LINE.name());
0282:                EditorOptions.getPreferences(
0283:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0284:                        EditorOptions.newLineBeforeBraceDeclaration,
0285:                        CodeStyle.BracePlacement.SAME_LINE.name());
0286:                setLoadDocumentText("class Test {\n" + "Test(int one,\n"
0287:                        + "int two,\n" + "int three,\n" + "int four) {\n"
0288:                        + "this.one = one;\n" + "}\n" + "};");
0289:                reformat();
0290:                assertDocumentText(
0291:                        "Incorrect multiline constructor reformatting",
0292:                        "class Test {\n" + "    Test(int one,\n"
0293:                                + "            int two,\n"
0294:                                + "            int three,\n"
0295:                                + "            int four) {\n"
0296:                                + "        this.one = one;\n" + "    }\n"
0297:                                + "};");
0298:            }
0299:
0300:            /**
0301:             * Test reformatting of multiline constructors
0302:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
0303:             */
0304:            public void testReformatMultilineConstructor2() {
0305:                setDefaultsOptions();
0306:                setLoadDocumentText("class Test {\n" + "Test(int one,\n"
0307:                        + "int two,\n" + "int three,\n" + "int four) {\n"
0308:                        + "this.one = one;\n" + "}\n" + "};");
0309:                reformat();
0310:                assertDocumentText(
0311:                        "Incorrect multiline constructor reformatting",
0312:                        "class Test\n" + "{\n" + "    Test(int one,\n"
0313:                                + "            int two,\n"
0314:                                + "            int three,\n"
0315:                                + "            int four)\n" + "    {\n"
0316:                                + "        this.one = one;\n" + "    }\n"
0317:                                + "};");
0318:            }
0319:
0320:            /**
0321:             * Test reformatting of if else without brackets
0322:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
0323:             */
0324:            public void testReformatIfElseWithoutBrackets() {
0325:                setDefaultsOptions();
0326:                setLoadDocumentText("if (count == 0)\n" + "return 0.0f;\n"
0327:                        + "else\n" + "return performanceSum / getCount();\n");
0328:                reformat();
0329:                assertDocumentText(
0330:                        "Incorrect reformatting of if-else without brackets",
0331:                        "if (count == 0)\n" + "    return 0.0f;\n" + "else\n"
0332:                                + "    return performanceSum / getCount();\n");
0333:            }
0334:
0335:            /**
0336:             * Test reformatting of if else without brackets
0337:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
0338:             */
0339:            public void testReformatIfElseWithoutBrackets2() {
0340:                setDefaultsOptions();
0341:                setLoadDocumentText("if (count == 0)\n" + "return 0.0f;\n"
0342:                        + "else  {\n" + "return performanceSum / getCount();\n"
0343:                        + "}\n");
0344:                reformat();
0345:                assertDocumentText(
0346:                        "Incorrect reformatting of if-else without brackets",
0347:                        "if (count == 0)\n" + "    return 0.0f;\n" + "else {\n"
0348:                                + "    return performanceSum / getCount();\n"
0349:                                + "}\n");
0350:            }
0351:
0352:            /**
0353:             * Test reformatting of if else without brackets
0354:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
0355:             */
0356:            public void testReformatIfElseWithoutBrackets3() {
0357:                setDefaultsOptions();
0358:                setLoadDocumentText("if (true) if (true) if (true)\n"
0359:                        + "else return;\n" + "else return;\n"
0360:                        + "else return;\n");
0361:                reformat();
0362:                assertDocumentText(
0363:                        "Incorrect reformatting of if-else without brackets",
0364:                        "if (true) if (true) if (true)\n"
0365:                                + "        else return;\n"
0366:                                + "    else return;\n" + "else return;\n");
0367:            }
0368:
0369:            /**
0370:             * Test reformatting of if else without brackets
0371:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
0372:             */
0373:            public void testReformatIfElseWithoutBrackets4() {
0374:                setDefaultsOptions();
0375:                setLoadDocumentText("if (true)\n" + "    if (true)\n"
0376:                        + "    if (true)\n" + "else return;\n"
0377:                        + "else return;\n" + "else return;\n");
0378:                reformat();
0379:                assertDocumentText(
0380:                        "Incorrect reformatting of if-else without brackets",
0381:                        "if (true)\n" + "    if (true)\n"
0382:                                + "        if (true)\n"
0383:                                + "        else return;\n"
0384:                                + "    else return;\n" + "else return;\n");
0385:            }
0386:
0387:            /**
0388:             * Test reformatting of class
0389:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
0390:             */
0391:            public void testReformatSimpleClass() {
0392:                setDefaultsOptions();
0393:                EditorOptions.getPreferences(
0394:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0395:                        EditorOptions.newLineBeforeBraceClass,
0396:                        CodeStyle.BracePlacement.SAME_LINE.name());
0397:                setLoadDocumentText("class C {\n" + "protected:\n" + "int i;\n"
0398:                        + "int foo();\n" + "private:\n" + "int j;\n"
0399:                        + "public:\n" + "int k;\n" + "};\n");
0400:                reformat();
0401:                assertDocumentText("Incorrect reformatting of simple class",
0402:                        "class C {\n" + "protected:\n" + "    int i;\n"
0403:                                + "    int foo();\n" + "private:\n"
0404:                                + "    int j;\n" + "public:\n" + "    int k;\n"
0405:                                + "};\n");
0406:            }
0407:
0408:            /**
0409:             * Test reformatting of class
0410:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
0411:             */
0412:            public void testReformatSimpleClass2() {
0413:                setDefaultsOptions();
0414:                setLoadDocumentText("class C {\n" + "protected:\n" + "int i;\n"
0415:                        + "int foo();\n" + "private:\n" + "int j;\n"
0416:                        + "public:\n" + "int k;\n" + "};\n");
0417:                reformat();
0418:                assertDocumentText("Incorrect reformatting of simple class",
0419:                        "class C\n" + "{\n" + "protected:\n" + "    int i;\n"
0420:                                + "    int foo();\n" + "private:\n"
0421:                                + "    int j;\n" + "public:\n" + "    int k;\n"
0422:                                + "};\n");
0423:            }
0424:
0425:            /**
0426:             * Test reformatting of For without braces
0427:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=98475
0428:             */
0429:            public void testReformatForWithoutBraces() {
0430:                setDefaultsOptions();
0431:                setLoadDocumentText("for (i = 0; i < MAXBUCKET; i++) {\n"
0432:                        + "for (j = 0; j < MAXBUCKET; j++)\n"
0433:                        + "if (i != j) {\n" + "if (isempty()) {\n"
0434:                        + "pour(current, i, j);\n" + "insCnf(current);\n"
0435:                        + "}\n" + "}\n" + "}\n");
0436:                reformat();
0437:                assertDocumentText(
0438:                        "Incorrect reformatting of For without braces",
0439:                        "for (i = 0; i < MAXBUCKET; i++) {\n"
0440:                                + "    for (j = 0; j < MAXBUCKET; j++)\n"
0441:                                + "        if (i != j) {\n"
0442:                                + "            if (isempty()) {\n"
0443:                                + "                pour(current, i, j);\n"
0444:                                + "                insCnf(current);\n"
0445:                                + "            }\n" + "        }\n" + "}\n");
0446:            }
0447:
0448:            /**
0449:             * Test reformatting for preprocessors directives
0450:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
0451:             */
0452:            public void testReformatPreprocessorsDirectives() {
0453:                setDefaultsOptions();
0454:                EditorOptions.getPreferences(
0455:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0456:                        EditorOptions.newLineBeforeBraceDeclaration,
0457:                        CodeStyle.BracePlacement.SAME_LINE.name());
0458:                setLoadDocumentText("main() {\n" + "#define AAA 1\n"
0459:                        + "int aaa;\n" + "#define BBB 2\n" + "long bbb;\n"
0460:                        + "int ccc;\n" + "int ddd;\n" + "}\n");
0461:                reformat();
0462:                assertDocumentText(
0463:                        "Incorrect reformatting for preprocessors directives",
0464:                        "main() {\n" + "#define AAA 1\n" + "    int aaa;\n"
0465:                                + "#define BBB 2\n" + "    long bbb;\n"
0466:                                + "    int ccc;\n" + "    int ddd;\n" + "}\n");
0467:            }
0468:
0469:            /**
0470:             * Test reformatting for preprocessors directives
0471:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
0472:             */
0473:            public void testReformatPreprocessorsDirectives2() {
0474:                setDefaultsOptions();
0475:                setLoadDocumentText("main() {\n" + "#define AAA 1\n"
0476:                        + "int aaa;\n" + "#define BBB 2\n" + "long bbb;\n"
0477:                        + "int ccc;\n" + "int ddd;\n" + "}\n");
0478:                reformat();
0479:                assertDocumentText(
0480:                        "Incorrect reformatting for preprocessors directives",
0481:                        "main()\n" + "{\n" + "#define AAA 1\n"
0482:                                + "    int aaa;\n" + "#define BBB 2\n"
0483:                                + "    long bbb;\n" + "    int ccc;\n"
0484:                                + "    int ddd;\n" + "}\n");
0485:            }
0486:
0487:            /**
0488:             * Test reformatting of function arguments list
0489:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=115628
0490:             */
0491:            public void testReformatFunctionArguments() {
0492:                setDefaultsOptions();
0493:                EditorOptions.getPreferences(
0494:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0495:                        .putBoolean(EditorOptions.alignMultilineCallArgs, true);
0496:                setLoadDocumentText("int foo(int z){\n" + "z += myfoo(a,\n"
0497:                        + "b,\n" + "c);\n" + "}\n");
0498:                reformat();
0499:                assertDocumentText(
0500:                        "Incorrect reformatting of function arguments list",
0501:                        "int foo(int z)\n" + "{\n" + "    z += myfoo(a,\n"
0502:                                + "               b,\n"
0503:                                + "               c);\n" + "}\n");
0504:            }
0505:
0506:            /**
0507:             * Test reformatting of constructor initializer
0508:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
0509:             */
0510:            public void testReformatConstructorInitializer() {
0511:                setDefaultsOptions();
0512:                EditorOptions.getPreferences(
0513:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0514:                        EditorOptions.newLineBeforeBraceDeclaration,
0515:                        CodeStyle.BracePlacement.SAME_LINE.name());
0516:                setLoadDocumentText("Cpu::Cpu(int type, int architecture, int units) :\n"
0517:                        + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
0518:                        + "ComputeSupportMetric();\n" + "}\n");
0519:                reformat();
0520:                assertDocumentText(
0521:                        "Incorrect reformatting of constructor initializer",
0522:                        "Cpu::Cpu(int type, int architecture, int units) :\n"
0523:                                + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
0524:                                + "    ComputeSupportMetric();\n" + "}\n");
0525:            }
0526:
0527:            /**
0528:             * Test reformatting of constructor initializer
0529:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
0530:             */
0531:            public void testReformatConstructorInitializer2() {
0532:                setDefaultsOptions();
0533:                setLoadDocumentText("Cpu::Cpu(int type, int architecture, int units) :\n"
0534:                        + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
0535:                        + "ComputeSupportMetric();\n" + "}\n");
0536:                reformat();
0537:                assertDocumentText(
0538:                        "Incorrect reformatting of constructor initializer",
0539:                        "Cpu::Cpu(int type, int architecture, int units) :\n"
0540:                                + "Module(\"CPU\", \"generic\", type, architecture, units)\n"
0541:                                + "{\n" + "    ComputeSupportMetric();\n"
0542:                                + "}\n");
0543:            }
0544:
0545:            /**
0546:             * Test reformatting of constructor initializer
0547:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
0548:             */
0549:            public void testReformatMultilineMainDefinition() {
0550:                setDefaultsOptions();
0551:                EditorOptions.getPreferences(
0552:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0553:                        EditorOptions.newLineBeforeBraceDeclaration,
0554:                        CodeStyle.BracePlacement.SAME_LINE.name());
0555:                setLoadDocumentText("int\n" + "main(int argc, char** argv) {\n"
0556:                        + "return (EXIT_SUCCESS);\n" + "};\n");
0557:                reformat();
0558:                assertDocumentText(
0559:                        "Incorrect reformatting of multi line main definition",
0560:                        "int\n" + "main(int argc, char** argv) {\n"
0561:                                + "    return (EXIT_SUCCESS);\n" + "};\n");
0562:            }
0563:
0564:            /**
0565:             * Test reformatting of constructor initializer
0566:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
0567:             */
0568:            public void testReformatMultilineMainDefinition2() {
0569:                setDefaultsOptions();
0570:                setLoadDocumentText("int\n" + "main(int argc, char** argv) {\n"
0571:                        + "return (EXIT_SUCCESS);\n" + "};\n");
0572:                reformat();
0573:                assertDocumentText(
0574:                        "Incorrect reformatting of multi line main definition",
0575:                        "int\n" + "main(int argc, char** argv)\n" + "{\n"
0576:                                + "    return (EXIT_SUCCESS);\n" + "};\n");
0577:            }
0578:
0579:            /**
0580:             * Test reformatting of unbalanced braces
0581:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
0582:             */
0583:            public void testReformatUnbalancedBraces() {
0584:                setDefaultsOptions();
0585:                setLoadDocumentText("void foo() {\n" + "#if A\n" + "if (0) {\n"
0586:                        + "#else\n" + "if (1) {\n" + "#endif\n" + "}\n" + "}\n");
0587:                reformat();
0588:                assertDocumentText(
0589:                        "Incorrect reformatting of unbalanced braces",
0590:                        "void foo()\n" + "{\n" + "#if A\n" + "    if (0) {\n"
0591:                                + "#else\n" + "    if (1) {\n" + "#endif\n"
0592:                                + "    }\n" + "}\n");
0593:            }
0594:
0595:            public void testIdentInnerEnum() {
0596:                setDefaultsOptions();
0597:                EditorOptions.getPreferences(
0598:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0599:                        EditorOptions.newLineBeforeBraceClass,
0600:                        CodeStyle.BracePlacement.SAME_LINE.name());
0601:                setLoadDocumentText("class NdbTransaction {\n" + "#ifndef D\n"
0602:                        + "friend class Ndb;\n" + "#endif\n" + "\n"
0603:                        + "public:\n" + "\n" + "enum AbortOption {\n"
0604:                        + "#ifndef D\n" + "AbortOnError=::AbortOnError,\n"
0605:                        + "#endif\n" + "AO_IgnoreError=::AO_IgnoreError,\n"
0606:                        + "AO_SkipError\n" + "};\n" + "};\n");
0607:                reformat();
0608:                assertDocumentText(
0609:                        "Incorrect identing of inner enum",
0610:                        "class NdbTransaction {\n"
0611:                                + "#ifndef D\n"
0612:                                + "    friend class Ndb;\n"
0613:                                + "#endif\n"
0614:                                + "\n"
0615:                                + "public:\n"
0616:                                + "\n"
0617:                                + "    enum AbortOption {\n"
0618:                                + "#ifndef D\n"
0619:                                + "        AbortOnError = ::AbortOnError,\n"
0620:                                + "#endif\n"
0621:                                + "        AO_IgnoreError = ::AO_IgnoreError,\n"
0622:                                + "        AO_SkipError\n" + "    };\n"
0623:                                + "};\n");
0624:            }
0625:
0626:            public void testIdentInnerEnum2() {
0627:                setDefaultsOptions();
0628:                setLoadDocumentText("class NdbTransaction {\n" + "#ifndef D\n"
0629:                        + "friend class Ndb;\n" + "#endif\n" + "\n"
0630:                        + "public:\n" + "\n" + "enum AbortOption {\n"
0631:                        + "#ifndef D\n" + "AbortOnError=::AbortOnError,\n"
0632:                        + "#endif\n" + "AO_IgnoreError=::AO_IgnoreError,\n"
0633:                        + "AO_SkipError\n" + "};\n" + "};\n");
0634:                reformat();
0635:                assertDocumentText(
0636:                        "Incorrect identing of inner enum",
0637:                        "class NdbTransaction\n"
0638:                                + "{\n"
0639:                                + "#ifndef D\n"
0640:                                + "    friend class Ndb;\n"
0641:                                + "#endif\n"
0642:                                + "\n"
0643:                                + "public:\n"
0644:                                + "\n"
0645:                                + "    enum AbortOption\n"
0646:                                + "    {\n"
0647:                                + "#ifndef D\n"
0648:                                + "        AbortOnError = ::AbortOnError,\n"
0649:                                + "#endif\n"
0650:                                + "        AO_IgnoreError = ::AO_IgnoreError,\n"
0651:                                + "        AO_SkipError\n" + "    };\n"
0652:                                + "};\n");
0653:            }
0654:
0655:            public void testTemplate() {
0656:                setDefaultsOptions();
0657:                EditorOptions.getPreferences(
0658:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0659:                        EditorOptions.newLineBeforeBraceClass,
0660:                        CodeStyle.BracePlacement.SAME_LINE.name());
0661:                EditorOptions.getPreferences(
0662:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0663:                        EditorOptions.newLineBeforeBraceDeclaration,
0664:                        CodeStyle.BracePlacement.SAME_LINE.name());
0665:                setLoadDocumentText("template <class T, class U>\n"
0666:                        + "class KeyTable2 : public DLHashTable2<T, U> {\n"
0667:                        + "public:\n" + "KeyTable2(ArrayPool<U>& pool) :\n"
0668:                        + "DLHashTable2<T, U>(pool) {\n" + "}\n" + "\n"
0669:                        + "bool find(Ptr<T>& ptr, const T& rec) const {\n"
0670:                        + "return DLHashTable2<T, U>::find(ptr, rec);\n"
0671:                        + "}\n" + "};\n");
0672:                reformat();
0673:                assertDocumentText(
0674:                        "Incorrect identing of template class",
0675:                        "template <class T, class U>\n"
0676:                                + "class KeyTable2 : public DLHashTable2<T, U> {\n"
0677:                                + "public:\n"
0678:                                + "    KeyTable2(ArrayPool<U>& pool) :\n"
0679:                                + "    DLHashTable2<T, U>(pool) {\n"
0680:                                + "    }\n"
0681:                                + "\n"
0682:                                + "    bool find(Ptr<T>& ptr, const T& rec) const {\n"
0683:                                + "        return DLHashTable2<T, U>::find(ptr, rec);\n"
0684:                                + "    }\n" + "};\n");
0685:            }
0686:
0687:            public void testTemplate2() {
0688:                setDefaultsOptions();
0689:                setLoadDocumentText("template <class T, class U>\n"
0690:                        + "class KeyTable2 : public DLHashTable2<T, U> {\n"
0691:                        + "public:\n" + "KeyTable2(ArrayPool<U>& pool) :\n"
0692:                        + "DLHashTable2<T, U>(pool) {\n" + "}\n" + "\n"
0693:                        + "bool find(Ptr<T>& ptr, const T& rec) const {\n"
0694:                        + "return DLHashTable2<T, U>::find(ptr, rec);\n"
0695:                        + "}\n" + "};\n");
0696:                reformat();
0697:                assertDocumentText(
0698:                        "Incorrect identing of template class",
0699:                        "template <class T, class U>\n"
0700:                                + "class KeyTable2 : public DLHashTable2<T, U>\n"
0701:                                + "{\n"
0702:                                + "public:\n"
0703:                                + "    KeyTable2(ArrayPool<U>& pool) :\n"
0704:                                + "    DLHashTable2<T, U>(pool)\n"
0705:                                + "    {\n"
0706:                                + "    }\n"
0707:                                + "\n"
0708:                                + "    bool find(Ptr<T>& ptr, const T& rec) const\n"
0709:                                + "    {\n"
0710:                                + "        return DLHashTable2<T, U>::find(ptr, rec);\n"
0711:                                + "    }\n" + "};\n");
0712:            }
0713:
0714:            public void testIdentPreprocessorElase() {
0715:                setDefaultsOptions();
0716:                setLoadDocumentText("#if defined(USE_MB)\n"
0717:                        + "if (use_mb(cs)) {\n"
0718:                        + "result_state = IDENT_QUOTED;\n" + "}\n" + "#endif\n"
0719:                        + "{\n" + "}\n");
0720:                reformat();
0721:                assertDocumentText("Incorrect identing of preprocessor else",
0722:                        "#if defined(USE_MB)\n" + "if (use_mb(cs)) {\n"
0723:                                + "    result_state = IDENT_QUOTED;\n" + "}\n"
0724:                                + "#endif\n" + "{\n" + "}\n");
0725:            }
0726:
0727:            public void testIdentDefine() {
0728:                setDefaultsOptions();
0729:                setLoadDocumentText("int\n" + "main() {\n" + "int z;\n"
0730:                        + "#define X \\\n" + "        a+\\\n"
0731:                        + "        b+ \\\n" + "        c \n" + "z++;\n" + "}\n");
0732:                reformat();
0733:                assertDocumentText("Incorrect identing of preprocessor else",
0734:                        "int\n" + "main()\n" + "{\n" + "    int z;\n"
0735:                                + "#define X \\\n" + "        a+\\\n"
0736:                                + "        b+ \\\n" + "        c \n"
0737:                                + "    z++;\n" + "}\n");
0738:            }
0739:
0740:            public void testIdentMultyLineMain() {
0741:                setDefaultsOptions();
0742:                EditorOptions.getPreferences(
0743:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0744:                        EditorOptions.newLineBeforeBraceDeclaration,
0745:                        CodeStyle.BracePlacement.SAME_LINE.name());
0746:                setLoadDocumentText("long z;\n" + "int\n" + "main() {\n"
0747:                        + "short a;\n" + "}\n");
0748:                reformat();
0749:                assertDocumentText("Incorrect identing multyline main",
0750:                        "long z;\n" + "int\n" + "main() {\n" + "    short a;\n"
0751:                                + "}\n");
0752:            }
0753:
0754:            public void testIdentMultyLineMain2() {
0755:                setDefaultsOptions();
0756:                setLoadDocumentText("long z;\n" + "int\n" + "main() {\n"
0757:                        + "short a;\n" + "}\n");
0758:                reformat();
0759:                assertDocumentText("Incorrect identing multyline main",
0760:                        "long z;\n" + "int\n" + "main()\n" + "{\n"
0761:                                + "    short a;\n" + "}\n");
0762:            }
0763:
0764:            public void testIdentMultyConstructor() {
0765:                setDefaultsOptions();
0766:                EditorOptions.getPreferences(
0767:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0768:                        EditorOptions.newLineBeforeBraceDeclaration,
0769:                        CodeStyle.BracePlacement.SAME_LINE.name());
0770:                setLoadDocumentText("Log_event::Log_event(uint flags_arg, bool using_trans)\n"
0771:                        + "        :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)\n"
0772:                        + "        {\n"
0773:                        + "                server_id=thd->server_id;\n"
0774:                        + "        }\n");
0775:                reformat();
0776:                assertDocumentText(
0777:                        "Incorrect identing multyline constructor",
0778:                        "Log_event::Log_event(uint flags_arg, bool using_trans)\n"
0779:                                + ": log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg) {\n"
0780:                                + "    server_id = thd->server_id;\n" + "}\n");
0781:            }
0782:
0783:            public void testIdentMultyConstructor2() {
0784:                setDefaultsOptions();
0785:                EditorOptions.getPreferences(
0786:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0787:                        .putBoolean(EditorOptions.spaceAfterColon, false);
0788:                setLoadDocumentText("Log_event::Log_event(const char* buf,\n"
0789:                        + "        const Format_description_log_event* description_event)\n"
0790:                        + "        :temp_buf(0), cache_stmt(0)\n"
0791:                        + "        {\n"
0792:                        + "                server_id=thd->server_id;\n"
0793:                        + "        }\n");
0794:                reformat();
0795:                assertDocumentText(
0796:                        "Incorrect identing multyline constructor",
0797:                        "Log_event::Log_event(const char* buf,\n"
0798:                                + "        const Format_description_log_event* description_event)\n"
0799:                                + ":temp_buf(0), cache_stmt(0)\n" + "{\n"
0800:                                + "    server_id = thd->server_id;\n" + "}\n");
0801:            }
0802:
0803:            public void testIdentMultyConstructor3() {
0804:                setDefaultsOptions();
0805:                EditorOptions.getPreferences(
0806:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0807:                        .putBoolean(EditorOptions.spaceAfterColon, false);
0808:                EditorOptions.getPreferences(
0809:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0810:                        .putBoolean(EditorOptions.alignMultilineMethodParams,
0811:                                true);
0812:                setLoadDocumentText("Log_event::Log_event(const char* buf,\n"
0813:                        + "        const Format_description_log_event* description_event)\n"
0814:                        + "        :temp_buf(0), cache_stmt(0)\n"
0815:                        + "        {\n"
0816:                        + "                server_id=thd->server_id;\n"
0817:                        + "        }\n");
0818:                reformat();
0819:                assertDocumentText(
0820:                        "Incorrect identing multyline constructor",
0821:                        "Log_event::Log_event(const char* buf,\n"
0822:                                + "                     const Format_description_log_event* description_event)\n"
0823:                                + ":temp_buf(0), cache_stmt(0)\n" + "{\n"
0824:                                + "    server_id = thd->server_id;\n" + "}\n");
0825:            }
0826:
0827:            public void testIdentDefineBrace() {
0828:                setDefaultsOptions();
0829:                setLoadDocumentText("#define BRACE {\n" + "int main() {\n"
0830:                        + "if (a) {\n" + "}\n" + "}\n");
0831:                reformat();
0832:                assertDocumentText("Incorrect identing define brace",
0833:                        "#define BRACE {\n" + "int main()\n" + "{\n"
0834:                                + "    if (a) {\n" + "    }\n" + "}\n");
0835:            }
0836:
0837:            public void testIdentDefineBrace2() {
0838:                setDefaultsOptions();
0839:                setLoadDocumentText("#define BRACE }\n" + "int main() {\n"
0840:                        + "if (a) {\n" + "}\n" + "}\n");
0841:                reformat();
0842:                assertDocumentText("Incorrect identing define brace",
0843:                        "#define BRACE }\n" + "int main()\n" + "{\n"
0844:                                + "    if (a) {\n" + "    }\n" + "}\n");
0845:            }
0846:
0847:            //    public void testIdentMultyConstructor3() {
0848:            //        setDefaultsOptions();
0849:            //        setLoadDocumentText(
0850:            //            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" +
0851:            //            "        ulong query_length, bool using_trans,\n" +
0852:            //            "        bool suppress_use)\n" +
0853:            //            ":Log_event(thd_arg,\n" +
0854:            //            "        ((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0)\n" +
0855:            //            "        & (suppress_use          ? LOG_EVENT_SUPPRESS_USE_F    : 0)),\n" +
0856:            //            "                using_trans),\n" +
0857:            //            "                data_buf(0), query(query_arg), catalog(thd_arg->catalog),\n" +
0858:            //            "                db(thd_arg->db), q_len((uint32) query_length),\n" +
0859:            //            "                error_code((thd_arg->killed != THD::NOT_KILLED) ?\n" +
0860:            //            "                    ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ?\n" +
0861:            //            "                        0 : thd->killed_errno()) : thd_arg->net.last_errno),\n" +
0862:            //            "                                thread_id(thd_arg->thread_id),\n" +
0863:            //            "                                /* save the original thread id; we already know the server id */\n" +
0864:            //            "                                slave_proxy_id(thd_arg->variables.pseudo_thread_id),\n" +
0865:            //            "                                flags2_inited(1), sql_mode_inited(1), charset_inited(1),\n" +
0866:            //            "                                sql_mode(thd_arg->variables.sql_mode),\n" +
0867:            //            "                                auto_increment_increment(thd_arg->variables.auto_increment_increment),\n" +
0868:            //            "                                auto_increment_offset(thd_arg->variables.auto_increment_offset)\n" +
0869:            //            "                        {\n" +
0870:            //            "                            time_t end_time;\n" +
0871:            //            "                        }\n"
0872:            //            );
0873:            //        reformat();
0874:            //        assertDocumentText("Incorrect identing multyline constructor",
0875:            //            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" +
0876:            //            "        ulong query_length, bool using_trans,\n" +
0877:            //            "        bool suppress_use)\n" +
0878:            //            ": Log_event(thd_arg,\n" +
0879:            //            "        ((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0)\n" +
0880:            //            "        & (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0)),\n" +
0881:            //            "        using_trans),\n" +
0882:            //            "        data_buf(0), query(query_arg), catalog(thd_arg->catalog),\n" +
0883:            //            "        db(thd_arg->db), q_len((uint32) query_length),\n" +
0884:            //            "        error_code((thd_arg->killed != THD::NOT_KILLED) ?\n" +
0885:            //            "            ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ?\n" +
0886:            //            "                 0 : thd->killed_errno()) : thd_arg->net.last_errno),\n" +
0887:            //            "        thread_id(thd_arg->thread_id),\n" +
0888:            //            "        /* save the original thread id; we already know the server id */\n" +
0889:            //            "        slave_proxy_id(thd_arg->variables.pseudo_thread_id),\n" +
0890:            //            "        flags2_inited(1), sql_mode_inited(1), charset_inited(1),\n" +
0891:            //            "        sql_mode(thd_arg->variables.sql_mode),\n" +
0892:            //            "        auto_increment_increment(thd_arg->variables.auto_increment_increment),\n" +
0893:            //            "        auto_increment_offset(thd_arg->variables.auto_increment_offset) {\n" +
0894:            //            "    time_t end_time;\n" +
0895:            //            "}\n"
0896:            //        );
0897:            //    }
0898:
0899:            public void testMacroDefineWithBrace() {
0900:                setDefaultsOptions();
0901:                setLoadDocumentText("#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0902:                reformat();
0903:                assertDocumentText(
0904:                        "Incorrect formatting for macro define with brace",
0905:                        "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0906:            }
0907:
0908:            public void testMacroDefineWithBrace1() {
0909:                setDefaultsOptions();
0910:                setLoadDocumentText("\n"
0911:                        + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0912:                reformat();
0913:                assertDocumentText(
0914:                        "Incorrect formatting for macro define with brace",
0915:                        "\n"
0916:                                + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0917:            };
0918:
0919:            public void testMacroDefineWithBrace2() {
0920:                setDefaultsOptions();
0921:                EditorOptions.getPreferences(
0922:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0923:                        EditorOptions.newLineBeforeBrace,
0924:                        CodeStyle.BracePlacement.NEW_LINE.name());
0925:                setLoadDocumentText("#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0926:                reformat();
0927:                assertDocumentText(
0928:                        "Incorrect formatting for macro define with brace",
0929:                        "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0930:            }
0931:
0932:            public void testMacroDefineWithBrace3() {
0933:                setDefaultsOptions();
0934:                EditorOptions.getPreferences(
0935:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0936:                        EditorOptions.newLineBeforeBrace,
0937:                        CodeStyle.BracePlacement.NEW_LINE.name());
0938:                setLoadDocumentText("\n"
0939:                        + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0940:                reformat();
0941:                assertDocumentText(
0942:                        "Incorrect formatting for macro define with brace",
0943:                        "\n"
0944:                                + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
0945:            }
0946:
0947:            public void testMacroDefineWithParen() {
0948:                setDefaultsOptions();
0949:                EditorOptions.getPreferences(
0950:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0951:                        EditorOptions.newLineBeforeBraceDeclaration,
0952:                        CodeStyle.BracePlacement.SAME_LINE.name());
0953:                setLoadDocumentText("#include <stdio.h>\n"
0954:                        + "#define M(x) puts(#x)\n" + "int main() {\n"
0955:                        + "M(\"test\");\n" + "return 0;\n" + "}\n");
0956:                reformat();
0957:                assertDocumentText(
0958:                        "Incorrect formatting for macro define with paren",
0959:                        "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
0960:                                + "int main() {\n" + "    M(\"test\");\n"
0961:                                + "    return 0;\n" + "}\n");
0962:            }
0963:
0964:            public void testMacroDefineWithParen11() {
0965:                setDefaultsOptions();
0966:                setLoadDocumentText("#include <stdio.h>\n"
0967:                        + "#define M(x) puts(#x)\n" + "int main() {\n"
0968:                        + "M(\"test\");\n" + "return 0;\n" + "}\n");
0969:                reformat();
0970:                assertDocumentText(
0971:                        "Incorrect formatting for macro define with paren",
0972:                        "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
0973:                                + "int main()\n" + "{\n" + "    M(\"test\");\n"
0974:                                + "    return 0;\n" + "}\n");
0975:            }
0976:
0977:            public void testMacroDefineWithParen2() {
0978:                setDefaultsOptions();
0979:                EditorOptions.getPreferences(
0980:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0981:                        .putBoolean(EditorOptions.spaceBeforeMethodCallParen,
0982:                                true);
0983:                EditorOptions.getPreferences(
0984:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
0985:                        .putBoolean(EditorOptions.spaceBeforeMethodDeclParen,
0986:                                true);
0987:                EditorOptions.getPreferences(
0988:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
0989:                        EditorOptions.newLineBeforeBraceDeclaration,
0990:                        CodeStyle.BracePlacement.SAME_LINE.name());
0991:                setLoadDocumentText("#include <stdio.h>\n"
0992:                        + "#define M(x) puts(#x)\n" + "int main() {\n"
0993:                        + "    M(\"test\");\n" + "    return 0;\n" + "}\n");
0994:                reformat();
0995:                assertDocumentText(
0996:                        "Incorrect formatting for macro define with paren",
0997:                        "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
0998:                                + "int main () {\n" + "    M (\"test\");\n"
0999:                                + "    return 0;\n" + "}\n");
1000:            }
1001:
1002:            public void testMacroDefineWithParen21() {
1003:                setDefaultsOptions();
1004:                EditorOptions.getPreferences(
1005:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1006:                        .putBoolean(EditorOptions.spaceBeforeMethodCallParen,
1007:                                true);
1008:                setLoadDocumentText("#include <stdio.h>\n"
1009:                        + "#define M(x) puts(#x)\n" + "int main() {\n"
1010:                        + "    M(\"test\");\n" + "    return 0;\n" + "}\n");
1011:                reformat();
1012:                assertDocumentText(
1013:                        "Incorrect formatting for macro define with paren",
1014:                        "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
1015:                                + "int main()\n" + "{\n"
1016:                                + "    M (\"test\");\n" + "    return 0;\n"
1017:                                + "}\n");
1018:            }
1019:
1020:            public void testSwitchFormatting() {
1021:                setDefaultsOptions();
1022:                setLoadDocumentText("switch (GetTypeID()) {\n" + "case FAST:\n"
1023:                        + "metric += 100;\n" + "break;\n" + "case ULTRA:\n"
1024:                        + "case SLOW:\n" + "metric += 200;\n" + "break;\n"
1025:                        + "default:\n" + "break;\n" + "}\n");
1026:                reformat();
1027:                assertDocumentText(
1028:                        "Incorrect formatting for macro define with paren",
1029:                        "switch (GetTypeID()) {\n" + "    case FAST:\n"
1030:                                + "        metric += 100;\n"
1031:                                + "        break;\n" + "    case ULTRA:\n"
1032:                                + "    case SLOW:\n"
1033:                                + "        metric += 200;\n"
1034:                                + "        break;\n" + "    default:\n"
1035:                                + "        break;\n" + "}\n");
1036:            }
1037:
1038:            public void testSwitchFormatting2() {
1039:                setDefaultsOptions();
1040:                EditorOptions.getPreferences(
1041:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1042:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
1043:                setLoadDocumentText("switch (GetTypeID()) {\n" + "case FAST:\n"
1044:                        + "metric += 100;\n" + "break;\n" + "case ULTRA:\n"
1045:                        + "case SLOW:\n" + "metric += 200;\n" + "break;\n"
1046:                        + "default:\n" + "break;\n" + "}\n");
1047:                reformat();
1048:                assertDocumentText(
1049:                        "Incorrect formatting for macro define with paren",
1050:                        "switch (GetTypeID()) {\n" + "case FAST:\n"
1051:                                + "    metric += 100;\n" + "    break;\n"
1052:                                + "case ULTRA:\n" + "case SLOW:\n"
1053:                                + "    metric += 200;\n" + "    break;\n"
1054:                                + "default:\n" + "    break;\n" + "}\n");
1055:            }
1056:
1057:            public void testSwitchFormatting3() {
1058:                setDefaultsOptions();
1059:                setLoadDocumentText("int main(int i)\n" + "{\n"
1060:                        + "    switch (i) {\n" + "        case 1:\n"
1061:                        + "        return 1;\n" + "        case 4 :\n"
1062:                        + "                   if (true)return;\n"
1063:                        + "                   else {break;}\n"
1064:                        + "        break;\n" + "        case 14 :\n"
1065:                        + "        {\n" + "        i++;\n" + "        }\n"
1066:                        + "        case 6:\n" + "        return;\n"
1067:                        + "    default:\n" + "        break;\n" + "    }\n"
1068:                        + "    if (i != 8)\n" + "        switch (i) {\n"
1069:                        + "        case 1:\n" + "        return 1;\n"
1070:                        + "        case 2:\n" + "        break;\n"
1071:                        + "        case 4 :\n" + "                i++;\n"
1072:                        + "           case 6:\n"
1073:                        + "               switch (i * 2) {\n"
1074:                        + "            case 10:\n"
1075:                        + "                   if (true)return;\n"
1076:                        + "                   else {break;}\n"
1077:                        + "       case 12:\n" + "                {\n"
1078:                        + "                break;\n" + "                }\n"
1079:                        + "        }\n" + "     default :\n"
1080:                        + "            break;\n" + "     }\n" + "}\n");
1081:                reformat();
1082:                assertDocumentText(
1083:                        "Incorrect formatting for macro define with paren",
1084:                        "int main(int i)\n" + "{\n" + "    switch (i) {\n"
1085:                                + "        case 1:\n"
1086:                                + "            return 1;\n"
1087:                                + "        case 4:\n"
1088:                                + "            if (true)return;\n"
1089:                                + "            else {\n"
1090:                                + "                break;\n"
1091:                                + "            }\n" + "            break;\n"
1092:                                + "        case 14:\n" + "        {\n"
1093:                                + "            i++;\n" + "        }\n"
1094:                                + "        case 6:\n" + "            return;\n"
1095:                                + "        default:\n" + "            break;\n"
1096:                                + "    }\n" + "    if (i != 8)\n"
1097:                                + "        switch (i) {\n"
1098:                                + "            case 1:\n"
1099:                                + "                return 1;\n"
1100:                                + "            case 2:\n"
1101:                                + "                break;\n"
1102:                                + "            case 4:\n"
1103:                                + "                i++;\n"
1104:                                + "            case 6:\n"
1105:                                + "                switch (i * 2) {\n"
1106:                                + "                    case 10:\n"
1107:                                + "                        if (true)return;\n"
1108:                                + "                        else {\n"
1109:                                + "                            break;\n"
1110:                                + "                        }\n"
1111:                                + "                    case 12:\n"
1112:                                + "                    {\n"
1113:                                + "                        break;\n"
1114:                                + "                    }\n"
1115:                                + "                }\n"
1116:                                + "            default:\n"
1117:                                + "                break;\n" + "        }\n"
1118:                                + "}\n");
1119:            }
1120:
1121:            public void testSwitchFormatting4() {
1122:                setDefaultsOptions();
1123:                EditorOptions.getPreferences(
1124:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1125:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
1126:                setLoadDocumentText("int main(int i)\n" + "{\n"
1127:                        + "    switch (i) {\n" + "        case 1:\n"
1128:                        + "        return 1;\n" + "        case 4 :\n"
1129:                        + "        i++;\n" + "        case 6:\n"
1130:                        + "        return;\n" + "    default:\n"
1131:                        + "        break;\n" + "    }\n" + "    if (i != 8)\n"
1132:                        + "        switch (i) {\n" + "        case 1:\n"
1133:                        + "        return 1;\n" + "        case 2:\n"
1134:                        + "        break;\n" + "        case 4 :\n"
1135:                        + "                i++;\n" + "           case 6:\n"
1136:                        + "               switch (i * 2) {\n"
1137:                        + "            case 10:\n"
1138:                        + "                   return;\n" + "       case 12:\n"
1139:                        + "                break;\n" + "        }\n"
1140:                        + "     default :\n" + "            break;\n"
1141:                        + "     }\n" + "}\n");
1142:                reformat();
1143:                assertDocumentText(
1144:                        "Incorrect formatting for macro define with paren",
1145:                        "int main(int i)\n" + "{\n" + "    switch (i) {\n"
1146:                                + "    case 1:\n" + "        return 1;\n"
1147:                                + "    case 4:\n" + "        i++;\n"
1148:                                + "    case 6:\n" + "        return;\n"
1149:                                + "    default:\n" + "        break;\n"
1150:                                + "    }\n" + "    if (i != 8)\n"
1151:                                + "        switch (i) {\n"
1152:                                + "        case 1:\n"
1153:                                + "            return 1;\n"
1154:                                + "        case 2:\n" + "            break;\n"
1155:                                + "        case 4:\n" + "            i++;\n"
1156:                                + "        case 6:\n"
1157:                                + "            switch (i * 2) {\n"
1158:                                + "            case 10:\n"
1159:                                + "                return;\n"
1160:                                + "            case 12:\n"
1161:                                + "                break;\n"
1162:                                + "            }\n" + "        default:\n"
1163:                                + "            break;\n" + "        }\n"
1164:                                + "}\n");
1165:            }
1166:
1167:            public void testDoxyGenIdent() {
1168:                setDefaultsOptions();
1169:                setLoadDocumentText("        /**\n"
1170:                        + "         * Class for accessing a compound stream.\n"
1171:                        + "         *\n"
1172:                        + "         * @version $Id: CompoundFile.h,v 1.1.2.12 2005/11/02 12:44:22 ustramooner Exp $\n"
1173:                        + "         */\n"
1174:                        + "        class CompoundFileReader: public CL_NS(store)::Directory {\n"
1175:                        + "        }\n");
1176:                reformat();
1177:                assertDocumentText(
1178:                        "Incorrect identing doc comment",
1179:                        "/**\n"
1180:                                + " * Class for accessing a compound stream.\n"
1181:                                + " *\n"
1182:                                + " * @version $Id: CompoundFile.h,v 1.1.2.12 2005/11/02 12:44:22 ustramooner Exp $\n"
1183:                                + " */\n"
1184:                                + "class CompoundFileReader : public CL_NS(store)::Directory\n"
1185:                                + "{\n" + "}\n");
1186:            }
1187:
1188:            public void testBlockCommentIdent() {
1189:                setDefaultsOptions();
1190:                setLoadDocumentText("        /*\n"
1191:                        + "         * Class for accessing a compound stream.\n"
1192:                        + "         *\n"
1193:                        + "         * @version $Id: CompoundFile.h,v 1.1.2.12 2005/11/02 12:44:22 ustramooner Exp $\n"
1194:                        + "         */\n"
1195:                        + "        class CompoundFileReader: public CL_NS(store)::Directory {\n"
1196:                        + "        }\n");
1197:                reformat();
1198:                assertDocumentText(
1199:                        "Incorrect identing block comment",
1200:                        "/*\n"
1201:                                + " * Class for accessing a compound stream.\n"
1202:                                + " *\n"
1203:                                + " * @version $Id: CompoundFile.h,v 1.1.2.12 2005/11/02 12:44:22 ustramooner Exp $\n"
1204:                                + " */\n"
1205:                                + "class CompoundFileReader : public CL_NS(store)::Directory\n"
1206:                                + "{\n" + "}\n");
1207:            }
1208:
1209:            public void testIdentElse() {
1210:                setDefaultsOptions();
1211:                setLoadDocumentText("    void FieldsWriter::addDocument(Document* doc)\n"
1212:                        + "    {\n"
1213:                        + "         if (field->stringValue() == NULL) {\n"
1214:                        + "             Reader* r = field->readerValue();\n"
1215:                        + "         }    else\n"
1216:                        + "         fieldsStream->writeString(field->stringValue(), _tcslen(field->stringValue()));\n"
1217:                        + "    }\n");
1218:                reformat();
1219:                assertDocumentText(
1220:                        "Incorrect identing eles without {}",
1221:                        "void FieldsWriter::addDocument(Document* doc)\n"
1222:                                + "{\n"
1223:                                + "    if (field->stringValue() == NULL) {\n"
1224:                                + "        Reader* r = field->readerValue();\n"
1225:                                + "    } else\n"
1226:                                + "        fieldsStream->writeString(field->stringValue(), _tcslen(field->stringValue()));\n"
1227:                                + "}\n");
1228:            }
1229:
1230:            public void testIdentDoWhile() {
1231:                setDefaultsOptions();
1232:                setLoadDocumentText(" int foo()\n" + " {\n" + " do {\n"
1233:                        + " try {\n" + " op1().op2.op3().op4();\n"
1234:                        + " } catch (Throwable t) {\n" + " log();\n" + " }\n"
1235:                        + " }\n" + " while (this.number < 2 && number != 3);\n"
1236:                        + " }\n");
1237:                reformat();
1238:                assertDocumentText("Incorrect identing doWhile", "int foo()\n"
1239:                        + "{\n" + "    do {\n" + "        try {\n"
1240:                        + "            op1().op2.op3().op4();\n"
1241:                        + "        } catch (Throwable t) {\n"
1242:                        + "            log();\n" + "        }\n"
1243:                        + "    } while (this.number < 2 && number != 3);\n"
1244:                        + "}\n");
1245:            }
1246:
1247:            public void testIdentInlineMethod() {
1248:                setDefaultsOptions();
1249:                setLoadDocumentText("class IndexReader : LUCENE_BASE\n"
1250:                        + "{\n"
1251:                        + "    		CL_NS(store)::Directory* getDirectory() { return directory; }\n"
1252:                        + "};\n");
1253:                reformat();
1254:                assertDocumentText(
1255:                        "Incorrect identing multyline constructor",
1256:                        "class IndexReader : LUCENE_BASE\n"
1257:                                + "{\n"
1258:                                + "    CL_NS(store)::Directory* getDirectory()\n"
1259:                                + "    {\n" + "        return directory;\n"
1260:                                + "    }\n" + "};\n");
1261:            }
1262:
1263:            public void testIdentInlineMethod2() {
1264:                setDefaultsOptions();
1265:                setLoadDocumentText("    		CL_NS(store)::Directory* getDirectory() { return directory; }\n");
1266:                reformat();
1267:                assertDocumentText("Incorrect identing multyline constructor",
1268:                        "CL_NS(store)::Directory* getDirectory()\n" + "{\n"
1269:                                + "    return directory;\n" + "}\n");
1270:            }
1271:
1272:            // end line comment should prevent move left brace on same line by design
1273:            // RFE: move brace before end line comment in future
1274:            public void testBraceBeforeLineComment() {
1275:                setDefaultsOptions();
1276:                setLoadDocumentText("int foo()\n" + "{\n"
1277:                        + "if (!line) // End of file\n" + "{\n"
1278:                        + "status.exit_status = 0;\n" + "break;\n" + "}\n"
1279:                        + "}\n");
1280:                reformat();
1281:                assertDocumentText(
1282:                        "Incorrect formatting brace before line comment",
1283:                        "int foo()\n" + "{\n"
1284:                                + "    if (!line) // End of file\n" + "    {\n"
1285:                                + "        status.exit_status = 0;\n"
1286:                                + "        break;\n" + "    }\n" + "}\n");
1287:            }
1288:
1289:            public void testCaseIndentAftePreprocessor() {
1290:                setDefaultsOptions();
1291:                setLoadDocumentText("int foo() {\n" + "     switch (optid) {\n"
1292:                        + "#ifdef __NETWARE__\n"
1293:                        + "        case OPT_AUTO_CLOSE:\n"
1294:                        + "        setscreenmode(SCR_AUTOCLOSE_ON_EXIT);\n"
1295:                        + "#define X\n" + "        break;\n" + "#endif\n"
1296:                        + "        case OPT_CHARSETS_DIR:\n"
1297:                        + "        strmov(mysql_charsets_dir, argument);\n"
1298:                        + "        charsets_dir = mysql_charsets_dir;\n"
1299:                        + "        break;\n"
1300:                        + "    case OPT_DEFAULT_CHARSET:\n"
1301:                        + "        default_charset_used = 1;\n"
1302:                        + "        break;\n" + "}\n" + "}\n");
1303:                reformat();
1304:                assertDocumentText(
1305:                        "Incorrect identing case after preprocessor",
1306:                        "int foo()\n"
1307:                                + "{\n"
1308:                                + "    switch (optid) {\n"
1309:                                + "#ifdef __NETWARE__\n"
1310:                                + "        case OPT_AUTO_CLOSE:\n"
1311:                                + "            setscreenmode(SCR_AUTOCLOSE_ON_EXIT);\n"
1312:                                + "#define X\n"
1313:                                + "            break;\n"
1314:                                + "#endif\n"
1315:                                + "        case OPT_CHARSETS_DIR:\n"
1316:                                + "            strmov(mysql_charsets_dir, argument);\n"
1317:                                + "            charsets_dir = mysql_charsets_dir;\n"
1318:                                + "            break;\n"
1319:                                + "        case OPT_DEFAULT_CHARSET:\n"
1320:                                + "            default_charset_used = 1;\n"
1321:                                + "            break;\n" + "    }\n" + "}\n");
1322:            }
1323:
1324:            public void testCaseIndentAftePreprocessor2() {
1325:                setDefaultsOptions();
1326:                EditorOptions.getPreferences(
1327:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1328:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
1329:                setLoadDocumentText("int foo() {\n" + "     switch (optid) {\n"
1330:                        + "#ifdef __NETWARE__\n"
1331:                        + "        case OPT_AUTO_CLOSE:\n"
1332:                        + "        setscreenmode(SCR_AUTOCLOSE_ON_EXIT);\n"
1333:                        + "#define X\n" + "        break;\n" + "#endif\n"
1334:                        + "        case OPT_CHARSETS_DIR:\n" + "#define Y\n"
1335:                        + "        {\n"
1336:                        + "        strmov(mysql_charsets_dir, argument);\n"
1337:                        + "        charsets_dir = mysql_charsets_dir;\n"
1338:                        + "        break;\n" + "}\n"
1339:                        + "    case OPT_DEFAULT_CHARSET:\n"
1340:                        + "        default_charset_used = 1;\n"
1341:                        + "        break;\n" + "}\n" + "}\n");
1342:                reformat();
1343:                assertDocumentText(
1344:                        "Incorrect identing case after preprocessor",
1345:                        "int foo()\n"
1346:                                + "{\n"
1347:                                + "    switch (optid) {\n"
1348:                                + "#ifdef __NETWARE__\n"
1349:                                + "    case OPT_AUTO_CLOSE:\n"
1350:                                + "        setscreenmode(SCR_AUTOCLOSE_ON_EXIT);\n"
1351:                                + "#define X\n"
1352:                                + "        break;\n"
1353:                                + "#endif\n"
1354:                                + "    case OPT_CHARSETS_DIR:\n"
1355:                                + "#define Y\n"
1356:                                + "    {\n"
1357:                                + "        strmov(mysql_charsets_dir, argument);\n"
1358:                                + "        charsets_dir = mysql_charsets_dir;\n"
1359:                                + "        break;\n" + "    }\n"
1360:                                + "    case OPT_DEFAULT_CHARSET:\n"
1361:                                + "        default_charset_used = 1;\n"
1362:                                + "        break;\n" + "    }\n" + "}\n");
1363:            }
1364:
1365:            public void testTypedefClassNameIndent() {
1366:                setDefaultsOptions();
1367:                setLoadDocumentText("typedef struct st_line_buffer\n" + "{\n"
1368:                        + "File file;\n" + "char *buffer;\n"
1369:                        + "/* The buffer itself, grown as needed. */\n"
1370:                        + "}LINE_BUFFER;\n");
1371:                reformat();
1372:                assertDocumentText(
1373:                        "Incorrect identing case after preprocessor",
1374:                        "typedef struct st_line_buffer\n"
1375:                                + "{\n"
1376:                                + "    File file;\n"
1377:                                + "    char *buffer;\n"
1378:                                + "    /* The buffer itself, grown as needed. */\n"
1379:                                + "} LINE_BUFFER;\n");
1380:            }
1381:
1382:            public void testLabelIndent() {
1383:                setDefaultsOptions();
1384:                setLoadDocumentText("int foo()\n" + "{\n" + "end:\n"
1385:                        + "if (fd >= 0)\n"
1386:                        + "        my_close(fd, MYF(MY_WME));\n"
1387:                        + "    return error;\n" + "}\n");
1388:                reformat();
1389:                assertDocumentText("Incorrect label indent", "int foo()\n"
1390:                        + "{\n" + "end:\n" + "    if (fd >= 0)\n"
1391:                        + "        my_close(fd, MYF(MY_WME));\n"
1392:                        + "    return error;\n" + "}\n");
1393:            }
1394:
1395:            public void testIdentBlockAfterDirective() {
1396:                setDefaultsOptions();
1397:                setLoadDocumentText("int yyparse()\n"
1398:                        + "{\n"
1399:                        + "    yychar = - 1;\n"
1400:                        + "#if YYMAXDEPTH <= 0\n"
1401:                        + "    if (yymaxdepth <= 0) {\n"
1402:                        + "        if ((yymaxdepth = YYEXPAND(0)) <= 0) {\n"
1403:                        + "            yyerror(\"yacc initialization error\");\n"
1404:                        + "            YYABORT;\n" + "        }\n" + "    }\n"
1405:                        + "#endif\n" + " {\n"
1406:                        + "        register YYSTYPE *yy_pv;\n"
1407:                        + "        /* top of value stack */\n" + "}\n" + "}\n");
1408:                reformat();
1409:                assertDocumentText(
1410:                        "Incorrect identing coode block after directive",
1411:                        "int yyparse()\n"
1412:                                + "{\n"
1413:                                + "    yychar = - 1;\n"
1414:                                + "#if YYMAXDEPTH <= 0\n"
1415:                                + "    if (yymaxdepth <= 0) {\n"
1416:                                + "        if ((yymaxdepth = YYEXPAND(0)) <= 0) {\n"
1417:                                + "            yyerror(\"yacc initialization error\");\n"
1418:                                + "            YYABORT;\n" + "        }\n"
1419:                                + "    }\n" + "#endif\n" + "    {\n"
1420:                                + "        register YYSTYPE *yy_pv;\n"
1421:                                + "        /* top of value stack */\n"
1422:                                + "    }\n" + "}\n");
1423:            }
1424:
1425:            public void testMacroBeforePrepricessor() {
1426:                setDefaultsOptions();
1427:                EditorOptions.getPreferences(
1428:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1429:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
1430:                setLoadDocumentText("int yyparse()\n"
1431:                        + "{\n"
1432:                        + "    switch (nchar) {\n"
1433:                        + "        /* split current window in two parts, horizontally */\n"
1434:                        + "    case 'S':\n"
1435:                        + "    case 's':\n"
1436:                        + "        CHECK_CMDWIN\n"
1437:                        + "#    ifdef FEAT_VISUAL\n"
1438:                        + "reset_VIsual_and_resel();\n"
1439:                        + "        /* stop Visual mode */\n"
1440:                        + "#    endif\n"
1441:                        + "    case 'W':\n"
1442:                        + "        CHECK_CMDWIN\n"
1443:                        + "if (lastwin == firstwin && Prenum != 1) /* just one window */\n"
1444:                        + "            beep_flush();\n" + "}\n" + "}\n");
1445:                reformat();
1446:                assertDocumentText(
1447:                        "Incorrect identing macro before preoprocessor",
1448:                        "int yyparse()\n"
1449:                                + "{\n"
1450:                                + "    switch (nchar) {\n"
1451:                                + "        /* split current window in two parts, horizontally */\n"
1452:                                + "    case 'S':\n"
1453:                                + "    case 's':\n"
1454:                                + "        CHECK_CMDWIN\n"
1455:                                + "#ifdef FEAT_VISUAL\n"
1456:                                + "                reset_VIsual_and_resel();\n"
1457:                                + "        /* stop Visual mode */\n"
1458:                                + "#endif\n"
1459:                                + "    case 'W':\n"
1460:                                + "        CHECK_CMDWIN\n"
1461:                                + "        if (lastwin == firstwin && Prenum != 1) /* just one window */\n"
1462:                                + "            beep_flush();\n" + "    }\n"
1463:                                + "}\n");
1464:            }
1465:
1466:            public void testIdentElseBeforePreprocessor() {
1467:                setDefaultsOptions();
1468:                EditorOptions.getPreferences(
1469:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
1470:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
1471:                setLoadDocumentText("int yyparse()\n"
1472:                        + "{\n"
1473:                        + "#ifdef X\n"
1474:                        + "    if (true) {\n"
1475:                        + "        if (oldwin->w_p_wfw)\n"
1476:                        + "            win_setwidth_win(oldwin->w_width + new_size, oldwin);\n"
1477:                        + "    } else\n" + "#    endif\n" + " {\n"
1478:                        + "        layout = FR_COL;\n" + "}\n" + "}\n");
1479:                reformat();
1480:                assertDocumentText(
1481:                        "Incorrect identing else before preprocessor",
1482:                        "int yyparse()\n"
1483:                                + "{\n"
1484:                                + "#ifdef X\n"
1485:                                + "    if (true) {\n"
1486:                                + "        if (oldwin->w_p_wfw)\n"
1487:                                + "            win_setwidth_win(oldwin->w_width + new_size, oldwin);\n"
1488:                                + "    } else\n" + "#endif\n" + "    {\n"
1489:                                + "        layout = FR_COL;\n" + "    }\n"
1490:                                + "}\n");
1491:            }
1492:
1493:            public void testIdentK_and_R_style() {
1494:                setDefaultsOptions();
1495:                setLoadDocumentText("static void\n" + "win_init(newp, oldp)\n"
1496:                        + "win_T *newp;\n" + "win_T *oldp;\n" + "{\n"
1497:                        + "    int i;\n" + "}\n");
1498:                reformat();
1499:                assertDocumentText("Incorrect identing K&R declaration",
1500:                        "static void\n" + "win_init(newp, oldp)\n"
1501:                                + "win_T *newp;\n" + "win_T *oldp;\n" + "{\n"
1502:                                + "    int i;\n" + "}\n");
1503:            }
1504:
1505:            public void testIdentK_and_R_style2() {
1506:                setDefaultsOptions();
1507:                setLoadDocumentText("extern \"C\" {\n" + "static void\n"
1508:                        + "win_init(newp, oldp)\n" + "win_T *newp;\n"
1509:                        + "win_T *oldp;\n" + "{\n" + "    int i;\n" + "}\n"
1510:                        + "}\n");
1511:                reformat();
1512:                assertDocumentText("Incorrect identing multyline constructor",
1513:                        "extern \"C\"\n" + "{\n" + "    static void\n"
1514:                                + "    win_init(newp, oldp)\n"
1515:                                + "    win_T *newp;\n" + "    win_T *oldp;\n"
1516:                                + "    {\n" + "        int i;\n" + "    }\n"
1517:                                + "}\n");
1518:            }
1519:
1520:            public void testIdentInBlockComment() {
1521:                setDefaultsOptions();
1522:                setLoadDocumentText("extern \"C\" {\n" + "static void\n"
1523:                        + "win_init(newp, oldp)\n" + "win_T *newp;\n"
1524:                        + "win_T *oldp;\n" + "           /*\n"
1525:                        + "             Preserve identation in block\n"
1526:                        + "               1.\n" + "               2.\n" + "\n"
1527:                        + "            */\n" + "{\n" + "/*\n"
1528:                        + "  Preserve identation in block\n" + "    1.\n"
1529:                        + "    2.\n" + "\n" + "*/\n" + "    int i;\n" + "}\n"
1530:                        + "}\n");
1531:                reformat();
1532:                assertDocumentText("Incorrect identing in block comment",
1533:                        "extern \"C\"\n" + "{\n" + "    static void\n"
1534:                                + "    win_init(newp, oldp)\n"
1535:                                + "    win_T *newp;\n" + "    win_T *oldp;\n"
1536:                                + "    /*\n"
1537:                                + "      Preserve identation in block\n"
1538:                                + "        1.\n" + "        2.\n" + "\n"
1539:                                + "     */\n" + "    {\n" + "        /*\n"
1540:                                + "          Preserve identation in block\n"
1541:                                + "            1.\n" + "            2.\n"
1542:                                + "\n" + "         */\n" + "        int i;\n"
1543:                                + "    }\n" + "}\n");
1544:            }
1545:
1546:            public void testIdentInBlockComment2() {
1547:                setDefaultsOptions();
1548:                setLoadDocumentText("extern \"C\" {\n" + "static void\n"
1549:                        + "win_init(newp, oldp)\n" + "win_T *newp;\n"
1550:                        + "win_T *oldp;\n" + "      /*\n"
1551:                        + "           * Preserve identation in block\n"
1552:                        + "          *   1.\n" + "       *   2.\n" + "*\n"
1553:                        + "   */\n" + "{\n" + "  /*\n"
1554:                        + "* Preserve identation in block\n" + "    *   1.\n"
1555:                        + " *   2.\n" + "*\n" + "*/\n" + "    int i;\n" + "}\n"
1556:                        + "}\n");
1557:                reformat();
1558:                assertDocumentText("Incorrect identing in block comment",
1559:                        "extern \"C\"\n" + "{\n" + "    static void\n"
1560:                                + "    win_init(newp, oldp)\n"
1561:                                + "    win_T *newp;\n" + "    win_T *oldp;\n"
1562:                                + "    /*\n"
1563:                                + "     * Preserve identation in block\n"
1564:                                + "     *   1.\n" + "     *   2.\n"
1565:                                + "     *\n" + "     */\n" + "    {\n"
1566:                                + "        /*\n"
1567:                                + "         * Preserve identation in block\n"
1568:                                + "         *   1.\n" + "         *   2.\n"
1569:                                + "         *\n" + "         */\n"
1570:                                + "        int i;\n" + "    }\n" + "}\n");
1571:
1572:            }
1573:
1574:            public void testAddNewLineAfterSemocolon() {
1575:                setDefaultsOptions();
1576:                setLoadDocumentText("int foo(int i)\n" + "{\n"
1577:                        + "if(true) if(true) if(true) i--;\n"
1578:                        + "else i++;else i++; else i++;\n"
1579:                        + " if(true) while(i>0) i--;\n"
1580:                        + " if(true) return; else break;\n"
1581:                        + " if(true) return;\n" + " else {break;}\n" + "}\n");
1582:                reformat();
1583:                assertDocumentText("Incorrect adding new line after semocolon",
1584:                        "int foo(int i)\n" + "{\n"
1585:                                + "    if (true) if (true) if (true) i--;\n"
1586:                                + "            else i++;\n"
1587:                                + "        else i++;\n" + "    else i++;\n"
1588:                                + "    if (true) while (i > 0) i--;\n"
1589:                                + "    if (true) return;\n"
1590:                                + "    else break;\n"
1591:                                + "    if (true) return;\n" + "    else {\n"
1592:                                + "        break;\n" + "    }\n" + "}\n");
1593:            }
1594:
1595:            public void testIdentFunctionDefinition() {
1596:                setDefaultsOptions();
1597:                setLoadDocumentText("uchar *\n" + "        tokname(int n)\n"
1598:                        + "{\n" + "    static char buf[100];\n"
1599:                        + "    return printname[n - 257];\n" + "}\n");
1600:                reformat();
1601:                assertDocumentText("Incorrect identing function definition",
1602:                        "uchar *\n" + "tokname(int n)\n" + "{\n"
1603:                                + "    static char buf[100];\n"
1604:                                + "    return printname[n - 257];\n" + "}\n");
1605:            }
1606:
1607:            public void testIdentFunctionDefinition2() {
1608:                setDefaultsOptions();
1609:                setLoadDocumentText("namespace A\n" + "{\n" + "uchar *\n"
1610:                        + "        tokname(int n)\n" + "{\n"
1611:                        + "    static char buf[100];\n"
1612:                        + "    return printname[n - 257];\n" + "}\n" + "}\n");
1613:                reformat();
1614:                assertDocumentText("Incorrect identing function definition",
1615:                        "namespace A\n" + "{\n" + "    uchar *\n"
1616:                                + "    tokname(int n)\n" + "    {\n"
1617:                                + "        static char buf[100];\n"
1618:                                + "        return printname[n - 257];\n"
1619:                                + "    }\n" + "}\n");
1620:            }
1621:
1622:            public void testIdentElseAfterPreprocessor() {
1623:                setDefaultsOptions();
1624:                setLoadDocumentText("getcmdline(int firstc)\n" + "{\n"
1625:                        + "    if (firstc == '/')\n" + "    {\n"
1626:                        + "#ifdef USE_IM_CONTROL\n"
1627:                        + "	im_set_active(*b_im_ptr == B_IMODE_IM);\n"
1628:                        + "#endif\n" + "    }\n" + "#ifdef USE_IM_CONTROL\n"
1629:                        + "    else if (p_imcmdline)\n"
1630:                        + "	im_set_active(TRUE);\n" + "#endif\n" + "}\n");
1631:                reformat();
1632:                assertDocumentText(
1633:                        "Incorrect identing else after preprocessor",
1634:                        "getcmdline(int firstc)\n"
1635:                                + "{\n"
1636:                                + "    if (firstc == '/') {\n"
1637:                                + "#ifdef USE_IM_CONTROL\n"
1638:                                + "        im_set_active(*b_im_ptr == B_IMODE_IM);\n"
1639:                                + "#endif\n" + "    }\n"
1640:                                + "#ifdef USE_IM_CONTROL\n"
1641:                                + "    else if (p_imcmdline)\n"
1642:                                + "        im_set_active(TRUE);\n" + "#endif\n"
1643:                                + "}\n");
1644:            }
1645:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.