<commit_before>/*******************************************************************************
his file is part of Pebble.
 *
 * Copyright (c) 2014 by <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 ******************************************************************************/
package com.mitchellbosecke.pebble;

import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.loader.Loader;
import com.mitchellbosecke.pebble.loader.StringLoader;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.junit.Test;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;

import static org.junit.Assert.assertEquals;

public class CoreTagsTest extends AbstractTest {

	@Test
	public void testBlock() throws PebbleException, IOException {
		PebbleTemplate template = pebble.getTemplate("template.grandfather.peb");
		Writer writer = new StringWriter();
		template.evaluate(writer);
	}

	/**
	 * This ensures that block inheritance works properly even if it skips a
	 * generation.
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void skipGenerationBlock() throws PebbleException, IOException {
		PebbleTemplate template = pebble.getTemplate("template.skipGenerationBlock1.peb");
		Writer writer = new StringWriter();
		template.evaluate(writer);
		assertEquals("success", writer.toString());
	}

	@Test
	public void testIf() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if false or steve == true  %}yes{% else %}no{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);

		Map<String, Object> context = new HashMap<>();
		context.put("yes", true);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("no", writer.toString());
	}

	/**
	 * Issue #34
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void testIfThenElse() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if alpha %}alpha{% elseif beta %}beta{% else %}gamma{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);

		Map<String, Object> context = new HashMap<>();
		context.put("alpha", true);
		context.put("beta", false);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("alpha", writer.toString());
	}

	@Test
	public void testIfThenElse() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if alpha %}alpha{% elseif beta %}beta{% else %}gamma{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);

		Map<String, Object> context = new HashMap<>();
		context.put("alpha", true);
		context.put("beta", false);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("alpha", writer.toString());
	}

	@Test
	public void testIfWithDirectProperty() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if variable %}yes{% else %}no{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);
		Map<String, Object> context = new HashMap<>();
		context.put("variable", true);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("yes", writer.toString());
	}

	/**
	 * Issue #37
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void testIfTestAgainstNullVar() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);<commit_msg>remove duplicate test added during PR merges<commit_after>/*******************************************************************************
his file is part of Pebble.
 *
 * Copyright (c) 2014 by <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 ******************************************************************************/
package com.mitchellbosecke.pebble;

import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.loader.Loader;
import com.mitchellbosecke.pebble.loader.StringLoader;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.junit.Test;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;

import static org.junit.Assert.assertEquals;

public class CoreTagsTest extends AbstractTest {

	@Test
	public void testBlock() throws PebbleException, IOException {
		PebbleTemplate template = pebble.getTemplate("template.grandfather.peb");
		Writer writer = new StringWriter();
		template.evaluate(writer);
	}

	/**
	 * This ensures that block inheritance works properly even if it skips a
	 * generation.
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void skipGenerationBlock() throws PebbleException, IOException {
		PebbleTemplate template = pebble.getTemplate("template.skipGenerationBlock1.peb");
		Writer writer = new StringWriter();
		template.evaluate(writer);
		assertEquals("success", writer.toString());
	}

	@Test
	public void testIf() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if false or steve == true  %}yes{% else %}no{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);

		Map<String, Object> context = new HashMap<>();
		context.put("yes", true);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("no", writer.toString());
	}

	/**
	 * Issue #34
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void testIfThenElse() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if alpha %}alpha{% elseif beta %}beta{% else %}gamma{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);

		Map<String, Object> context = new HashMap<>();
		context.put("alpha", true);
		context.put("beta", false);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("alpha", writer.toString());
	}

	@Test
	public void testIfWithDirectProperty() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);

		String source = "{% if variable %}yes{% else %}no{% endif %}";
		PebbleTemplate template = pebble.getTemplate(source);
		Map<String, Object> context = new HashMap<>();
		context.put("variable", true);

		Writer writer = new StringWriter();
		template.evaluate(writer, context);
		assertEquals("yes", writer.toString());
	}

	/**
	 * Issue #36
	 *
	 * @throws PebbleException
	 * @throws IOException
	 */
	@Test
	public void testIfTestAgainstNullVar() throws PebbleException, IOException {
		Loader loader = new StringLoader();
		PebbleEngine pebble = new PebbleEngine(loader);
		pebble.setStrictVariables(false);
{'fraction_non_alphanumeric': 0.15522917194226388, 'fraction_numerical': 0.002279057989364396, 'mean_word_length': 5.2640761300555114, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5323083', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2231, 'n_words': 608}