<commit_before>package org.smoothbuild.parse;

import static com.google.common.base.Charsets.UTF_8;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.junit.Test;
import org.smoothbuild.parse.err.SyntaxError;
import org.smoothbuild.testing.problem.TestingProblemsListener;

public class ScriptParserTest {

  @Test
  public void emptyScriptSucceeds() throws Exception {
    assertParsingSucceeds("");
  }

  @Test
  public void simpleFunctionDefinition() throws Exception {
    assertParsingSucceeds("functionA: functionB;");
  }

  @Test
  public void pipedFunctionDefinition() throws Exception {
    assertParsingSucceeds("functionA: functionB | functionC;");
  }

  @Test
  public void functionDefinitionWithoutSemicolonFails() throws Exception {
    parse("functionA : functionB ").assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void functionDefinitionWithoutBodyFails() throws Exception {
    parse("functionA : ;").assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void functionAssignedToStringLiteral() throws Exception {
    assertParsingSucceeds("functionA : \"abc\" ;");
  }

  @Test
  public void functionCallWithFunctionCallArgument() throws Exception {
    assertParsingSucceeds("functionA: functionB(param1=functionC);");
  }

  @Test
  public void functionCallWithStringLiteralArgument() throws Exception {
    assertParsingSucceeds("functionA: functionB(param1=\"abc\");");
  }

  @Test
  public void incorrectScriptFails() throws Exception {
    parse("abc").assertOnlyProblem(SyntaxError.class);
  }

  private static void assertParsingSucceeds(String scriptText) throws IOException {
    TestingProblemsListener problems = parse(scriptText);
    problems.assertNoProblems();
  }

  private static TestingProblemsListener parse(String string) throws IOException {
    TestingProblemsListener problems = new TestingProblemsListener();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(string.getBytes(UTF_8));<commit_msg>refactored ScriptParserTest to use ScriptBuilder<commit_after>package org.smoothbuild.parse;

import static com.google.common.base.Charsets.UTF_8;
import static org.smoothbuild.testing.ScriptBuilder.oneLineScript;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.junit.Test;
import org.smoothbuild.parse.err.SyntaxError;
import org.smoothbuild.testing.problem.TestingProblemsListener;

public class ScriptParserTest {

  @Test
  public void emptyScriptSucceeds() throws Exception {
    assertParsingSucceeds("");
  }

  @Test
  public void simpleFunctionDefinition() throws Exception {
    assertParsingSucceeds("functionA: functionB;");
  }

  @Test
  public void pipedFunctionDefinition() throws Exception {
    assertParsingSucceeds("functionA: functionB | functionC;");
  }

  @Test
  public void functionDefinitionWithoutSemicolonFails() throws Exception {
    parse("functionA : functionB ").assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void functionDefinitionWithoutBodyFails() throws Exception {
    parse("functionA : ;").assertOnlyProblem(SyntaxError.class);
  }

  @Test
  public void functionAssignedToStringLiteral() throws Exception {
    assertParsingSucceeds(oneLineScript("functionA : 'abc' ;"));
  }

  @Test
  public void functionCallWithFunctionCallArgument() throws Exception {
    assertParsingSucceeds("functionA: functionB(param1=functionC);");
  }

  @Test
  public void functionCallWithStringLiteralArgument() throws Exception {
    assertParsingSucceeds(oneLineScript("functionA: functionB(param1='abc');"));
  }

  @Test
  public void incorrectScriptFails() throws Exception {
    parse("abc").assertOnlyProblem(SyntaxError.class);
  }

  private static void assertParsingSucceeds(String scriptText) throws IOException {
    TestingProblemsListener problems = parse(scriptText);
    problems.assertNoProblems();
  }

  private static TestingProblemsListener parse(String string) throws IOException {
    TestingProblemsListener problems = new TestingProblemsListener();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(string.getBytes(UTF_8));
{'fraction_non_alphanumeric': 0.09220716360116167, 'fraction_numerical': 0.001936108422071636, 'mean_word_length': 5.6877022653721685, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4148645', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1129, 'n_words': 238}