<commit_before>package edu.oregonstate.mutation.statementHistory

import org.eclipse.jdt.core.dom.ASTNode
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.revwalk.RevCommit

/**
 * Created by caius on 2/11/16.
 */
class StatementInfoTest extends GitTest {

  private val FILE_NAME = "A.java"

  def makeClass(block: String): String = {
    "public class A{\npublic void m(){\n" + block + "\n{\nint x=3;}}}"
  }

  def find(commit: RevCommit): ASTNode = {
    BlockFinder.findNode(Git.open(repo), commit.getName, FILE_NAME, 4)
  }

  it should "have the correct info for a if block" in {
    val node = find(add(FILE_NAME, makeClass("if(true)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,if(4:5),")
  }

  it should "have the correct info for a while block" in {
    val node = find(add(FILE_NAME, makeClass("while(true)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,while(4:5),")
  }

  it should "have the correct info for a for block" in {
    val node = find(add(FILE_NAME, makeClass("for(int i=0;i<10;i++)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,for(4:5),")
  }

  it should "have the correct info for an enhanced for block" in {
    val node = find(add(FILE_NAME, makeClass("for(String x:xes)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,for(4:5),")
  }

  it should "have the correct info for a try block" in {
    val node = find(add(FILE_NAME, "public class A{\npublic void m(){\ntry\n{\nint x=3;}catch(Exception e){}}}"))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,try(4:5),")
  }

  it should "have the correct info for a catch block" in {
    val commit = add(FILE_NAME, "public class A{\npublic void m(){\ntry\n{\nint x=3;}catch(Exception e){\nint y=3;}}}")
    val node = BlockFinder.findNode(Git.open(repo), commit.getName, FILE_NAME, 5)
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",5,catch(5:6),")
  }

  it should "have the correct info for a method body" in {<commit_msg>Added test for do-while.<commit_after>package edu.oregonstate.mutation.statementHistory

import org.eclipse.jdt.core.dom.{Block, DoStatement, VariableDeclarationStatement, ASTNode}
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.revwalk.RevCommit

/**
 * Created by caius on 2/11/16.
 */
class StatementInfoTest extends GitTest {

  private val FILE_NAME = "A.java"

  def makeClass(block: String): String = {
    "public class A{\npublic void m(){\n" + block + "\n{\nint x=3;}}}"
  }

  def find(commit: RevCommit): ASTNode = {
    BlockFinder.findNode(Git.open(repo), commit.getName, FILE_NAME, 4)
  }

  it should "have the correct info for a if block" in {
    val node = find(add(FILE_NAME, makeClass("if(true)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,if(4:5),")
  }

  it should "have the correct info for a while block" in {
    val node = find(add(FILE_NAME, makeClass("while(true)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,while(4:5),")
  }

  it should "have the correct info for a for block" in {
    val node = find(add(FILE_NAME, makeClass("for(int i=0;i<10;i++)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,for(4:5),")
  }

  it should "have the correct info for an enhanced for block" in {
    val node = find(add(FILE_NAME, makeClass("for(String x:xes)")))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,for(4:5),")
  }

  it should "have the correct info for a do-while block" in {
    val commit = add(FILE_NAME, "public class A{\npublic void m(){\ndo {\nint x=3;\n}while(true);\n}\n}")
    val node = BlockFinder.findNode(Git.open(repo), commit.getName, FILE_NAME, 4)
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",3,do(3:5),")
  }

  it should "have the correct info for a try block" in {
    val node = find(add(FILE_NAME, "public class A{\npublic void m(){\ntry\n{\nint x=3;}catch(Exception e){}}}"))
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",4,try(4:5),")
  }

  it should "have the correct info for a catch block" in {
    val commit = add(FILE_NAME, "public class A{\npublic void m(){\ntry\n{\nint x=3;}catch(Exception e){\nint y=3;}}}")
    val node = BlockFinder.findNode(Git.open(repo), commit.getName, FILE_NAME, 5)
    new StatementInfo(FILE_NAME, node).printInfo should equal (FILE_NAME + ",5,catch(5:6),")
  }

  it should "have the correct info for a method body" in {
{'fraction_non_alphanumeric': 0.14829961256995264, 'fraction_numerical': 0.01485148514851485, 'mean_word_length': 4.292710706150341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3876119', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1586, 'n_words': 452}