TS 65 Formatting

Code Formatting Test Specification

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_TS_65_Formatting.zip .All settings can be found in Options dialog, category Editor, tab Formatting. Check the preview each time the settings are changed.

Contents


Test suite: General indentation setting

Purpose:
Setup:

  1. Number of spaces per indent, right margin
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Number Of Space per Indent' and 'Right Margin'
    4. 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
  1. Expand tab to spaces, Tab size
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Tab Size' and uncheck 'Expand tabs to spaces'
    4. 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.
  1. Tabs size, indentation level
    1. Open options dialog on proper tab.
    2. Select Language: All Languages, Category: Tabs And Indents
    3. Change 'Tab Size' and 'Number of Spaces per Indenr' to various values, keep 'Expand tabs to spaces' unchecked
    4. 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.


Test suite: Tabs and indents

Purpose: This suite is focused on Java language formatting settings
Setup: Set default formatting setting before performing this suite

  1. Continuation indentation
    1. Open options dialog on proper tab.
    2. Select Language: Java, Category: Tabs And Indents
    3. Change 'Continuation Indentation Size'
    4. Open any java file and type (in scope where it makes sence:
      1. int i = <enter>
      2. public void <enter>
      3. public void metgod(int a, <enter>
      4. class <enter>
      5. int a = 3 <enter>
    • EXPECTED RESULT: The caret is moved to next line. The position of cursot is indentation level + continuation indentation
  1. Label indentation
    1. Open options dialog on proper tab.
    2. Select Language: Java, Category: Tabs And Indents
    3. Change 'Label indentation' and 'Absolute label indentation'
    4. Try another combination of values
    5. 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)
  1. Indent Top Level Class Members, Indent Case Statements
    1. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    2. Uncheck 'Indent Top Level Class Members'
    3. Reformat class Indentation.java
    4. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    5. Uncheck 'Indent Case Statement In Switch'
    6. 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
  1. Overriding default indentation settings
    1. Open options dialog on proper tab, Language: Java, Category: Tabs And Indents
    2. Check 'Override Global Options' and set new values for items which are enabled.
    3. Open Indentation.java and reformat it
    4. 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.


Test suite: Alignment

  1. New lines
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in section New Lines
    3. Open Alignment.java and reformat it
    4. 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
  1. Multiline Alignment 1
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in 1st column in section Multiline Alignment
    3. Open Alignment2.java and reformat it
    4. 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.
  1. Multiline Alignment 2
    1. Open options dialog on proper tab, Language: Java, Category: Alignment
    2. Check all checkboxes in 2st column in section Multiline Alignment
    3. Open Alignment3.java and reformat it
    4. 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.


Test suite: Braces

  1. Position - Class
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Class Declaration' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. 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
  1. Position - Method
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Method declartion' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. Open BracesPosition.java and reformat it
    • EXPECTED RESULT: The checkbox controls only position of braces in method declarations, the position is described above
  1. Position - Other
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In combobox 'Other' select values
      1. Same line
      2. New line
      3. New line half indented
      4. New line indented
    3. 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
  1. else if
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. Uncheck 'Special else if Threatment
    3. Open BracesPosition.java and reformat it
    4. 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
  1. Brace generation
    1. Open options dialog on proper tab, Language: Java, Category: Braces
    2. In section Braces Generation set folowing values in all comboboxex -
      1. Leave alone
      2. Gnerate
      3. Eliminate
    3. 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'


Test suite: Wrapping

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

  1. Wrapping 1
    1. Open options dialog on proper tab, Language: Java, Category: Wrapping
    2. Open Wraping1.java
    3. Perform steps described in Comments with first half of the rules one by one - from Extend/Implements to ArrayInitializer
    • {{result|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
  1. Wrapping 2
    1. Open options dialog on proper tab, Language: Java, Category: Wrapping
    2. Open Wraping2.java
    3. Perform steps described in Comments with the second half of the rules one by one - from For to Assignment Operator
    • {{{1}}}

Test suite: Blank lines

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.

  1. Blank lines
    1. Open options dialog on proper tab, Language: Java, Category: Blank lines
    2. Try change each value one by one
    3. 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
  1. Blank lines - commjents
    1. Open EmptyLines.java and add comments - javadoc, block and inline
    2. Open options dialog on proper tab, Language: Java, Category: Blank lines
    3. Try change each value one by one
    4. 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


Test suite: Spaces

Comment: The Spaces formatting options controls entering spaces in various places. The name of each combobox is quite straight forward, so there is no need to describe separately in this test suite what it does.

  1. Spaces
    1. Open ClassA.java
    2. Open options dialog on proper tab, Language: Java, Category: Spaces
    3. Try change each value one by one
    4. After entering new value, open ClassA.java and reformat it
    • EXPECTED RESULT: The spaces are insrted to proper positons


Test suite: Per-project formatting

Purpose: This tests formatting setting which applies only to one specific projects. This settings can be compiled among the projects
Setup: Start IDE with default formatting settings (clear userdir) and create new J2se project

  1. Formatting
    1. Open project properties
    2. Select tab formatting
    3. Select 'Use project specific options'
    4. Customize the formatting setting is this dialog
    5. Confirm and reformat source code
    • EXPECTED RESULT: The project formatting is changed. It effects only files in this project. Other files are unchanged. The formatting settings are written to project.properties as a set of properties which differs from the default setting.
  2. Formatting - setting to default
    1. Open project properties
    2. Open project properties
    3. Select tab formatting
    4. Select 'Use global setting'
    5. Confirm and reformat code
    • EXPECTED RESULT: The sources are formatted according to default setting. A prompt dialog appears when 'Use global settings' is selected. Formatting settings are removed form project.properties
  3. Copy formatting setting
    1. Open project properties and customize project specific formatting
    2. Create new project
    3. Go to project properties, formatting tab
    4. Select 'Use project specific formatting' and press 'Load from other project'
    5. In the dialog select first project and confirm
    • EXPECTED RESULT: The settings are copied from the original project to the actual one.
  4. Invalid copy
    1. Repeat previous test case, but in the last step select project w/o project specific formatting
    • EXPECTED RESULT: A warning appears after selection of project, informing that there are no project specific formatting available
  5. Go to globla setting
    1. Open project properties
    2. Select tab formatting
    3. Press 'Edit global options'
    • EXPECTED RESULT: Options dialog is opened with preselected Editor -> Formatting category


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo