<commit_before>package org.jetbrains.plugins.ideavim.extension.commentary;

import org.jetbrains.plugins.ideavim.JavaVimTestCase;

import static com.maddyhome.idea.vim.command.CommandState.Mode.COMMAND;
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;

/**
 * @author dhleong
 */
public class CommentaryExtensionTest extends JavaVimTestCase {

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    enableExtensions("commentary");
  }

  // |gc| |l|
  public void testBlockCommentSingle() {
    doTest(parseKeys("gcll"),
           "<caret>if (condition) {\n" + "}\n",
           "/<caret>*i*/f (condition) {\n" + "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }


  // |gc| |iw|
  public void testBlockCommentInnerWord() {
    doTest(parseKeys("gciw"),
           "<caret>if (condition) {\n" + "}\n",
           "<caret>/*if*/ (condition) {\n" + "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gc| |iw|
  public void testBlockCommentTillForward() {
    doTest(parseKeys("gct{"),
           "<caret>if (condition) {\n" + "}\n",
           "<caret>/*if (condition) */{\n" + "}\n");
  }

  // |gc| |ab|
  public void testBlockCommentOuterParens() {
    doTest(parseKeys("gcab"),
           "if (<caret>condition) {\n" + "}\n",
           "if /*(condition)*/ {\n" + "}\n");
  }

  /*
   * NB: linewise motions become linewise comments;
   *  otherwise, they are incredibly difficult to undo
   */

  // |gc| |j|
  public void testLineCommentDown() {
    doTest(parseKeys("gcj"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineCommentInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineCommentSingleLineInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>if (condition) {}",
           "//if (condition) {}");
  }

  /* Ensure uncommenting works as well */

  // |gc| |ip|
  public void testLineUncommentInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>//if (condition) {\n" + "//}\n",
           "if (condition) {\n" +
           "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gc| |ip|
  public void testLineUncommentSingleLineInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>//if (condition) {}",
           "if (condition) {}");
  }

  /* Visual mode */

  // |gc| |ip|
  public void testLineCommentVisualInnerParagraph() {
    doTest(parseKeys("vipgc"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineUncommentVisualInnerParagraph() {
    doTest(parseKeys("vipgc"),
           "<caret>//if (condition) {\n" + "//}\n",
           "if (condition) {\n" +
           "}\n");
  }




  /* Special shortcut gcc is always linewise */

  // |gcc|
  public void testLineCommentShortcut() {
    doTest(parseKeys("gccj"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "<caret>}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gcc|
  public void testLineUncommentShortcut() {
    doTest(parseKeys("gcc"),
           "<caret>//if (condition) {\n" + "}\n",
           "<caret>if (condition) {\n" +
           "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }
}<commit_msg>Add an HTML filetype test<commit_after>package org.jetbrains.plugins.ideavim.extension.commentary;

import com.intellij.ide.highlighter.HtmlFileType;
import org.jetbrains.plugins.ideavim.JavaVimTestCase;

import static com.maddyhome.idea.vim.command.CommandState.Mode.COMMAND;
import static com.maddyhome.idea.vim.helper.StringHelper.parseKeys;

/**
 * @author dhleong
 */
public class CommentaryExtensionTest extends JavaVimTestCase {

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    enableExtensions("commentary");
  }

  // |gc| |l|
  public void testBlockCommentSingle() {
    doTest(parseKeys("gcll"),
           "<caret>if (condition) {\n" + "}\n",
           "/<caret>*i*/f (condition) {\n" + "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }


  // |gc| |iw|
  public void testBlockCommentInnerWord() {
    doTest(parseKeys("gciw"),
           "<caret>if (condition) {\n" + "}\n",
           "<caret>/*if*/ (condition) {\n" + "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gc| |iw|
  public void testBlockCommentTillForward() {
    doTest(parseKeys("gct{"),
           "<caret>if (condition) {\n" + "}\n",
           "<caret>/*if (condition) */{\n" + "}\n");
  }

  // |gc| |ab|
  public void testBlockCommentOuterParens() {
    doTest(parseKeys("gcab"),
           "if (<caret>condition) {\n" + "}\n",
           "if /*(condition)*/ {\n" + "}\n");
  }

  /*
   * NB: linewise motions become linewise comments;
   *  otherwise, they are incredibly difficult to undo
   */

  // |gc| |j|
  public void testLineCommentDown() {
    doTest(parseKeys("gcj"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineCommentInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineCommentSingleLineInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>if (condition) {}",
           "//if (condition) {}");
  }

  /* Ensure uncommenting works as well */

  // |gc| |ip|
  public void testLineUncommentInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>//if (condition) {\n" + "//}\n",
           "if (condition) {\n" +
           "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gc| |ip|
  public void testLineUncommentSingleLineInnerParagraph() {
    doTest(parseKeys("gcip"),
           "<caret>//if (condition) {}",
           "if (condition) {}");
  }

  /* Visual mode */

  // |gc| |ip|
  public void testLineCommentVisualInnerParagraph() {
    doTest(parseKeys("vipgc"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "//}\n");
  }

  // |gc| |ip|
  public void testLineUncommentVisualInnerParagraph() {
    doTest(parseKeys("vipgc"),
           "<caret>//if (condition) {\n" + "//}\n",
           "if (condition) {\n" +
           "}\n");
  }




  /* Special shortcut gcc is always linewise */

  // |gcc|
  public void testLineCommentShortcut() {
    doTest(parseKeys("gccj"),
           "<caret>if (condition) {\n" + "}\n",
           "//if (condition) {\n" +
           "<caret>}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gcc|
  public void testLineUncommentShortcut() {
    doTest(parseKeys("gcc"),
           "<caret>//if (condition) {\n" + "}\n",
           "<caret>if (condition) {\n" +
           "}\n");
    assertMode(COMMAND);
    assertSelection(null);
  }

  // |gcc|
  public void testHTMLCommentShortcut() {
    myFixture.configureByText(HtmlFileType.INSTANCE, "<div />");
    typeText(parseKeys("gcc"));
    myFixture.checkResult("<!--<div />-->");
    assertMode(COMMAND);
    assertSelection(null);
  }
}
{'fraction_non_alphanumeric': 0.1944069170494461, 'fraction_numerical': 0.0, 'mean_word_length': 2.4368616527390903, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206629', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2531, 'n_words': 482}