Author: Jiri Prox
Version: 6.5
Last update: 18.09.2008
Introduction: This is test specification for code formatting feature in NetBeans 6.5. It covers indentation in editor, reformat action, global formatting settings and project specific formatting settings. The formatting can be customized in several levels. The first level is general formatting respected by all languages. For small set languages there is language specific formatting reflexing the language sturcture of particular language. This settings overrides the default one. The same two level hierarchy can be turned on project level. The project can have it's own formatting settings which has higher priority the the globla settings. The customization is made in project properties dialog.
Comments: Start IDE with fresh userdir, to get rid of old settings. Open prepared project Formatting.zip .All settings can be found in Options dialog, category Editor, tab Formatting. Check the preview each time the settings are changed.
Purpose:
Setup:
- Number of spaces per indent, right margin
- Open options dialog on proper tab.
- Select Language: All Languages, Category: Tabs And Indents
- Change 'Number Of Space per Indent' and 'Right Margin'
- Open all files Indentaiton.{java|html|xml} and reformat them
- EXPECTED RESULT: The indentation is corrected to specified value, right margin is painted at correct position
- Expand tab to spaces, Tab size
- Open options dialog on proper tab.
- Select Language: All Languages, Category: Tabs And Indents
- Change 'Tab Size' and uncheck 'Expand tabs to spaces'
- Open all files indentaiton.{java|html|xml} and reformat them
- EXPECTED RESULT: If there is N spaces in a row (where N is tab size) when invoking reformat, they are replace by one tab character. Tab key does not insert one tab char but tyies to add as many tab as it can, a the rest of space to the value of indentation level is filled with spaces. The spaces are never replaced by tab char when typing them manually.
- Tabs size, indentation level
- Open options dialog on proper tab.
- Select Language: All Languages, Category: Tabs And Indents
- Change 'Tab Size' and 'Number of Spaces per Indenr' to various values, keep 'Expand tabs to spaces' unchecked
- Open all files indentaiton.{java|html|xml} and reformat them after each change
- EXPECTED RESULT: The spaces and tabs are inserted acording to notes in previous testcase result. Every time as many spaces as is possible is replaced by tabs,othervise the spaces are kept in code to get to appropriate indentation level.
Purpose: This suite is focused on Java language formatting settings
Setup: Set default formatting setting before performing this suite
- Continuation indentation
- Open options dialog on proper tab.
- Select Language: Java, Category: Tabs And Indents
- Change 'Continuation Indentation Size'
- Open any java file and type (in scope where it makes sence:
- int i = <enter>
- public void <enter>
- public void metgod(int a, <enter>
- class <enter>
- int a = 3 <enter>
- EXPECTED RESULT: The caret is moved to next line. The position of cursot is indentation level + continuation indentation
- Label indentation
- Open options dialog on proper tab.
- Select Language: Java, Category: Tabs And Indents
- Change 'Label indentation' and 'Absolute label indentation'
- Try another combination of values
- Open file Label.java and reformat it
- EXPECTED RESULT: If 'Absolute indentation' is checked, the label is moved to the 1st colum, othervise it respect indentation level. The 'Label indentaiton' controls additional indentation of the block the label belong to. E.g. the code in block is at position: 'indentation level'*'indentation size'+'label indentation'. If the label indentation is bigger the lable name + 1 for ':' char the blocks is moved to begin at the same line as lable, otherview the block is moved to begin in new line. (Try remaning label to test this)
- Indent Top Level Class Members, Indent Case Statements
- Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
- Uncheck 'Indent Top Level Class Members'
- Reformat class Indentation.java
- Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
- Uncheck 'Indent Case Statement In Switch'
- Reformat class Indentation.java
- EXPECTED RESULT: Whne first checkbox is unselected all class members (methods, fields, inner classes, initializers) are indented to begin at 1st column. (also in inner classes). When second checkbox is unselected the 'case' statements is indented to begin as the same position as related 'switch' statement
- Overriding default indentation settings
- Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
- Check 'Override Global Options' and set new values for items which are enabled.
- Open Indentation.java and reformat it
- Open OD and uncheck 'Override Global Options' again
- EXPECTED RESULT: The reformat in java respects entered values. Formatting in others files is unchanged. Once the global settings are not overrided the formatting settings is same in all files.
- New lines
- Open options dialog on proper tab, Language: Java, Category: Alignment
- Check all checkboxes in section New Lines
- Open Alignment.java and reformat it
- Open OD and uncheck all checboxes again
- EXPECTED RESULT: New lines are inserted before 'void' in method declaration, else, while, catch and finally. Whne the checkbox are unchecked the newlines are removed again
- Multiline Alignment 1
- Open options dialog on proper tab, Language: Java, Category: Alignment
- Check all checkboxes in 1st column in section Multiline Alignment
- Open Alignment2.java and reformat it
- Open OD and uncheck all checboxes again
- EXPECTED RESULT: The parameters in method declaration, arguments in annotations, exceptions behing throws, operands of binary operator , parts of assign statemen are indented that the identifiers stars at the same column. When the checkboxes are unchecked the value of continuation indentation is important again.
- Multiline Alignment 2
- Open options dialog on proper tab, Language: Java, Category: Alignment
- Check all checkboxes in 2st column in section Multiline Alignment
- Open Alignment3.java and reformat it
- Open OD and uncheck all checboxes again
- EXPECTED RESULT: The arguments in method call, interfaces behing 'implements', array elements, parts of ternary operator, parts of for statements are indented that the identifiers stars at the same column. When the checkboxes are unchecked the value of continuation indentation is important again.
- Position - Class
- Open options dialog on proper tab, Language: Java, Category: Braces
- In combobox 'Class Declaration' select values
- Same line
- New line
- New line half indented
- New line indented
- Open BracesPosition.java and reformat it
- EXPECTED RESULT: The checkbox controls only position of class bracess, and the formatting is following 1) opening braces is behind class name, closing is at 1st column, 2) opening brace is at first column at a new line, closing is at 1st column, 3) opening and closing braces are as separated lines, indented by half value of intentation size, 4) opening and closing braces are indented by indentation size
- Position - Method
- Open options dialog on proper tab, Language: Java, Category: Braces
- In combobox 'Method declartion' select values
- Same line
- New line
- New line half indented
- New line indented
- Open BracesPosition.java and reformat it
- EXPECTED RESULT: The checkbox controls only position of braces in method declarations, the position is described above
- Position - Other
- Open options dialog on proper tab, Language: Java, Category: Braces
- In combobox 'Other' select values
- Same line
- New line
- New line half indented
- New line indented
- Open BracesPosition.java and reformat it
- EXPECTED RESULT: The checkbox controls only position of other types of braces - ifs, initializers, array initializers, block, synchronized blocks, lools, switch, the position where are braces moved is described above
- else if
- Open options dialog on proper tab, Language: Java, Category: Braces
- Uncheck 'Special else if Threatment
- Open BracesPosition.java and reformat it
- Restore the setting and reformat again
- EXPECTED RESULT: If check box is selected the else if is not separated into two lines but the code is kept togeather in one line
- Brace generation
- Open options dialog on proper tab, Language: Java, Category: Braces
- In section Braces Generation set folowing values in all comboboxex -
- Leave alone
- Gnerate
- Eliminate
- Open BracesGeneration.java and reformat it after each kind of value is set.
- EXPECTED RESULT: When 'leave alone' is set, there is not added or removed any braces. When 'generate' is set the bodies of if, while, do while, for is wrapped into a block. See method generate(). If 'eliminate' is set, the body of loops and for are unwrapped from a block if it is possible, e.g. the body contains only one statement. See method 'eliminate()' and 'cannotEliminate'
Comments: This suite tests the line wrapping, wrapping of each element can by set to 3 level: Never - the code construction is never wrapped, If long - the code is wrapped only if it exceeds right margin, Always - the code is always separated into new lines. To test this follow theses steps 1) open requested file, set mentioned rule to Always and reformat code, 2) undo changes, set right margin to 40 and set wrapping value to If Long, reformat code, 3) undo changes, set wrapping value to Never and reformat 4) set right margin back to 80
- Wrapping 1
- Open options dialog on proper tab, Language: Java, Category: Wrapping
- Open Wraping1.java
- Perform steps described in Comments with first half of the rules one by one - from Extend/Implements to ArrayInitializer
- EXPECTED RESULT:
- Extends/Implemtnes Keyword - break is added before extends/implements keyword (classes InnerClassWithQuiteALongName,InnerClassWithQuiteALongName)
- Extends/Implemtnes list - break is added behind comma in list of implemented interfaces and behind implements/extends (classes Wrapping1,InnerClass)
- Method parameters - break is added behind comma in list of parameters (method method(int,intStrng ...) )
- Method call argument - break is added behind comma in method call (method method(int,intStrng ...) )
- Annotation Arguments - behind opening brace or comma in annotation argument list (usage of MyAnnot)
- Chained method Calls - behind period in row of method invocations (chained call of method method(int,intStrng ...))
- Throws keyword - before throw keyword
- Throws list - behind throw keyword of comma in the list of exceptions
- Array Initializer - after opening '{' of after comma between array elements
- Wrapping 2
- Open options dialog on proper tab, Language: Java, Category: Wrapping
- Open Wraping2.java
- Perform steps described in Comments with the second half of the rules one by one - from For to Assignment Operator
- EXPECTED RESULT:
- For - new line is added behind each ';' inside for statement
- For Stratement - new line is added behind closing ) of for statement (automatic bracket generation must be turned off to test this)
- If Statement - new line is added behind closing ) of if statement (automatic bracket generation must be turned off to test this)
- While Statement - new line is added behind closing ) of while statement (automatic bracket generation must be turned off to test this)
- Do ... While Statement - new line is added behind do in do...while statement (automatic bracket generation must be turned off to test this)
- Assert - new line is added behind : in assert
- Enum Constants - new line is added behind ',' in constatn list
- Annotations - each annotation is moved to separate line
- Binary Operator - new line is added behind binary operator
- Ternary Operator - new line is added before ? or : in ternary operator
- Assignment Operator - new line is added after =
Comments: The testsuite focuses on controling number of blank lines between elements in java code. The number of empty spaces between element A and B is the bigger number from blank lines behind A and blank lines before B. The javadoc and inline comments counts as part of releated element. The blank lines inside methods body must stay untouched.
- Blank lines
- Open options dialog on proper tab, Language: Java, Category: Blank lines
- Try change each value one by one
- After entering new value, open EmptyLines.java and reformat it
- EXPECTED RESULT: The number of blank lines respect entered values. How is computed exact number of empty lines is descibed in the comments
- Blank lines - commjents
- Open EmptyLines.java and add comments - javadoc, block and inline
- Open options dialog on proper tab, Language: Java, Category: Blank lines
- Try change each value one by one
- After entering new value, open EmptyLines.java and reformat it
- EXPECTED RESULT: The number of blank lines respect entered values. The comment is handeled as a part of element
Comment: The Spaces formatting options controls entering spaces in various places. The name of eahc combobox is quite straiforward, so there is no need to describe separately in this test suite what it does.
- Spaces
- Open ClassA.java
- Open options dialog on proper tab, Language: Java, Category: Spaces
- Try change each value one by one
- After entering new value, open ClassA.java and reformat it
- EXPECTED RESULT: The spaces are insrted to proper positons
Purpose:
Setup: