This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 131379
Collapse All | Expand All

(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatSupport.java (-5 / +5 lines)
Lines 504-517 public class CCFormatSupport extends Ext Link Here
504
     *  the given token.
504
     *  the given token.
505
     */
505
     */
506
    public TokenItem findStatementStart(TokenItem token) {
506
    public TokenItem findStatementStart(TokenItem token) {
507
        TokenItem t = findStatementStart(token, true);
507
        TokenItem t = findStatementStart(token, false);
508
        // preprocessor tokens are not important (bug#22570)
508
        // preprocessor tokens are not important (bug#22570)
509
        while (t != null && isPreprocessorLine(t)) {
509
        while (t != null && isPreprocessorLine(t)) {
510
            TokenItem current = t.getPrevious();
510
            TokenItem current = t.getPrevious();
511
            if (current == null) {
511
            if (current == null) {
512
                return null;
512
                return null;
513
            }
513
            }
514
            t = findStatementStart(current, true);
514
            t = findStatementStart(current, false);
515
        }
515
        }
516
        return t;
516
        return t;
517
    }
517
    }
Lines 968-974 public class CCFormatSupport extends Ext Link Here
968
                            }
968
                            }
969
                        }
969
                        }
970
                        if (indent < 0) {
970
                        if (indent < 0) {
971
                            indent = computeStatementIndent(token);
971
                            indent = computeStatementIndent(t);
972
                        }
972
                        }
973
                        break;
973
                        break;
974
974
Lines 977-983 public class CCFormatSupport extends Ext Link Here
977
                            indent = getTokenIndent(t);
977
                            indent = getTokenIndent(t);
978
                            break;
978
                            break;
979
                        }
979
                        }
980
                        indent = computeStatementIndent(token);
980
                        indent = computeStatementIndent(t);
981
                        break;
981
                        break;
982
                        
982
                        
983
                    case CCTokenContext.COMMA_ID:
983
                    case CCTokenContext.COMMA_ID:
Lines 988-994 public class CCFormatSupport extends Ext Link Here
988
                        indent = computeStatementIndent(t);
988
                        indent = computeStatementIndent(t);
989
                        break;
989
                        break;
990
                    default:
990
                    default:
991
                        indent = computeStatementIndent(token);
991
                        indent = computeStatementIndent(t);
992
                        break;
992
                        break;
993
                }
993
                }
994
994
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCFormatter.java (-1 / +1 lines)
Lines 121-127 public class CCFormatter extends ExtForm Link Here
121
            typedText.length() == 1 && Character.isLetter(typedText.charAt(0))) {
121
            typedText.length() == 1 && Character.isLetter(typedText.charAt(0))) {
122
            try {
122
            try {
123
                int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
123
                int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
124
                if (checkCase(doc, fnw, typedText+"\n")) { // NOI18N
124
                if (checkCase(doc, fnw, typedText+"\n") || dotPos == doc.getLength()) { // NOI18N
125
                    ret = new int[]{fnw, fnw + 1};
125
                    ret = new int[]{fnw, fnw + 1};
126
                }
126
                }
127
            } catch (BadLocationException e) {
127
            } catch (BadLocationException e) {
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/reformat/ReformatterImpl.java (-3 / +33 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.cnd.editor.reformat;
40
package org.netbeans.modules.cnd.editor.reformat;
41
41
42
import java.util.ArrayList;
42
import java.util.LinkedList;
43
import java.util.LinkedList;
43
import org.netbeans.api.lexer.Token;
44
import org.netbeans.api.lexer.Token;
44
import org.netbeans.api.lexer.TokenSequence;
45
import org.netbeans.api.lexer.TokenSequence;
Lines 1069-1093 public class ReformatterImpl { Link Here
1069
                    case LPAREN:
1070
                    case LPAREN:
1070
                        paren--;
1071
                        paren--;
1071
                        if (paren==0 && hasParen){
1072
                        if (paren==0 && hasParen){
1073
                            ArrayList<Integer> nlList = new ArrayList<Integer>();
1072
                            Token<CppTokenId> function = ts.lookPreviousImportant();
1074
                            Token<CppTokenId> function = ts.lookPreviousImportant();
1073
                            if (function != null && function.id()==IDENTIFIER) {
1075
                            if (function != null && function.id()==IDENTIFIER) {
1074
                                int startName = -1;
1076
                                int startName = -1;
1077
                                boolean isPrevID = false;
1075
                                while (ts.movePrevious()) {
1078
                                while (ts.movePrevious()) {
1076
                                    switch(ts.token().id()){
1079
                                    switch(ts.token().id()){
1077
                                        case COMMA:
1080
                                        case COMMA:
1078
                                        case COLON:
1081
                                        case COLON:
1079
                                            return;
1082
                                            return;
1083
                                        case NEW_LINE:
1084
                                            nlList.add(ts.index());
1085
                                            break;
1086
                                        case BLOCK_COMMENT:
1080
                                        case WHITESPACE:
1087
                                        case WHITESPACE:
1081
                                            break;
1088
                                            break;
1082
                                        case IDENTIFIER:
1083
                                        case SCOPE:
1084
                                        case TILDE:
1089
                                        case TILDE:
1085
                                            startName = ts.index();
1090
                                            startName = ts.index();
1091
                                            isPrevID = true;
1086
                                            break;
1092
                                            break;
1093
                                        case SCOPE:
1094
                                            startName = ts.index();
1095
                                            isPrevID = false;
1096
                                            break;
1097
                                        case IDENTIFIER:
1098
                                            if (!isPrevID) {
1099
                                                startName = ts.index();
1100
                                                isPrevID = true;
1101
                                                break;
1102
                                            }
1103
                                            // nobreak
1087
                                        default:
1104
                                        default:
1088
                                            ts.moveIndex(startName);
1105
                                            ts.moveIndex(startName);
1089
                                            ts.moveNext();
1106
                                            ts.moveNext();
1090
                                            newLineBefore(false);
1107
                                            newLineBefore(braces.getIndent());
1108
                                            for(int i = 0; i < nlList.size(); i++){
1109
                                                int nl = nlList.get(i);
1110
                                                if (startName < nl) {
1111
                                                    ts.moveIndex(nl);
1112
                                                    ts.moveNext();
1113
                                                    ts.moveNext();
1114
                                                    removeLineBefore(false);
1115
                                                }
1116
                                            }
1091
                                            return;
1117
                                            return;
1092
                                    }
1118
                                    }
1093
                                }
1119
                                }
Lines 1640-1645 public class ReformatterImpl { Link Here
1640
        } else {
1666
        } else {
1641
            spaces = getIndent();
1667
            spaces = getIndent();
1642
        }
1668
        }
1669
        newLineBefore(spaces);
1670
    }
1671
1672
    private void newLineBefore(int spaces) {
1643
        if (!ts.isFirstLineToken()) {
1673
        if (!ts.isFirstLineToken()) {
1644
            Token<CppTokenId> previous = ts.lookPrevious();
1674
            Token<CppTokenId> previous = ts.lookPrevious();
1645
            if (previous != null) {
1675
            if (previous != null) {
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCBracketCompletionUnitTestCase.java (-28 / +99 lines)
Lines 49-64 public class CCBracketCompletionUnitTest Link Here
49
    // ------- Tests for completion of right parenthesis ')' -------------
49
    // ------- Tests for completion of right parenthesis ')' -------------
50
    
50
    
51
    public void testRightParenSimpleMethodCall() {
51
    public void testRightParenSimpleMethodCall() {
52
        setDefaultsOptions();
52
        setLoadDocumentText("m()|)");
53
        setLoadDocumentText("m()|)");
53
        assertTrue(isSkipRightParen());
54
        assertTrue(isSkipRightParen());
54
    }
55
    }
55
    
56
    
56
    public void testRightParenSwingInvokeLaterRunnable() {
57
    public void testRightParenSwingInvokeLaterRunnable() {
58
        setDefaultsOptions();
57
        setLoadDocumentText("SwingUtilities.invokeLater(new Runnable()|))");
59
        setLoadDocumentText("SwingUtilities.invokeLater(new Runnable()|))");
58
        assertTrue(isSkipRightParen());
60
        assertTrue(isSkipRightParen());
59
    }
61
    }
60
62
61
    public void testRightParenSwingInvokeLaterRunnableRun() {
63
    public void testRightParenSwingInvokeLaterRunnableRun() {
64
        setDefaultsOptions();
62
        setLoadDocumentText(
65
        setLoadDocumentText(
63
            "SwingUtilities.invokeLater(new Runnable() {\n"
66
            "SwingUtilities.invokeLater(new Runnable() {\n"
64
          + "    public void run()|)\n"
67
          + "    public void run()|)\n"
Lines 69-74 public class CCBracketCompletionUnitTest Link Here
69
    }
72
    }
70
    
73
    
71
    public void testRightParenIfMethodCall() {
74
    public void testRightParenIfMethodCall() {
75
        setDefaultsOptions();
72
        setLoadDocumentText(
76
        setLoadDocumentText(
73
            " if (a()|) + 5 > 6) {\n"
77
            " if (a()|) + 5 > 6) {\n"
74
          + " }"
78
          + " }"
Lines 77-87 public class CCBracketCompletionUnitTest Link Here
77
    }
81
    }
78
82
79
    public void testRightParenNoSkipNonBracketChar() {
83
    public void testRightParenNoSkipNonBracketChar() {
84
        setDefaultsOptions();
80
        setLoadDocumentText("m()| ");
85
        setLoadDocumentText("m()| ");
81
        assertFalse(isSkipRightParen());
86
        assertFalse(isSkipRightParen());
82
    }
87
    }
83
88
84
    public void testRightParenNoSkipDocEnd() {
89
    public void testRightParenNoSkipDocEnd() {
90
        setDefaultsOptions();
85
        setLoadDocumentText("m()|");
91
        setLoadDocumentText("m()|");
86
        assertFalse(isSkipRightParen());
92
        assertFalse(isSkipRightParen());
87
    }
93
    }
Lines 90-115 public class CCBracketCompletionUnitTest Link Here
90
    // ------- Tests for completion of right brace '}' -------------
96
    // ------- Tests for completion of right brace '}' -------------
91
    
97
    
92
    public void testAddRightBraceIfLeftBrace() {
98
    public void testAddRightBraceIfLeftBrace() {
99
        setDefaultsOptions();
93
        setLoadDocumentText("if (true) {|");
100
        setLoadDocumentText("if (true) {|");
94
        assertTrue(isAddRightBrace());
101
        assertTrue(isAddRightBrace());
95
    }
102
    }
96
103
97
    public void testAddRightBraceIfLeftBraceWhiteSpace() {
104
    public void testAddRightBraceIfLeftBraceWhiteSpace() {
105
        setDefaultsOptions();
98
        setLoadDocumentText("if (true) { \t|\n");
106
        setLoadDocumentText("if (true) { \t|\n");
99
        assertTrue(isAddRightBrace());
107
        assertTrue(isAddRightBrace());
100
    }
108
    }
101
    
109
    
102
    public void testAddRightBraceIfLeftBraceLineComment() {
110
    public void testAddRightBraceIfLeftBraceLineComment() {
111
        setDefaultsOptions();
103
        setLoadDocumentText("if (true) { // line-comment|\n");
112
        setLoadDocumentText("if (true) { // line-comment|\n");
104
        assertTrue(isAddRightBrace());
113
        assertTrue(isAddRightBrace());
105
    }
114
    }
106
115
107
    public void testAddRightBraceIfLeftBraceBlockComment() {
116
    public void testAddRightBraceIfLeftBraceBlockComment() {
117
        setDefaultsOptions();
108
        setLoadDocumentText("if (true) { /* block-comment */|\n");
118
        setLoadDocumentText("if (true) { /* block-comment */|\n");
109
        assertTrue(isAddRightBrace());
119
        assertTrue(isAddRightBrace());
110
    }
120
    }
111
121
112
    public void testAddRightBraceIfLeftBraceAlreadyPresent() {
122
    public void testAddRightBraceIfLeftBraceAlreadyPresent() {
123
        setDefaultsOptions();
113
        setLoadDocumentText(
124
        setLoadDocumentText(
114
            "if (true) {|\n"
125
            "if (true) {|\n"
115
          + "}"
126
          + "}"
Lines 118-123 public class CCBracketCompletionUnitTest Link Here
118
    }
129
    }
119
130
120
    public void testAddRightBraceCaretInComment() {
131
    public void testAddRightBraceCaretInComment() {
132
        setDefaultsOptions();
121
        setLoadDocumentText(
133
        setLoadDocumentText(
122
            "if (true) { /* in-block-comment |\n"
134
            "if (true) { /* in-block-comment |\n"
123
        );
135
        );
Lines 125-130 public class CCBracketCompletionUnitTest Link Here
125
    }
137
    }
126
    
138
    
127
    public void testSimpleAdditionOfOpeningParenthesisAfterWhile () throws Exception {
139
    public void testSimpleAdditionOfOpeningParenthesisAfterWhile () throws Exception {
140
        setDefaultsOptions();
128
        setLoadDocumentText (
141
        setLoadDocumentText (
129
            "while |"
142
            "while |"
130
        );
143
        );
Lines 137-142 public class CCBracketCompletionUnitTest Link Here
137
    
150
    
138
    // ------- Tests for completion of quote (") -------------    
151
    // ------- Tests for completion of quote (") -------------    
139
    public void testSimpleQuoteInEmptyDoc () throws Exception {
152
    public void testSimpleQuoteInEmptyDoc () throws Exception {
153
        setDefaultsOptions();
140
        setLoadDocumentText (
154
        setLoadDocumentText (
141
            "|"
155
            "|"
142
        );
156
        );
Lines 147-152 public class CCBracketCompletionUnitTest Link Here
147
    }
161
    }
148
162
149
    public void testSimpleQuoteAtBeginingOfDoc () throws Exception {
163
    public void testSimpleQuoteAtBeginingOfDoc () throws Exception {
164
        setDefaultsOptions();
150
        setLoadDocumentText (
165
        setLoadDocumentText (
151
            "|  "
166
            "|  "
152
        );
167
        );
Lines 157-162 public class CCBracketCompletionUnitTest Link Here
157
    }
172
    }
158
173
159
    public void testSimpleQuoteAtEndOfDoc () throws Exception {
174
    public void testSimpleQuoteAtEndOfDoc () throws Exception {
175
        setDefaultsOptions();
160
        setLoadDocumentText (
176
        setLoadDocumentText (
161
            "  |"
177
            "  |"
162
        );
178
        );
Lines 167-172 public class CCBracketCompletionUnitTest Link Here
167
    }
183
    }
168
    
184
    
169
    public void testSimpleQuoteInWhiteSpaceArea () throws Exception {
185
    public void testSimpleQuoteInWhiteSpaceArea () throws Exception {
186
        setDefaultsOptions();
170
        setLoadDocumentText (
187
        setLoadDocumentText (
171
            "  |  "
188
            "  |  "
172
        );
189
        );
Lines 177-182 public class CCBracketCompletionUnitTest Link Here
177
    }
194
    }
178
    
195
    
179
    public void testQuoteAtEOL () throws Exception {
196
    public void testQuoteAtEOL () throws Exception {
197
        setDefaultsOptions();
180
        setLoadDocumentText (
198
        setLoadDocumentText (
181
            "  |\n"
199
            "  |\n"
182
        );
200
        );
Lines 187-192 public class CCBracketCompletionUnitTest Link Here
187
    }
205
    }
188
    
206
    
189
    public void testQuoteWithUnterminatedStringLiteral () throws Exception {
207
    public void testQuoteWithUnterminatedStringLiteral () throws Exception {
208
        setDefaultsOptions();
190
        setLoadDocumentText (
209
        setLoadDocumentText (
191
            "  \"unterminated string| \n"
210
            "  \"unterminated string| \n"
192
        );
211
        );
Lines 197-202 public class CCBracketCompletionUnitTest Link Here
197
    }
216
    }
198
    
217
    
199
    public void testQuoteAtEOLWithUnterminatedStringLiteral () throws Exception {
218
    public void testQuoteAtEOLWithUnterminatedStringLiteral () throws Exception {
219
        setDefaultsOptions();
200
        setLoadDocumentText (
220
        setLoadDocumentText (
201
            "  \"unterminated string |\n"
221
            "  \"unterminated string |\n"
202
        );
222
        );
Lines 207-212 public class CCBracketCompletionUnitTest Link Here
207
    }
227
    }
208
228
209
    public void testQuoteInsideStringLiteral () throws Exception {
229
    public void testQuoteInsideStringLiteral () throws Exception {
230
        setDefaultsOptions();
210
        setLoadDocumentText (
231
        setLoadDocumentText (
211
            "  \"stri|ng literal\" "
232
            "  \"stri|ng literal\" "
212
        );
233
        );
Lines 217-222 public class CCBracketCompletionUnitTest Link Here
217
    }
238
    }
218
239
219
    public void testQuoteInsideEmptyParentheses () throws Exception {
240
    public void testQuoteInsideEmptyParentheses () throws Exception {
241
        setDefaultsOptions();
220
        setLoadDocumentText (
242
        setLoadDocumentText (
221
            " printf(|) "
243
            " printf(|) "
222
        );
244
        );
Lines 227-232 public class CCBracketCompletionUnitTest Link Here
227
    }
249
    }
228
250
229
    public void testQuoteInsideNonEmptyParentheses () throws Exception {
251
    public void testQuoteInsideNonEmptyParentheses () throws Exception {
252
        setDefaultsOptions();
230
        setLoadDocumentText (
253
        setLoadDocumentText (
231
            " printf(|some text) "
254
            " printf(|some text) "
232
        );
255
        );
Lines 237-242 public class CCBracketCompletionUnitTest Link Here
237
    }
260
    }
238
    
261
    
239
    public void testQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception {
262
    public void testQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception {
263
        setDefaultsOptions();
240
        setLoadDocumentText (
264
        setLoadDocumentText (
241
            " printf(i+|) "
265
            " printf(i+|) "
242
        );
266
        );
Lines 247-252 public class CCBracketCompletionUnitTest Link Here
247
    }
271
    }
248
    
272
    
249
    public void testQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedStringLiteral () throws Exception {
273
    public void testQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedStringLiteral () throws Exception {
274
        setDefaultsOptions();
250
        setLoadDocumentText (
275
        setLoadDocumentText (
251
            " printf(\"unterminated string literal |); "
276
            " printf(\"unterminated string literal |); "
252
        );
277
        );
Lines 257-262 public class CCBracketCompletionUnitTest Link Here
257
    }
282
    }
258
283
259
    public void testQuoteBeforePlus () throws Exception {
284
    public void testQuoteBeforePlus () throws Exception {
285
        setDefaultsOptions();
260
        setLoadDocumentText (
286
        setLoadDocumentText (
261
            " printf(|+\"string literal\"); "
287
            " printf(|+\"string literal\"); "
262
        );
288
        );
Lines 267-272 public class CCBracketCompletionUnitTest Link Here
267
    }
293
    }
268
294
269
    public void testQuoteBeforeComma () throws Exception {
295
    public void testQuoteBeforeComma () throws Exception {
296
        setDefaultsOptions();
270
        setLoadDocumentText (
297
        setLoadDocumentText (
271
            "String s[] = new String[]{|,\"two\"};"
298
            "String s[] = new String[]{|,\"two\"};"
272
        );
299
        );
Lines 277-282 public class CCBracketCompletionUnitTest Link Here
277
    }
304
    }
278
305
279
    public void testQuoteBeforeBrace () throws Exception {
306
    public void testQuoteBeforeBrace () throws Exception {
307
        setDefaultsOptions();
280
        setLoadDocumentText (
308
        setLoadDocumentText (
281
            "String s[] = new String[]{\"one\",|};"
309
            "String s[] = new String[]{\"one\",|};"
282
        );
310
        );
Lines 287-292 public class CCBracketCompletionUnitTest Link Here
287
    }
315
    }
288
316
289
    public void testQuoteBeforeSemicolon() throws Exception {
317
    public void testQuoteBeforeSemicolon() throws Exception {
318
        setDefaultsOptions();
290
        setLoadDocumentText (
319
        setLoadDocumentText (
291
            "String s = \"\" + |;"
320
            "String s = \"\" + |;"
292
        );
321
        );
Lines 297-302 public class CCBracketCompletionUnitTest Link Here
297
    }
326
    }
298
327
299
    public void testQuoteBeforeSemicolonWithWhitespace() throws Exception {
328
    public void testQuoteBeforeSemicolonWithWhitespace() throws Exception {
329
        setDefaultsOptions();
300
        setLoadDocumentText (
330
        setLoadDocumentText (
301
            "String s = \"\" +| ;"
331
            "String s = \"\" +| ;"
302
        );
332
        );
Lines 307-312 public class CCBracketCompletionUnitTest Link Here
307
    }
337
    }
308
338
309
    public void testQuoteAfterEscapeSequence() throws Exception {
339
    public void testQuoteAfterEscapeSequence() throws Exception {
340
        setDefaultsOptions();
310
        setLoadDocumentText (
341
        setLoadDocumentText (
311
            "\\|"
342
            "\\|"
312
        );
343
        );
Lines 318-323 public class CCBracketCompletionUnitTest Link Here
318
    
349
    
319
    /** issue #69524 */
350
    /** issue #69524 */
320
    public void testQuoteEaten() throws Exception {
351
    public void testQuoteEaten() throws Exception {
352
        setDefaultsOptions();
321
        setLoadDocumentText (
353
        setLoadDocumentText (
322
            "|"
354
            "|"
323
        );
355
        );
Lines 330-335 public class CCBracketCompletionUnitTest Link Here
330
362
331
    /** issue #69935 */
363
    /** issue #69935 */
332
    public void testQuoteInsideComments() throws Exception {
364
    public void testQuoteInsideComments() throws Exception {
365
        setDefaultsOptions();
333
        setLoadDocumentText (
366
        setLoadDocumentText (
334
            "/** |\n */"
367
            "/** |\n */"
335
        );
368
        );
Lines 341-346 public class CCBracketCompletionUnitTest Link Here
341
    
374
    
342
    /** issue #71880 */
375
    /** issue #71880 */
343
    public void testQuoteAtTheEndOfLineCommentLine() throws Exception {
376
    public void testQuoteAtTheEndOfLineCommentLine() throws Exception {
377
        setDefaultsOptions();
344
        setLoadDocumentText (
378
        setLoadDocumentText (
345
            "// test line comment |\n"
379
            "// test line comment |\n"
346
        );
380
        );
Lines 354-359 public class CCBracketCompletionUnitTest Link Here
354
    // ------- Tests for completion of single quote (') -------------        
388
    // ------- Tests for completion of single quote (') -------------        
355
    
389
    
356
    public void testSingleQuoteInEmptyDoc () throws Exception {
390
    public void testSingleQuoteInEmptyDoc () throws Exception {
391
        setDefaultsOptions();
357
        setLoadDocumentText (
392
        setLoadDocumentText (
358
            "|"
393
            "|"
359
        );
394
        );
Lines 364-369 public class CCBracketCompletionUnitTest Link Here
364
    }
399
    }
365
400
366
    public void testSingleQuoteAtBeginingOfDoc () throws Exception {
401
    public void testSingleQuoteAtBeginingOfDoc () throws Exception {
402
        setDefaultsOptions();
367
        setLoadDocumentText (
403
        setLoadDocumentText (
368
            "|  "
404
            "|  "
369
        );
405
        );
Lines 374-379 public class CCBracketCompletionUnitTest Link Here
374
    }
410
    }
375
411
376
    public void testSingleQuoteAtEndOfDoc () throws Exception {
412
    public void testSingleQuoteAtEndOfDoc () throws Exception {
413
        setDefaultsOptions();
377
        setLoadDocumentText (
414
        setLoadDocumentText (
378
            "  |"
415
            "  |"
379
        );
416
        );
Lines 384-389 public class CCBracketCompletionUnitTest Link Here
384
    }
421
    }
385
    
422
    
386
    public void testSingleQuoteInWhiteSpaceArea () throws Exception {
423
    public void testSingleQuoteInWhiteSpaceArea () throws Exception {
424
        setDefaultsOptions();
387
        setLoadDocumentText (
425
        setLoadDocumentText (
388
            "  |  "
426
            "  |  "
389
        );
427
        );
Lines 394-399 public class CCBracketCompletionUnitTest Link Here
394
    }
432
    }
395
    
433
    
396
    public void testSingleQuoteAtEOL () throws Exception {
434
    public void testSingleQuoteAtEOL () throws Exception {
435
        setDefaultsOptions();
397
        setLoadDocumentText (
436
        setLoadDocumentText (
398
            "  |\n"
437
            "  |\n"
399
        );
438
        );
Lines 404-409 public class CCBracketCompletionUnitTest Link Here
404
    }
443
    }
405
    
444
    
406
    public void testSingleQuoteWithUnterminatedCharLiteral () throws Exception {
445
    public void testSingleQuoteWithUnterminatedCharLiteral () throws Exception {
446
        setDefaultsOptions();
407
        setLoadDocumentText (
447
        setLoadDocumentText (
408
            "  '| \n"
448
            "  '| \n"
409
        );
449
        );
Lines 414-419 public class CCBracketCompletionUnitTest Link Here
414
    }
454
    }
415
    
455
    
416
    public void testSingleQuoteAtEOLWithUnterminatedCharLiteral () throws Exception {
456
    public void testSingleQuoteAtEOLWithUnterminatedCharLiteral () throws Exception {
457
        setDefaultsOptions();
417
        setLoadDocumentText (
458
        setLoadDocumentText (
418
            "  ' |\n"
459
            "  ' |\n"
419
        );
460
        );
Lines 424-429 public class CCBracketCompletionUnitTest Link Here
424
    }
465
    }
425
466
426
    public void testSingleQuoteInsideCharLiteral () throws Exception {
467
    public void testSingleQuoteInsideCharLiteral () throws Exception {
468
        setDefaultsOptions();
427
        setLoadDocumentText (
469
        setLoadDocumentText (
428
            "  '| ' "
470
            "  '| ' "
429
        );
471
        );
Lines 434-439 public class CCBracketCompletionUnitTest Link Here
434
    }
476
    }
435
477
436
    public void testSingleQuoteInsideEmptyParentheses () throws Exception {
478
    public void testSingleQuoteInsideEmptyParentheses () throws Exception {
479
        setDefaultsOptions();
437
        setLoadDocumentText (
480
        setLoadDocumentText (
438
            " printf(|) "
481
            " printf(|) "
439
        );
482
        );
Lines 444-449 public class CCBracketCompletionUnitTest Link Here
444
    }
487
    }
445
488
446
    public void testSingleQuoteInsideNonEmptyParentheses () throws Exception {
489
    public void testSingleQuoteInsideNonEmptyParentheses () throws Exception {
490
        setDefaultsOptions();
447
        setLoadDocumentText (
491
        setLoadDocumentText (
448
            " printf(|some text) "
492
            " printf(|some text) "
449
        );
493
        );
Lines 454-459 public class CCBracketCompletionUnitTest Link Here
454
    }
498
    }
455
    
499
    
456
    public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception {
500
    public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParentheses () throws Exception {
501
        setDefaultsOptions();
457
        setLoadDocumentText (
502
        setLoadDocumentText (
458
            " printf(i+|) "
503
            " printf(i+|) "
459
        );
504
        );
Lines 464-469 public class CCBracketCompletionUnitTest Link Here
464
    }
509
    }
465
    
510
    
466
    public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedCharLiteral () throws Exception {
511
    public void testSingleQuoteInsideNonEmptyParenthesesBeforeClosingParenthesesAndUnterminatedCharLiteral () throws Exception {
512
        setDefaultsOptions();
467
        setLoadDocumentText (
513
        setLoadDocumentText (
468
            " printf(' |); "
514
            " printf(' |); "
469
        );
515
        );
Lines 474-479 public class CCBracketCompletionUnitTest Link Here
474
    }
520
    }
475
521
476
    public void testSingleQuoteBeforePlus () throws Exception {
522
    public void testSingleQuoteBeforePlus () throws Exception {
523
        setDefaultsOptions();
477
        setLoadDocumentText (
524
        setLoadDocumentText (
478
            " printf(|+\"string literal\"); "
525
            " printf(|+\"string literal\"); "
479
        );
526
        );
Lines 484-489 public class CCBracketCompletionUnitTest Link Here
484
    }
531
    }
485
532
486
    public void testSingleQuoteBeforeComma () throws Exception {
533
    public void testSingleQuoteBeforeComma () throws Exception {
534
        setDefaultsOptions();
487
        setLoadDocumentText (
535
        setLoadDocumentText (
488
            "String s[] = new String[]{|,\"two\"};"
536
            "String s[] = new String[]{|,\"two\"};"
489
        );
537
        );
Lines 494-499 public class CCBracketCompletionUnitTest Link Here
494
    }
542
    }
495
543
496
    public void testSingleQuoteBeforeBrace () throws Exception {
544
    public void testSingleQuoteBeforeBrace () throws Exception {
545
        setDefaultsOptions();
497
        setLoadDocumentText (
546
        setLoadDocumentText (
498
            "String s[] = new String[]{\"one\",|};"
547
            "String s[] = new String[]{\"one\",|};"
499
        );
548
        );
Lines 504-509 public class CCBracketCompletionUnitTest Link Here
504
    }
553
    }
505
554
506
    public void testSingleQuoteBeforeSemicolon() throws Exception {
555
    public void testSingleQuoteBeforeSemicolon() throws Exception {
556
        setDefaultsOptions();
507
        setLoadDocumentText (
557
        setLoadDocumentText (
508
            "String s = \"\" + |;"
558
            "String s = \"\" + |;"
509
        );
559
        );
Lines 514-519 public class CCBracketCompletionUnitTest Link Here
514
    }
564
    }
515
565
516
    public void testsingleQuoteBeforeSemicolonWithWhitespace() throws Exception {
566
    public void testsingleQuoteBeforeSemicolonWithWhitespace() throws Exception {
567
        setDefaultsOptions();
517
        setLoadDocumentText (
568
        setLoadDocumentText (
518
            "String s = \"\" +| ;"
569
            "String s = \"\" +| ;"
519
        );
570
        );
Lines 524-529 public class CCBracketCompletionUnitTest Link Here
524
    }
575
    }
525
576
526
    public void testSingleQuoteAfterEscapeSequence() throws Exception {
577
    public void testSingleQuoteAfterEscapeSequence() throws Exception {
578
        setDefaultsOptions();
527
        setLoadDocumentText (
579
        setLoadDocumentText (
528
            "\\|"
580
            "\\|"
529
        );
581
        );
Lines 535-540 public class CCBracketCompletionUnitTest Link Here
535
    
587
    
536
    /** issue #69524 */
588
    /** issue #69524 */
537
    public void testSingleQuoteEaten() throws Exception {
589
    public void testSingleQuoteEaten() throws Exception {
590
        setDefaultsOptions();
538
        setLoadDocumentText (
591
        setLoadDocumentText (
539
            "|"
592
            "|"
540
        );
593
        );
Lines 547-552 public class CCBracketCompletionUnitTest Link Here
547
    
600
    
548
    /** issue #69935 */
601
    /** issue #69935 */
549
    public void testSingleQuoteInsideComments() throws Exception {
602
    public void testSingleQuoteInsideComments() throws Exception {
603
        setDefaultsOptions();
550
        setLoadDocumentText (
604
        setLoadDocumentText (
551
            "/* |\n */"
605
            "/* |\n */"
552
        );
606
        );
Lines 558-563 public class CCBracketCompletionUnitTest Link Here
558
612
559
    /** issue #71880 */
613
    /** issue #71880 */
560
    public void testSingleQuoteAtTheEndOfLineCommentLine() throws Exception {
614
    public void testSingleQuoteAtTheEndOfLineCommentLine() throws Exception {
615
        setDefaultsOptions();
561
        setLoadDocumentText (
616
        setLoadDocumentText (
562
            "// test line comment |\n"
617
            "// test line comment |\n"
563
        );
618
        );
Lines 568-573 public class CCBracketCompletionUnitTest Link Here
568
    }    
623
    }    
569
624
570
    public void testSystemInclude() throws Exception {
625
    public void testSystemInclude() throws Exception {
626
        setDefaultsOptions();
571
        setLoadDocumentText (
627
        setLoadDocumentText (
572
            "#include |\n"
628
            "#include |\n"
573
        );
629
        );
Lines 578-583 public class CCBracketCompletionUnitTest Link Here
578
    }
634
    }
579
635
580
    public void testUserInclude() throws Exception {
636
    public void testUserInclude() throws Exception {
637
        setDefaultsOptions();
581
        setLoadDocumentText (
638
        setLoadDocumentText (
582
            "#include |\n"
639
            "#include |\n"
583
        );
640
        );
Lines 588-593 public class CCBracketCompletionUnitTest Link Here
588
    }
645
    }
589
646
590
    public void testArray() throws Exception {
647
    public void testArray() throws Exception {
648
        setDefaultsOptions();
591
        setLoadDocumentText (
649
        setLoadDocumentText (
592
            "int a|\n"
650
            "int a|\n"
593
        );
651
        );
Lines 598-603 public class CCBracketCompletionUnitTest Link Here
598
    }
656
    }
599
    
657
    
600
    public void testRightBracePreprocessor() {
658
    public void testRightBracePreprocessor() {
659
        setDefaultsOptions();
601
        setLoadDocumentText(
660
        setLoadDocumentText(
602
            "void foo(){\n" +
661
            "void foo(){\n" +
603
            "#if A\n" +
662
            "#if A\n" +
Lines 612-617 public class CCBracketCompletionUnitTest Link Here
612
    }
671
    }
613
672
614
    public void testRightBracePreprocessor2() {
673
    public void testRightBracePreprocessor2() {
674
        setDefaultsOptions();
615
        setLoadDocumentText(
675
        setLoadDocumentText(
616
            "void foo(){\n" +
676
            "void foo(){\n" +
617
            "#if A\n" +
677
            "#if A\n" +
Lines 626-631 public class CCBracketCompletionUnitTest Link Here
626
    }
686
    }
627
687
628
    public void testRightBracePreprocessor3() {
688
    public void testRightBracePreprocessor3() {
689
        setDefaultsOptions();
629
        setLoadDocumentText(
690
        setLoadDocumentText(
630
            "void foo(){\n" +
691
            "void foo(){\n" +
631
            "#if A\n" +
692
            "#if A\n" +
Lines 640-645 public class CCBracketCompletionUnitTest Link Here
640
    }
701
    }
641
702
642
    public void testRightBracePreprocessor4() {
703
    public void testRightBracePreprocessor4() {
704
        setDefaultsOptions();
643
        setLoadDocumentText(
705
        setLoadDocumentText(
644
            "void foo(){\n" +
706
            "void foo(){\n" +
645
            "#if A\n" +
707
            "#if A\n" +
Lines 655-660 public class CCBracketCompletionUnitTest Link Here
655
    }
717
    }
656
718
657
    public void testRightBracePreprocessor5() {
719
    public void testRightBracePreprocessor5() {
720
        setDefaultsOptions();
658
        setLoadDocumentText(
721
        setLoadDocumentText(
659
            "void foo(){\n" +
722
            "void foo(){\n" +
660
            "#define PAREN {\n" +
723
            "#define PAREN {\n" +
Lines 666-705 public class CCBracketCompletionUnitTest Link Here
666
    }
729
    }
667
    
730
    
668
    public void testIZ102091() throws Exception {
731
    public void testIZ102091() throws Exception {
732
        setDefaultsOptions();
669
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
733
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
670
                put(EditorOptions.newLineBeforeBrace, 
734
                put(EditorOptions.newLineBeforeBrace, 
671
                CodeStyle.BracePlacement.NEW_LINE.name());
735
                CodeStyle.BracePlacement.NEW_LINE.name());
672
        try {
736
        setLoadDocumentText (
673
            setLoadDocumentText (
737
            "if(i)\n"+
674
                "if(i)\n"+
738
            "    |"
675
                "    |"
739
        );
676
            );
740
        typeChar('{', true);
677
            typeChar('{', true);
741
        assertDocumentTextAndCaret ("IZ102091\n", 
678
            assertDocumentTextAndCaret ("IZ102091\n", 
742
            "if(i)\n"+
679
                "if(i)\n"+
743
            "{|"
680
                "{|"
744
        );
681
            );
682
        } finally {
683
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
684
                    put(EditorOptions.newLineBeforeBrace, 
685
                    CodeStyle.BracePlacement.SAME_LINE.name());
686
        }
687
    }
745
    }
688
    
746
    
689
//    public void testColonAfterPublic() throws Exception {
747
    public void testColonAfterPublic() throws Exception {
690
//        setLoadDocumentText (
748
        setDefaultsOptions();
691
//            "class A{\n" +
749
        setLoadDocumentText (
692
//            "    public|\n" +
750
            "class A{\n" +
693
//            "}\n"
751
            "    public|\n" +
694
//        );
752
            "}\n"
695
//        typeChar(':');
753
        );
696
//        assertDocumentTextAndCaret ("Colon After Public", 
754
        typeChar(':', true);
697
//            "class A{\n" +
755
        assertDocumentText("Colon After Public", 
698
//            "public:|\n" +
756
            "class A{\n" +
699
//            "}\n"
757
            "public:\n" +
700
//        );
758
            "}\n"
701
//    }
759
        );
760
    }
702
    
761
    
762
    public void testIdentFunctionName()  throws Exception {
763
        setDefaultsOptions("GNU");
764
        setLoadDocumentText(
765
            "tree\n" +
766
            "        |"
767
            );
768
        typeChar('d',true);
769
        assertDocumentTextAndCaret("Incorrect identing of main",
770
            "tree\n" +
771
            "d|"
772
            );
773
    }
703
774
704
    // ------- Private methods -------------
775
    // ------- Private methods -------------
705
    
776
    
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCase.java (-78 / +153 lines)
Lines 47-52 public class CCIndentUnitTestCase extend Link Here
47
    // indent new line tests
47
    // indent new line tests
48
    
48
    
49
    public void testJavadocEnterNothingAfterCaret() {
49
    public void testJavadocEnterNothingAfterCaret() {
50
        setDefaultsOptions();
50
        setLoadDocumentText(
51
        setLoadDocumentText(
51
                "/**\n"
52
                "/**\n"
52
                + " * text|\n"
53
                + " * text|\n"
Lines 63-68 public class CCIndentUnitTestCase extend Link Here
63
    }
64
    }
64
    
65
    
65
    public void testJavadocEnterTextAfterCaret() {
66
    public void testJavadocEnterTextAfterCaret() {
67
        setDefaultsOptions();
66
        setLoadDocumentText(
68
        setLoadDocumentText(
67
                "/**\n"
69
                "/**\n"
68
                + " * break|text\n"
70
                + " * break|text\n"
Lines 79-84 public class CCIndentUnitTestCase extend Link Here
79
    }
81
    }
80
    
82
    
81
    public void testJavadocEnterStarAfterCaret() {
83
    public void testJavadocEnterStarAfterCaret() {
84
        setDefaultsOptions();
82
        setLoadDocumentText(
85
        setLoadDocumentText(
83
                "/**\n"
86
                "/**\n"
84
                + " * text|*/\n"
87
                + " * text|*/\n"
Lines 93-98 public class CCIndentUnitTestCase extend Link Here
93
    }
96
    }
94
    
97
    
95
    public void testEnterInMultiLineSystemOutPrintln() {
98
    public void testEnterInMultiLineSystemOutPrintln() {
99
        setDefaultsOptions();
96
        setLoadDocumentText(
100
        setLoadDocumentText(
97
                "void m() {\n"
101
                "void m() {\n"
98
                + "    printf(|\n"
102
                + "    printf(|\n"
Lines 109-114 public class CCIndentUnitTestCase extend Link Here
109
    }
113
    }
110
    
114
    
111
    public void testEnterInMultiLineSystemOutPrintlnLineThree() {
115
    public void testEnterInMultiLineSystemOutPrintlnLineThree() {
116
        setDefaultsOptions();
112
        setLoadDocumentText(
117
        setLoadDocumentText(
113
                "void m() {\n"
118
                "void m() {\n"
114
                + "    printf(\n"
119
                + "    printf(\n"
Lines 127-132 public class CCIndentUnitTestCase extend Link Here
127
    }
132
    }
128
    
133
    
129
    public void testEnterInMultiLineSystemOutPrintlnAfterSemiColon() {
134
    public void testEnterInMultiLineSystemOutPrintlnAfterSemiColon() {
135
        setDefaultsOptions();
130
        setLoadDocumentText(
136
        setLoadDocumentText(
131
                "void m() {\n"
137
                "void m() {\n"
132
                + "    printf(\n"
138
                + "    printf(\n"
Lines 161-166 public class CCIndentUnitTestCase extend Link Here
161
//    }
167
//    }
162
    
168
    
163
    public void testEnterAfterIf() {
169
    public void testEnterAfterIf() {
170
        setDefaultsOptions();
164
        setLoadDocumentText(
171
        setLoadDocumentText(
165
                "if (true)|\n"
172
                "if (true)|\n"
166
                );
173
                );
Lines 172-181 public class CCIndentUnitTestCase extend Link Here
172
    }
179
    }
173
180
174
    public void testEnterAfterIfHalf() {
181
    public void testEnterAfterIfHalf() {
182
        setDefaultsOptions();
175
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
183
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
176
                put(EditorOptions.newLineBeforeBrace, 
184
                put(EditorOptions.newLineBeforeBrace, 
177
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
185
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
178
        try {
179
        setLoadDocumentText(
186
        setLoadDocumentText(
180
                "if (true)|\n"
187
                "if (true)|\n"
181
                );
188
                );
Lines 184-199 public class CCIndentUnitTestCase extend Link Here
184
                "if (true)\n"
191
                "if (true)\n"
185
                + "  |\n"
192
                + "  |\n"
186
                );
193
                );
187
        } finally{
188
            setDefaultsOptions();
189
        }
190
    }
194
    }
191
195
192
    public void testEnterAfterIfBraceHalf() {
196
    public void testEnterAfterIfBraceHalf() {
197
        setDefaultsOptions();
193
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
198
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
194
                put(EditorOptions.newLineBeforeBrace, 
199
                put(EditorOptions.newLineBeforeBrace, 
195
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
200
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
196
        try {
197
        setLoadDocumentText(
201
        setLoadDocumentText(
198
                "if (true)\n" +
202
                "if (true)\n" +
199
                "  {|\n" +
203
                "  {|\n" +
Lines 206-224 public class CCIndentUnitTestCase extend Link Here
206
                "    |\n" +
210
                "    |\n" +
207
                "  }\n" 
211
                "  }\n" 
208
                );
212
                );
209
        } finally{
210
            setDefaultsOptions();
211
        }
212
    }
213
    }
213
214
214
    public void testEnterAfterIfBraceHalf2() {
215
    public void testEnterAfterIfBraceHalf2() {
216
        setDefaultsOptions();
215
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
217
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
216
                put(EditorOptions.newLineBeforeBraceDeclaration, 
218
                put(EditorOptions.newLineBeforeBraceDeclaration, 
217
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
219
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
218
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
220
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
219
                put(EditorOptions.newLineBeforeBrace, 
221
                put(EditorOptions.newLineBeforeBrace, 
220
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
222
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
221
        try {
222
        setLoadDocumentText(
223
        setLoadDocumentText(
223
                "int foo()\n" +
224
                "int foo()\n" +
224
                "{\n" +
225
                "{\n" +
Lines 237-248 public class CCIndentUnitTestCase extend Link Here
237
                "    }\n" +
238
                "    }\n" +
238
                "}\n"
239
                "}\n"
239
                );
240
                );
240
        } finally{
241
            setDefaultsOptions();
242
        }
243
    }
241
    }
244
    
242
    
245
    public void testEnterAfterFor() {
243
    public void testEnterAfterFor() {
244
        setDefaultsOptions();
246
        setLoadDocumentText(
245
        setLoadDocumentText(
247
                "for (int i = 0; i < 10; i++)|\n"
246
                "for (int i = 0; i < 10; i++)|\n"
248
                );
247
                );
Lines 254-263 public class CCIndentUnitTestCase extend Link Here
254
    }
253
    }
255
254
256
    public void testEnterAfterForHalf() {
255
    public void testEnterAfterForHalf() {
256
        setDefaultsOptions();
257
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
257
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
258
                put(EditorOptions.newLineBeforeBrace, 
258
                put(EditorOptions.newLineBeforeBrace, 
259
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
259
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
260
        try {
261
        setLoadDocumentText(
260
        setLoadDocumentText(
262
                "for (int i = 0; i < 10; i++)|\n"
261
                "for (int i = 0; i < 10; i++)|\n"
263
                );
262
                );
Lines 266-277 public class CCIndentUnitTestCase extend Link Here
266
                "for (int i = 0; i < 10; i++)\n"
265
                "for (int i = 0; i < 10; i++)\n"
267
                + "  |\n"
266
                + "  |\n"
268
                );
267
                );
269
        } finally{
270
            setDefaultsOptions();
271
        }
272
    }
268
    }
273
    
269
    
274
    public void testEnterAfterWhile() {
270
    public void testEnterAfterWhile() {
271
        setDefaultsOptions();
275
        setLoadDocumentText(
272
        setLoadDocumentText(
276
                "while (true)|\n"
273
                "while (true)|\n"
277
                );
274
                );
Lines 283-292 public class CCIndentUnitTestCase extend Link Here
283
    }
280
    }
284
281
285
    public void testEnterAfterWhileHalf() {
282
    public void testEnterAfterWhileHalf() {
283
        setDefaultsOptions();
286
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
284
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
287
                put(EditorOptions.newLineBeforeBrace, 
285
                put(EditorOptions.newLineBeforeBrace, 
288
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
286
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
289
        try {
290
        setLoadDocumentText(
287
        setLoadDocumentText(
291
                "while (true)|\n"
288
                "while (true)|\n"
292
                );
289
                );
Lines 295-306 public class CCIndentUnitTestCase extend Link Here
295
                "while (true)\n" +
292
                "while (true)\n" +
296
                "  |\n"
293
                "  |\n"
297
                );
294
                );
298
        } finally{
299
            setDefaultsOptions();
300
        }
301
    }
295
    }
302
296
303
    public void testEnterAfterDo() {
297
    public void testEnterAfterDo() {
298
        setDefaultsOptions();
304
        setLoadDocumentText(
299
        setLoadDocumentText(
305
                "do|\n"
300
                "do|\n"
306
                );
301
                );
Lines 312-335 public class CCIndentUnitTestCase extend Link Here
312
    }
307
    }
313
    
308
    
314
    public void testEnterAfterDoHalf() {
309
    public void testEnterAfterDoHalf() {
310
        setDefaultsOptions();
315
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
311
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
316
                put(EditorOptions.newLineBeforeBrace, 
312
                put(EditorOptions.newLineBeforeBrace, 
317
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
313
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
318
        try {
314
        setLoadDocumentText(
319
            setLoadDocumentText(
315
                "do|\n"
320
                    "do|\n"
316
                );
321
                    );
317
        indentNewLine();
322
            indentNewLine();
318
        assertDocumentTextAndCaret("Incorrect new-line indent",
323
            assertDocumentTextAndCaret("Incorrect new-line indent",
319
                "do\n" +
324
                    "do\n" +
320
                "  |\n"
325
                    "  |\n"
321
                );
326
                    );
327
        } finally{
328
            setDefaultsOptions();
329
        }
330
    }
322
    }
331
323
332
    public void testEnterAfterIfStmt() {
324
    public void testEnterAfterIfStmt() {
325
        setDefaultsOptions();
333
        setLoadDocumentText(
326
        setLoadDocumentText(
334
                "if (true)\n"
327
                "if (true)\n"
335
                + "    stmt;|\n"
328
                + "    stmt;|\n"
Lines 343-352 public class CCIndentUnitTestCase extend Link Here
343
    }
336
    }
344
    
337
    
345
    public void testEnterAfterIfStmtHalf() {
338
    public void testEnterAfterIfStmtHalf() {
339
        setDefaultsOptions();
346
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
340
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
347
                put(EditorOptions.newLineBeforeBrace, 
341
                put(EditorOptions.newLineBeforeBrace, 
348
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
342
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
349
        try {
350
        setLoadDocumentText(
343
        setLoadDocumentText(
351
                "if (true)\n"
344
                "if (true)\n"
352
                + "  stmt;|\n"
345
                + "  stmt;|\n"
Lines 357-368 public class CCIndentUnitTestCase extend Link Here
357
                + "  stmt;\n"
350
                + "  stmt;\n"
358
                + "|\n"
351
                + "|\n"
359
                );
352
                );
360
        } finally{
361
            setDefaultsOptions();
362
        }
363
    }
353
    }
364
354
365
    public void testEnterAfterIfElse() {
355
    public void testEnterAfterIfElse() {
356
        setDefaultsOptions();
366
        setLoadDocumentText(
357
        setLoadDocumentText(
367
                "if (true)\n"
358
                "if (true)\n"
368
                + "    stmt;\n"
359
                + "    stmt;\n"
Lines 378-387 public class CCIndentUnitTestCase extend Link Here
378
    }
369
    }
379
370
380
    public void testEnterAfterIfElseHalf() {
371
    public void testEnterAfterIfElseHalf() {
372
        setDefaultsOptions();
381
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
373
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
382
                put(EditorOptions.newLineBeforeBrace, 
374
                put(EditorOptions.newLineBeforeBrace, 
383
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
375
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
384
        try {
385
        setLoadDocumentText(
376
        setLoadDocumentText(
386
                "if (true)\n"
377
                "if (true)\n"
387
                + "  stmt;\n"
378
                + "  stmt;\n"
Lines 394-405 public class CCIndentUnitTestCase extend Link Here
394
                + "else\n"
385
                + "else\n"
395
                + "  |\n"
386
                + "  |\n"
396
                );
387
                );
397
        } finally{
398
            setDefaultsOptions();
399
        }
400
    }
388
    }
401
    
389
    
402
    public void testEnterAfterIfElseStmt() {
390
    public void testEnterAfterIfElseStmt() {
391
        setDefaultsOptions();
403
        setLoadDocumentText(
392
        setLoadDocumentText(
404
                "if (true)\n"
393
                "if (true)\n"
405
                + "    stmt;\n"
394
                + "    stmt;\n"
Lines 417-422 public class CCIndentUnitTestCase extend Link Here
417
    }
406
    }
418
    
407
    
419
    public void testEnterAfterIfMultiLine() {
408
    public void testEnterAfterIfMultiLine() {
409
        setDefaultsOptions();
420
        setLoadDocumentText(
410
        setLoadDocumentText(
421
                "if (1 < 5|\n"
411
                "if (1 < 5|\n"
422
                );
412
                );
Lines 428-433 public class CCIndentUnitTestCase extend Link Here
428
    }
418
    }
429
    
419
    
430
    public void testEnterAfterIfMultiLine2() {
420
    public void testEnterAfterIfMultiLine2() {
421
        setDefaultsOptions();
431
        setLoadDocumentText(
422
        setLoadDocumentText(
432
                "if (1 < 5|)\n"
423
                "if (1 < 5|)\n"
433
                );
424
                );
Lines 443-448 public class CCIndentUnitTestCase extend Link Here
443
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
434
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
444
     */
435
     */
445
    public void testIdentUnbalancedBraces() {
436
    public void testIdentUnbalancedBraces() {
437
        setDefaultsOptions();
446
        setLoadDocumentText(
438
        setLoadDocumentText(
447
            "void foo() {\n" +
439
            "void foo() {\n" +
448
            "#if A\n" +
440
            "#if A\n" +
Lines 470-475 public class CCIndentUnitTestCase extend Link Here
470
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
462
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
471
     */
463
     */
472
    public void testIdentUnbalancedBraces2() {
464
    public void testIdentUnbalancedBraces2() {
465
        setDefaultsOptions();
473
        setLoadDocumentText(
466
        setLoadDocumentText(
474
            "void foo() {\n" +
467
            "void foo() {\n" +
475
            "#if A\n" +
468
            "#if A\n" +
Lines 522-527 public class CCIndentUnitTestCase extend Link Here
522
    
515
    
523
    public void testIdentMain() {
516
    public void testIdentMain() {
524
        setCppEditorKit(false);
517
        setCppEditorKit(false);
518
        setDefaultsOptions();
525
        setLoadDocumentText(
519
        setLoadDocumentText(
526
            "int main() {|\n");
520
            "int main() {|\n");
527
        indentNewLine();
521
        indentNewLine();
Lines 531-575 public class CCIndentUnitTestCase extend Link Here
531
    }
525
    }
532
526
533
    public void testIdentMainHalf() {
527
    public void testIdentMainHalf() {
528
        setCppEditorKit(false);
529
        setDefaultsOptions();
534
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
530
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
535
                put(EditorOptions.newLineBeforeBraceDeclaration, 
531
                put(EditorOptions.newLineBeforeBraceDeclaration, 
536
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
532
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
537
        try {
538
        setCppEditorKit(false);
539
        setLoadDocumentText(
533
        setLoadDocumentText(
540
            "int main() {|\n");
534
            "int main() {|\n");
541
        indentNewLine();
535
        indentNewLine();
542
        assertDocumentText("Incorrect identing of main",
536
        assertDocumentText("Incorrect identing of main",
543
            "int main() {\n" +
537
            "int main() {\n" +
544
            "  \n");
538
            "  \n");
545
        } finally{
546
            setDefaultsOptions();
547
        }
548
    }
539
    }
549
540
550
    public void testIdentMainHalf2() {
541
    public void testIdentMainHalf2() {
542
        setCppEditorKit(false);
543
        setDefaultsOptions();
551
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
544
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
552
                put(EditorOptions.newLineBeforeBraceDeclaration, 
545
                put(EditorOptions.newLineBeforeBraceDeclaration, 
553
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
546
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
554
        try {
555
        setCppEditorKit(false);
556
        setLoadDocumentText(
547
        setLoadDocumentText(
557
            "int main()|\n");
548
            "int main()|\n");
558
        indentNewLine();
549
        indentNewLine();
559
        assertDocumentText("Incorrect identing of main",
550
        assertDocumentText("Incorrect identing of main",
560
            "int main()\n" +
551
            "int main()\n" +
561
            "\n");
552
            "\n");
562
        } finally{
563
            setDefaultsOptions();
564
        }
565
    }
553
    }
566
554
567
    public void testIdentMainHalf3() {
555
    public void testIdentMainHalf3() {
556
        setCppEditorKit(false);
557
        setDefaultsOptions();
568
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
558
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
569
                put(EditorOptions.newLineBeforeBraceDeclaration, 
559
                put(EditorOptions.newLineBeforeBraceDeclaration, 
570
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
560
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
571
        try {
572
        setCppEditorKit(false);
573
        setLoadDocumentText(
561
        setLoadDocumentText(
574
            "int main()\n"+
562
            "int main()\n"+
575
            "{|\n");
563
            "{|\n");
Lines 578-589 public class CCIndentUnitTestCase extend Link Here
578
            "int main()\n" +
566
            "int main()\n" +
579
            "{\n" +
567
            "{\n" +
580
            "  \n");
568
            "  \n");
581
        } finally{
582
            setDefaultsOptions();
583
        }
584
    }
569
    }
585
570
586
    public void testIZ101099() {
571
    public void testIZ101099() {
572
        setDefaultsOptions();
587
        setLoadDocumentText(
573
        setLoadDocumentText(
588
                "template <class T>|\n"
574
                "template <class T>|\n"
589
                );
575
                );
Lines 595-600 public class CCIndentUnitTestCase extend Link Here
595
    }
581
    }
596
582
597
    public void testIZ122489() {
583
    public void testIZ122489() {
584
        setDefaultsOptions();
598
        setLoadDocumentText(
585
        setLoadDocumentText(
599
                "Cpu::Cpu(int units) :\n"+
586
                "Cpu::Cpu(int units) :\n"+
600
                "   Module(units) {\n"+
587
                "   Module(units) {\n"+
Lines 614-619 public class CCIndentUnitTestCase extend Link Here
614
     */
601
     */
615
    public void testIdentMethodParameters() {
602
    public void testIdentMethodParameters() {
616
        setCppEditorKit(false);
603
        setCppEditorKit(false);
604
        setDefaultsOptions();
617
        setLoadDocumentText(
605
        setLoadDocumentText(
618
            "int longmain(int a,|\n");
606
            "int longmain(int a,|\n");
619
        indentNewLine();
607
        indentNewLine();
Lines 626-645 public class CCIndentUnitTestCase extend Link Here
626
     * test parameter aligning
614
     * test parameter aligning
627
     */
615
     */
628
    public void testIdentMethodParameters2() {
616
    public void testIdentMethodParameters2() {
617
        setCppEditorKit(false);
618
        setDefaultsOptions();
629
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
619
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
630
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
620
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
631
        try {
621
        setLoadDocumentText(
632
            setCppEditorKit(false);
622
            "int longmain(int a,|\n");
633
            setLoadDocumentText(
623
        indentNewLine();
634
                "int longmain(int a,|\n");
624
        assertDocumentText("Incorrect identing of main",
635
            indentNewLine();
625
            "int longmain(int a,\n" +
636
            assertDocumentText("Incorrect identing of main",
626
            "             \n");
637
                "int longmain(int a,\n" +
638
                "             \n");
639
        } finally{
640
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
641
                putBoolean(EditorOptions.alignMultilineMethodParams, false);
642
        }
643
    }
627
    }
644
628
645
    /**
629
    /**
Lines 647-652 public class CCIndentUnitTestCase extend Link Here
647
     */
631
     */
648
    public void testIdentCallParameters() {
632
    public void testIdentCallParameters() {
649
        setCppEditorKit(false);
633
        setCppEditorKit(false);
634
        setDefaultsOptions();
650
        setLoadDocumentText(
635
        setLoadDocumentText(
651
            "a = longmain(a,|\n");
636
            "a = longmain(a,|\n");
652
        indentNewLine();
637
        indentNewLine();
Lines 659-676 public class CCIndentUnitTestCase extend Link Here
659
     * test parameter aligning
644
     * test parameter aligning
660
     */
645
     */
661
    public void testIdentCallParameters2() {
646
    public void testIdentCallParameters2() {
647
        setDefaultsOptions();
662
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
648
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
663
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
649
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
664
        try {
650
        setLoadDocumentText(
665
            setLoadDocumentText(
651
            "a = longmain(a,|\n");
666
                "a = longmain(a,|\n");
652
        indentNewLine();
667
            indentNewLine();
653
        assertDocumentText("Incorrect identing of main",
668
            assertDocumentText("Incorrect identing of main",
654
            "a = longmain(a,\n" +
669
                "a = longmain(a,\n" +
655
            "             \n");
670
                "             \n");
656
    }
671
        } finally{
657
672
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
658
    public void testIdentNewLineLocalDeclararion() throws Exception {
673
                putBoolean(EditorOptions.alignMultilineCallArgs, false);
659
        setDefaultsOptions("GNU");
674
        }
660
        setLoadDocumentText(
661
            "tree\n" +
662
            "disp(int i){\n" +
663
            "  int i = |\n" +
664
            "}"
665
            );
666
        indentNewLine();
667
        assertDocumentTextAndCaret("Incorrect identing of New Line Local Declararion",
668
            "tree\n" +
669
            "disp(int i){\n" +
670
            "  int i = \n" +
671
            "  |\n" +
672
            "}"
673
            );
674
    }
675
676
    public void testIdentNewLineLocalStatement() throws Exception {
677
        setDefaultsOptions("GNU");
678
        setLoadDocumentText(
679
            "tree\n" +
680
            "disp(int i){\n" +
681
            "  i = |\n" +
682
            "}"
683
            );
684
        indentNewLine();
685
        assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement",
686
            "tree\n" +
687
            "disp(int i){\n" +
688
            "  i = \n" +
689
            "          |\n" +
690
            "}"
691
            );
692
    }
693
694
    public void testIdentNewLineLocalStatement2() throws Exception {
695
        setDefaultsOptions("GNU");
696
        setLoadDocumentText(
697
            "tree\n" +
698
            "disp(int i){\n" +
699
            "  i = f(i,|)\n" +
700
            "}"
701
            );
702
        indentNewLine();
703
        assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement",
704
            "tree\n" +
705
            "disp(int i){\n" +
706
            "  i = f(i,\n" +
707
            "        |)\n" +
708
            "}"
709
            );
710
    }
711
712
    public void testIdentNewLineLocalStatement3() throws Exception {
713
        setDefaultsOptions("GNU");
714
        setLoadDocumentText(
715
            "tree\n" +
716
            "disp(int i){\n" +
717
            "  i = f(i,\n" +
718
            "        i+|)\n" +
719
            "}"
720
            );
721
        indentNewLine();
722
        assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement",
723
            "tree\n" +
724
            "disp(int i){\n" +
725
            "  i = f(i,\n" +
726
            "        i+\n" +
727
            "          |)\n" +
728
            "}"
729
            );
730
    }
731
732
    public void testIdentNewLineLocalStatement4() throws Exception {
733
        setDefaultsOptions("GNU");
734
        setLoadDocumentText(
735
            "tree\n" +
736
            "disp(int i){\n" +
737
            "  i = f(i,\n" +
738
            "        i+foo(a,|))\n" +
739
            "}"
740
            );
741
        indentNewLine();
742
        assertDocumentTextAndCaret("Incorrect identing of New Line Local Statement",
743
            "tree\n" +
744
            "disp(int i){\n" +
745
            "  i = f(i,\n" +
746
            "        i+foo(a,\n" +
747
            "              |))\n" +
748
            "}"
749
            );
675
    }
750
    }
676
}
751
}
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCIndentUnitTestCaseSingleTestCase.java (-52 lines)
Lines 44-99 public class CCIndentUnitTestCaseSingleT Link Here
44
        super(testMethodName);
44
        super(testMethodName);
45
    }
45
    }
46
46
47
    public void testEnterAfterIfBraceHalf() {
48
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
49
                put(EditorOptions.newLineBeforeBrace, 
50
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
51
        try {
52
        setLoadDocumentText(
53
                "if (true)\n" +
54
                "  {|\n" +
55
                "  }\n"
56
                );
57
        indentNewLine();
58
        assertDocumentTextAndCaret("Incorrect new-line indent",
59
                "if (true)\n" +
60
                "  {\n" +
61
                "    |\n" +
62
                "  }\n" 
63
                );
64
        } finally{
65
            setDefaultsOptions();
66
        }
67
    }
68
69
    public void testEnterAfterIfBraceHalf2() {
70
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
71
                put(EditorOptions.newLineBeforeBraceDeclaration, 
72
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
73
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
74
                put(EditorOptions.newLineBeforeBrace, 
75
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
76
        try {
77
        setLoadDocumentText(
78
                "int foo()\n" +
79
                "{\n" +
80
                "  if (true)\n" +
81
                "    {|\n" +
82
                "    }\n" +
83
                "}\n"
84
                );
85
        indentNewLine();
86
        assertDocumentTextAndCaret("Incorrect new-line indent",
87
                "int foo()\n" +
88
                "{\n" +
89
                "  if (true)\n" +
90
                "    {\n" +
91
                "      |\n" +
92
                "    }\n" +
93
                "}\n"
94
                );
95
        } finally{
96
            setDefaultsOptions();
97
        }
98
    }
99
}
47
}
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/CCNewFormatterUnitTestCase.java (+38 lines)
Lines 4177-4182 public class CCNewFormatterUnitTestCase Link Here
4177
                ", env_ (env) { }\n" 
4177
                ", env_ (env) { }\n" 
4178
                );
4178
                );
4179
    }
4179
    }
4180
4181
    public void testGnuStuleNewLineName5() {
4182
        setDefaultsOptions("GNU");
4183
        setLoadDocumentText(
4184
                "tree decl_shadowed_for_var_lookup (tree from)\n" +
4185
                "{\n" +
4186
                "  return NULL_TREE;\n" +
4187
                "}\n"
4188
                );
4189
        reformat();
4190
        assertDocumentText("Incorrect formatting GNU new line name",
4191
                "tree\n" +
4192
                "decl_shadowed_for_var_lookup (tree from)\n" +
4193
                "{\n" +
4194
                "  return NULL_TREE;\n" +
4195
                "}\n"
4196
                );
4197
    }
4198
4199
    public void testGnuStuleNewLineName6() {
4200
        setDefaultsOptions("GNU");
4201
        setLoadDocumentText(
4202
                "B::tree A::\n" +
4203
                "decl_shadowed_for_var_lookup (tree from)\n" +
4204
                "{\n" +
4205
                "  return NULL_TREE;\n" +
4206
                "}\n"
4207
                );
4208
        reformat();
4209
        assertDocumentText("Incorrect formatting GNU new line name",
4210
                "B::tree\n" +
4211
                "A::decl_shadowed_for_var_lookup (tree from)\n" +
4212
                "{\n" +
4213
                "  return NULL_TREE;\n" +
4214
                "}\n"
4215
                );
4216
    }
4217
    
4180
    //IZ#131158:"Spaces Within Parenthesis|Braces" checkbox works wrongly
4218
    //IZ#131158:"Spaces Within Parenthesis|Braces" checkbox works wrongly
4181
    public void testSpaceWithinBraces() {
4219
    public void testSpaceWithinBraces() {
4182
        setDefaultsOptions();
4220
        setDefaultsOptions();

Return to bug 131379