<commit_before>package org.smoothbuild.lang.builtin.file;

import static org.smoothbuild.io.IoConstants.SMOOTH_DIR;
import static org.smoothbuild.io.cache.CacheModule.RESULTS_DIR;
import static org.smoothbuild.io.fs.base.Path.path;

import org.junit.Test;
import org.smoothbuild.io.fs.base.Path;
import org.smoothbuild.task.exec.save.err.DuplicatePathsInFileArrayArtifactError;
import org.smoothbuild.testing.integration.IntegrationTestCase;

public class ArtifactSaverSmoothTest extends IntegrationTestCase {
  private static final Path RESULTS_PATH = SMOOTH_DIR.append(RESULTS_DIR);

  Path path1 = path("def/filename1.txt");
  Path path2 = path("def/filename2.txt");
  String content1 = "some content";
  String content2 = "some content2";

  String functionName = "myFunction";

  // basic types

  @Test
  public void storing_string_artifact() throws Exception {
    // given
    script(functionName + " : '" + content1 + "' ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();
    Path artifactPath = RESULTS_PATH.append(path(functionName));
    fileSystem.assertFileContains(artifactPath, content1);
  }

  @Test
  public void storing_file_artifact() throws Exception {
    // given
    fileSystem.createFile(path1, content1);

    script(functionName + " : file(" + path1 + ") ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();
    Path artifactPath = RESULTS_PATH.append(path(functionName));
    fileSystem.assertFileContains(artifactPath, content1);
  }

  // array types

  @Test
  public void storing_string_array_artifact() throws Exception {
    // given
    script(functionName + " : [ '" + content1 + "', '" + content2 + "' ]  ;");

    // when
    build(functionName);
<commit_msg>added tests for storing Blob and Blob[] to ArtifactSaverSmoothTest<commit_after>package org.smoothbuild.lang.builtin.file;

import static org.smoothbuild.io.IoConstants.SMOOTH_DIR;
import static org.smoothbuild.io.cache.CacheModule.RESULTS_DIR;
import static org.smoothbuild.io.fs.base.Path.path;

import org.junit.Test;
import org.smoothbuild.io.fs.base.Path;
import org.smoothbuild.task.exec.save.err.DuplicatePathsInFileArrayArtifactError;
import org.smoothbuild.testing.integration.IntegrationTestCase;

public class ArtifactSaverSmoothTest extends IntegrationTestCase {
  private static final Path RESULTS_PATH = SMOOTH_DIR.append(RESULTS_DIR);

  Path path1 = path("def/filename1.txt");
  Path path2 = path("def/filename2.txt");
  String content1 = "some content";
  String content2 = "some content2";

  String functionName = "myFunction";

  // basic types

  @Test
  public void storing_string_artifact() throws Exception {
    // given
    script(functionName + " : '" + content1 + "' ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();
    Path artifactPath = RESULTS_PATH.append(path(functionName));
    fileSystem.assertFileContains(artifactPath, content1);
  }

  @Test
  public void storing_blob_artifact() throws Exception {
    // given
    fileSystem.createFile(path1, content1);

    script(functionName + " : file(" + path1 + ") | contentOf ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();
    Path artifactPath = RESULTS_PATH.append(path(functionName));
    fileSystem.assertFileContains(artifactPath, content1);
  }

  @Test
  public void storing_file_artifact() throws Exception {
    // given
    fileSystem.createFile(path1, content1);

    script(functionName + " : file(" + path1 + ") ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();
    Path artifactPath = RESULTS_PATH.append(path(functionName));
    fileSystem.assertFileContains(artifactPath, content1);
  }

  // array types

  @Test
  public void storing_string_array_artifact() throws Exception {
    // given
    script(functionName + " : [ '" + content1 + "', '" + content2 + "' ]  ;");

    // when
    build(functionName);

    // then
    userConsole.assertNoProblems();

    Path dirPath = RESULTS_PATH.append(path(functionName));
    Path artifact1Path = dirPath.append(path("0"));
    Path artifact2Path = dirPath.append(path("1"));

    fileSystem.assertFileContains(artifact1Path, content1);
    fileSystem.assertFileContains(artifact2Path, content2);
  }

  @Test
  public void storing_blob_array_artifact() throws Exception {
    // given
    fileSystem.createFile(path1, content1);
    fileSystem.createFile(path2, content2);

    String functionName = "myFunction";

    script(functionName + " : [ contentOf(file(" + path1 + ")) , contentOf(file(" + path2
        + ")) ] ;");

    // when
    build(functionName);

{'fraction_non_alphanumeric': 0.12081390419669351, 'fraction_numerical': 0.010173802458668928, 'mean_word_length': 3.9054054054054053, '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': '1698486', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1395, 'n_words': 270}