<commit_before>package core.framework.impl.template;

import core.framework.api.util.ClasspathResources;
import core.framework.api.util.Lists;
import core.framework.impl.template.source.TemplateSource;
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

/**
 * @author neo
 */
public class HTMLTemplateTest {
    @Test
    public void process() {
        HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new TestTemplateSource("template-test/template.html"), TestModel.class);
        builder.message = key -> Optional.of(key + "_value");
        HTMLTemplate template = builder.build();

        TestModel model = new TestModel();
        model.stringField = "string<";
        model.numberField = 100;
        model.items.addAll(Lists.newArrayList("a", "b", "c"));
        model.children.add(child("child1", 1.0, true));
        model.children.add(child("child2", 2.0, false));
        model.htmlField = "<pre>html</pre>";

        String result = template.process(new TemplateContext(model));

        Assert.assertEquals(ClasspathResources.text("template-test/template-result.html").replaceAll("\r\n", "\n"), result);
    }

    private TestModelChild child(String stringField, Double doubleField, Boolean booleanField) {
        TestModelChild child = new TestModelChild();
        child.stringField = stringField;
        child.doubleField = doubleField;
        child.booleanField = booleanField;
        return child;<commit_msg>* template: fix template engine with c:src in String template<commit_after>package core.framework.impl.template;

import core.framework.api.util.ClasspathResources;
import core.framework.api.util.Lists;
import core.framework.impl.template.source.TemplateSource;
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

/**
 * @author neo
 */
public class HTMLTemplateTest {
    @Test
    public void process() {
        HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new TestTemplateSource("template-test/template.html"), TestModel.class);
        builder.message = key -> Optional.of(key + "_value");
        HTMLTemplate template = builder.build();

        TestModel model = new TestModel();
        model.stringField = "string<";
        model.numberField = 100;
        model.items.addAll(Lists.newArrayList("a", "b", "c"));
        model.children.add(child("child1", 1.0, true));
        model.children.add(child("child2", 2.0, false));
        model.htmlField = "<pre>html</pre>";

        String result = template.process(new TemplateContext(model, new CDNManager()));

        Assert.assertEquals(ClasspathResources.text("template-test/template-result.html").replaceAll("\r\n", "\n"), result);
    }

    private TestModelChild child(String stringField, Double doubleField, Boolean booleanField) {
        TestModelChild child = new TestModelChild();
        child.stringField = stringField;
        child.doubleField = doubleField;
        child.booleanField = booleanField;
        return child;
{'fraction_non_alphanumeric': 0.12733333333333333, 'fraction_numerical': 0.006, 'mean_word_length': 3.5746951219512195, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1465272', 'n_tokens_mistral': 828, 'n_tokens_neox': 802, 'n_words': 174}