TS 74 EditorCodeFolding

Editor - Codefolding

Author:Jiri Prox, Standa Sazonov
Version:7.4
Last update:2013/06/28
Introduction:

Contents

Test suite: Basic Code Folding

  1. Code folding after opening a file
    1. Open MyClass file
    • EXPECTED RESULT:
      - All folds are identified and expanded by default, so that user can see the whole source code.
      - Fold marks must be presented by initial comments, import statemets, javadoc comments, inner class and methods
  2. Add javadoc code
    1. In Projects window right click on MyClass.java and from pop-up menu go Tools->Analyze Javadoc
    2. Check checkbox in front of MyClass.java and confirm
    • EXPECTED RESULT:Code folds must be added immediately after javadoc is added
  3. Add/Remove code (1)
    1. Open MyClass file
    2. Add some inner classes
    3. Delete some inner classes
    4. Add/modify/delete some javadoc (/** ... */)
    • EXPECTED RESULT:Code folds should correctly corresponde to changes in code
  4. Add/Remove code (2)
    1. Open TestA.java
    2. Put caret on line 13 (between TestA and m1 declaration)
    3. Type "public class c1{"
    4. Put caret on line 17 an and close bracket "}"
    5. Delete class c1 with inner method m1
    • EXPECTED RESULT:Code fold for inner class c1 have to be added immediately after you type "}", when you delete class c1 corresponding folds should be deleted
  5. Collapse cases
    1. Go Tools->Options->Editor->Folding->All Languages and check "Documentation" in "Collapse by default", over checkboxes in same group leave unchecked then press "Ok"
    2. Open CollapseCases.java, wait till NetBeans calculates and draw code folds, then close CollapseCasses.java
    3. Check "Initial comments" in "Collapse by default", over checkboxes in same group leave unchecked then press "Ok"
    4. Open CollapseCases.java, wait till NetBeans calculates and draw code folds, then close CollapseCasses.java
    5. Check "Members" in "Collapse by default", over checkboxes in same group leave unchecked then press "Ok"
    6. Open CollapseCases.java, wait till NetBeans calculates and draw code folds, then close CollapseCasses.java
    7. Check "Nested blocks" in "Collapse by default", over checkboxes in same group leave unchecked then press "Ok"
    8. Open CollapseCases.java, wait till NetBeans calculates and draw code folds, then expand cl1 and cl2
    • EXPECTED RESULT:
      - In step 2 only javadoc should be collapsed (lines 8-11, 17-23)
      - In step 4 only initial comments should be collapsed (lines 1-5)
      - In step 6 only methods should be collapsed (lines 24-30, 32-34)
      - In step 8 only classes should be collapsed (lines 14-36, 15-35) when you expand cl1 and cl2, methods method1 and m1 are not collapsed
  6. Options - Disable/Enable CF
    1. Go to Tools->Options->Editor->Folding->All Languages
    2. Uncheck Use Code Folding checkbox
    • EXPECTED RESULT:
      - All fold marks must be removed from editor when you disable code folding and all previously collapsed portions of code must be expanded.
      - Fold marks must be shown in the way that reflects Code Folding settings under Tools->Options->Editor->Folding->All Languages after you re-enable the Use Code Folding option.
  7. Display Options
    1. Open CollapseCases.jave and using [-] collapse fold javadoc at line 17
    2. Go to Tools->Options->Editor->Folding->All Languages
    3. In "Display Options" group check both Content preview and Show summary then press Apply btn
    4. In "Display Options" group check Content preview and uncheck Show summary then press Apply btn
    5. In "Display Options" group uncheck Content preview and check Show summary then press Apply btn
    6. In "Display Options" group uncheck both Content preview and Show summary then press Apply btn
    • EXPECTED RESULT:
      - Both checked Content preview and Show summary: /** Simple method ...7 lines */
      - Content preview unchecked, Show summary checked:/**...7 lines */
      - Content preview checked, Show summary unchecked:/** Simple method ...*/
      - Both unchecked Content preview and Show summary:/**...*/
 
  1. Options - Typing in editor
    1. Enable CF if it's disabled from previous testcase
    2. Enabled default folding of all elements
    3. Open/create new java file
    4. Write some code in editor
    • EXPECTED RESULT: All folds are collapsed when file is opened. When editing the folds keep it status. The only exception is when enter is pressed behind the closing symbol ( } or */ ). In this situation the folder is collapsed
  2. Options - Scrolling
    1. Enabled default folding of all elements
    2. new java file A with 3 method a ,b, c (they are written in file in this order)
    3. method a,b are longer then editor view (may be empty)
    4. close A
    5. create class B calling method A.b()
    6. ctrl-click on the reference to b()
    • {{{1}}}
  3. Java Settings
    1. Go Tools->Options->Editor->Folding->Java(You'll get similar dialog like in previous steps)
    2. Randomly Combine these options (use default settings, use your own setting, enable/disable code folding, enable/disable Content Preview and Show summary)
    • EXPECTED RESULT:Options for Java are superior to All Languages options. Make sure that new settings are well corresponded to code.

Test suite: Code Folding Actions

  1. CF Mouse Actions
    1. Code folds are indicated by the [[[+ | [+]] or [[[- | [-]] mark, depending on the state of the fold, as depicted here (colors are just for demonstration):
      Image:TS74_CodeFolding_Screen01.png
    2. To collapse a code fold, click the [-] mark of that fold
    3. To expand a code fold, click the [+] mark of that fold
    4. Doble click on any collapsed code (indicated with border with "..." or description) in order to to expand the code fold
    • EXPECTED RESULT: Folds are collapsed/expanded as expected.
  2. Code Folding main menu
    1. Check content of "Code Folding" menu under View->Code Folds
    • EXPECTED RESULT:Following items must be present in the menu:
      - Collapse Fold
      - Expand Fold
      - Collapse All
      - Expand All
      - Collapse Fold Tree
      - Expand Fold Tree
      - Collapse All JavaDoc
      - Expand All JavaDoc
      - Collapse All JavaCode
      - Expand All JavaCode
  3. Collapse and expand single code fold
    1. Move caret inside method's body, collapse method's body using View|Code Folds|Collapse Fold
    2. Expand the method using View|Code Folds|Expand Fold
    3. Place caret on opening or closing mark of custom code fold, collapse custom code fold from the main menu
    4. Expand custom fold using main menu
    5. Move cursor in front of the method's declaration (the beginning of method's declaration row), collapse method from the main menu
    6. Expand the method using main menu
    7. Move cursor behind the end of a method's body (after closing brace "}") and collapse method from the main menu
    8. Expand the method using main menu
    9. Place caret on a row with JavaDoc comment, collapse JavaDoc comment from the main menu
    10. Expand the JavaDoc using main menu
    11. Place caret inside a method of some inner class, collapse method from the main menu
    12. Expand the method that you just collapsed using main menu
    13. Place caret inside some inner class, collapse inner class from the main menu
    14. Expand the inner class using main menu
    • EXPECTED RESULT: Collapsing and expanding code folds works as expected when you invoke main menu actions. Whenever code fold is collapsed, caret is placed in front of ... mark in the editor
  4. Collapse and expand all code folds
    1. Invoke "Collapse All" action from the main menu (View|Code Folds|Collapse All)
    2. Invoke "Expand All" action from the main menu (View|Code Folds|Expand All)
    3. Invoke "Collapse All JavaDoc" action from the main menu (View|Code Folds|Collapse All Javadoc)
    4. Invoke "Expand All JavaDoc" action from the main menu (View|Code Folds|Expand All Javadoc)
    5. Invoke "Collapse All Java Code" action from the main menu (View|Code Folds|Collapse All Java Code)
    6. Invoke "Expand All Java Code" action from the main menu (View|Code Folds|Expand All Java Code)
    7. Try to invoke above mentioned actions from editor's popup menu (Code Folds|...)
    • EXPECTED RESULT: All folds (or all folds of a particular type) in currently opened file must be collapsed and expanded as expected after performing an action.
  5. CF Shortcut Actions
    1. Use shortcut to collapse single code fold (Ctrl+'-')
    2. Use shortcut to expand single code fold (Ctrl+'+')
    3. Use shortcuts for "Collapse All" (Ctrl+Shift+'-') and "Expand All" (Ctrl+Shift+'+') actions
    • EXPECTED RESULT: Keyboard shortcuts work as expected, performing the same actions as corresponding actions invoked from the main menu
  6. Show Collapsed Code in Tooltip
    1. Move the mouse cursor above the collapsed code (border with "..." or description)
    • EXPECTED RESULT: Collapsed code is showed in tooltip, it is colored and indented.
  7. Open No Parsable File
    1. Open a corrupted file CorruptedFile.java
    • EXPECTED RESULT: Code folds should be painted properly where possible.
  8. Empty File
    1. Create file "Java Main Class"
    2. Select all code using Ctrl+A
    3. Press Delete
    • EXPECTED RESULT: All content should be erased, including the CF

Test suite: Defining Custom Code Folding

Setup: Create a new Java class

  1. Add custom code fold
    1. Add custom opening mark //<editor-fold> to the beginning of a file
    2. Add ending mark //</editor-fold> to the bottom of the same file
    3. Close and re-open the file
    • EXPECTED RESULT:The user defined fold must be correctly recognized when added. When file is re-opened, user defined code fold is in expanded state (source code is visible).
  2. Add custom code fold with description
    1. Add property "desc" to the opening mark of the custom fold from the previous test case, for example: //<editor-fold desc="This is my code fold">
    2. Click the little [-] sign in order to collapse the single code fold (→ code fold is collapsed)
    3. Expand the code fold by clicking the little [+] sign (→ code fold is expanded again)
    • EXPECTED RESULT: When the custom code fold with description is collapsed, you can see the border with a description (instead of just "...") in the editor.
  3. Add custom code fold (collapse by default)
    1. Add property "defaultstate" to the opening mark of the custom fold from the previous test case: //<editor-fold desc="This is my code fold" defaultstate="collapsed">
    2. Close and re-open the file
    • EXPECTED RESULT:The user defined fold must be in collapsed state after you reopen the file (source code is NOT visible).
  4. Change custom code fold
    1. Expand the custom code fold you created in previous test cases
    2. Remove the ending mark and place it just behind the first comment in the file (so that opening and closing marks enclose the first comment)
    • EXPECTED RESULT: The folds must be updated and correctly repainted
  5. Remove custom code fold
    1. Remove user fold (remove both marks)
    • EXPECTED RESULT: Code fold is correctly removed and there are no painting issues.

Test suite: Overlapped or corrupted folds, edge cases

  1. Overlapped folds
    1. Create custom fold that overlap a method fold :
    2. Try to remove the custom fold
    • EXPECTED RESULT: The fold for method should be visible. Custom fold is not recognized
  2. Corrupt Custom Folds 1
    1. Insert closing mark (<tt>//</editor-fold>) in editor
    2. Insert the opening mark behind the closing one (on the same row)
    3. Cut the opening mark and move it before the closing one (on the same row)
    4. Place caret between the opening and closing mark and hit enter
    • EXPECTED RESULT: No exceptions are thrown, code folds are recognized when opening mark is placed before the closing mark.
  3. Corrupt Custom Folds 2
    1. Insert character 'a' in closing mark in order to corrupt it, for example: //</aeditor-fold>
    2. Remove the 'a' from the mark in order to fix it
    • EXPECTED RESULT: Code fold is removed when you corrupt closing mark and recreated when you fix it.
  4. Corrupt Custom Folds 3
    1. Add 4 closing marks to the Java file:
    2. Add the opening marks before them using copy&paste:
    3. Add user fold with the same name at end of file :
    • EXPECTED RESULT: All folds must be recognized and collapsable. It is possible have more user defined folds with the same description (desc).
  5. Comments after block
    1. Add a comment behind a method's body (on the same row), like this "... } // my comment and collapse the method using the [-] sign
    • EXPECTED RESULT: The comment is visible when the code fold is collapsed.
  6. Two methods on the same line
    1. Add two methods on the same row, e.g. void aaa() { } void bbb() { }
    2. Try to collapse the code fold on the row
    • EXPECTED RESULT: Only the second method should be collapsed. A method can't be collapsed when there is another method on the same row.
  7. JavaDoc / Normal comment
    1. Remove the leading star from the beginning of a JavaDoc comment, so that Javadoc comment /** ... */ becomes normal comment /* ... */
    2. Add the star back to the comment so that it becomes a JavaDoc again
    3. Try to remove the beginning and end of a JavaDoc comment (/** and */)
    • EXPECTED RESULT:Code fold should be present only for JavaDoc comment, it has to disappear when JavaDoc comment becomes a normal comment and the other way around

Test suite: Miscellaneous

  1. Deleting when CF is collapsed
    1. Have a collapsed code fold
    2. Move the caret in front of the collapsed fold and hit Delete key
    3. Undo the last change and collapse the code fold again
    4. Move the caret behind the collapsed fold and hit Backspace key
    • EXPECTED RESULT: Code fold must be expanded when you press Delete/Backspace and the first/last character of the code inside the code fold must be removed
  2. Interaction with Surrounding Features 1 - Basic
    1. Check that showing/hiding line numbers (View|Show Line Numbers) this has no affect to CF
    2. Move caret before collapsed code fold (before the code fold mark, which is the border with "..." or with description)
    3. Move the caret over the CF mark and back using and keys
    4. Select collapsed code fold mark by keyboard (place caret just before CF mark, hold Shift and press )
    5. Press Delete to erase the content of the code fold and to remove the code fold
    6. Undo (Ctrl+Z) the last operation to restore the content and code folds
    • EXPECTED RESULT: The caret must be moved over the mark the same way as over a character. You can delete and restore whole code fold.
  3. Interactions with Surrounding Features 2 - Bookmarks
    1. Place a bookmark in a method
    2. Collapse the method
    3. Reach the bookmark by "Next Bookmark" action
    • EXPECTED RESULT: Fold must be expanded and caret placed on the bookmark
  4. Interactions with Surrounding Features 3 - Breakpoints
    1. Place breakpoint in a method
    2. Collapse the method fold
    3. Reach the breakpoint by a debugger session
    • EXPECTED RESULT:
      - The breakpoint is not visible when the method containing it is collapsed.
      - The code fold must be expanded when debugger session reaches it.
  5. Interactions with Surrounding Features 4 - Find & Replace
    1. Search for a text that is inside some folded code
    2. Try to replace some text that is inside collapsed fold
    • EXPECTED RESULT: If search finds the string inside collapsed fold, that fold is expanded
  6. Background/Foreground color
    1. Invoke Tools|Options|Fonts&Colors|Highlighting
    2. Select "Code Folding" in Category list and change background and foreground color settings
    3. Select "Code Folding Bar" in Category list and change background and foreground color settings
    4. Confirm the Options dialog with OK button
    • EXPECTED RESULT: Colors for collapsed code fold and for the [+]/[-] signs must respect settings.
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