<commit_before>package org.oxidize

import org.oxidize.test.AbstractUnitSpec

class TemplateEngineSpec extends AbstractUnitSpec {
  "Template Engine" should "eval simple JavaScript" in {
    checkEngineRenders("@{= 1 + 2 }@", "3")
  }

  it can "do complex JS expressions" in {
    checkEngineRenders(
      """@{=
        |(function() {
        |  var A = [1, 2, 3], i, ret = 0;
        |  for (var i = 0; i < A.length; i++) {
        |    ret += A[i];
        |  };
        |  return ret;
        |})();
      }@""".stripMargin, "6")
  }

  it should "ignore the result of the statement block" in {
    checkEngineRenders("@{ 1 }@2", "2")
  }

  it should "contain an $oxidize object with a setFileName(String) method" in {
    checkEngineRenders("@{ $oxidize.setFileName('test') }@", expectedFile = "test")
  }

  it should "set variables from context" in {
    checkEngineRenders("@{= a + b }@", "46", context = Map("a" -> 12, "b" -> 34))
  }

  it should "does not convert variables from Strings to JavaScript types" in {
    checkEngineRenders("@{= a + b }@", "1234", context = Map("a" -> "12", "b" -> "34"))
  }

  private def checkEngineRenders(template: String,
                                 expectedOutput: String = "",
                                 expectedFile: String = "",
                                 context: Map[String, Any] = Map.empty) {
    val result = TemplateEngine.applyTemplate(template, new OxidizeContext(null, context))
    result.output should be(expectedOutput)
    if (!expectedFile.isEmpty)
      result.targetFile should be (expectedFile)
  }
}<commit_msg>Fix broken tests (newlines).<commit_after>package org.oxidize

import org.oxidize.test.AbstractUnitSpec

class TemplateEngineSpec extends AbstractUnitSpec {
  "Template Engine" should "eval simple JavaScript" in {
    checkEngineRenders("@{= 1 + 2 }@", "3")
  }

  it can "do complex JS expressions" in {
    checkEngineRenders(
      """@{=
        (function() {
          var A = [1, 2, 3], i, ret = 0;
          for (var i = 0; i < A.length; i++) {
            ret += A[i];
          };
          return ret;
        })();
      }@""", "6")
  }

  it should "ignore the result of the statement block" in {
    checkEngineRenders("@{ 1 }@2", "2")
  }

  it should "contain an $oxidize object with a setFileName(String) method" in {
    checkEngineRenders("@{ $oxidize.setFileName('test') }@", expectedFile = "test")
  }

  it should "set variables from context" in {
    checkEngineRenders("@{= a + b }@", "46", context = Map("a" -> 12, "b" -> 34))
  }

  it should "does not convert variables from Strings to JavaScript types" in {
    checkEngineRenders("@{= a + b }@", "1234", context = Map("a" -> "12", "b" -> "34"))
  }

  private def checkEngineRenders(template: String,
                                 expectedOutput: String = "",
                                 expectedFile: String = "",
                                 context: Map[String, Any] = Map.empty) {
    val result = TemplateEngine.applyTemplate(template, new OxidizeContext(null, context))
    result.output should be(if (expectedOutput.isEmpty) "" else expectedOutput + "\n")
    if (!expectedFile.isEmpty)
      result.targetFile should be (expectedFile)
  }
}
{'fraction_non_alphanumeric': 0.14704973741118318, 'fraction_numerical': 0.01606425702811245, 'mean_word_length': 2.4742489270386265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654540', 'n_tokens_mistral': 1024, 'n_tokens_neox': 969, 'n_words': 290}