<commit_before>/**
 * Copyright (c) 2014 SQUARESPACE, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.squarespace.template.plugins;

import static com.squarespace.template.Constants.EMPTY_ARGUMENTS;
import static com.squarespace.template.plugins.CorePredicates.EQUAL;
import static com.squarespace.template.plugins.CorePredicates.EVEN;
import static com.squarespace.template.plugins.CorePredicates.GREATER_THAN;
import static com.squarespace.template.plugins.CorePredicates.LESS_THAN;
import static com.squarespace.template.plugins.CorePredicates.LESS_THAN_OR_EQUAL;
import static com.squarespace.template.plugins.CorePredicates.ODD;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.squarespace.template.Arguments;
import com.squarespace.template.CodeException;
import com.squarespace.template.CodeMaker;
import com.squarespace.template.Constants;
import com.squarespace.template.Context;
import com.squarespace.template.Predicate;
import com.squarespace.template.UnitTestBase;


public class CorePredicatesTest extends UnitTestBase {

  @Test
  public void testDebug() throws CodeException {
    String[] key = new String[] { "a", "b" };
    Context ctx = context("{\"debug\": true, \"a\": {\"b\": 1}}");
    ctx.pushSection(key);
    assertTrue(CorePredicates.DEBUG, ctx);

    for (String json : new String[] {
        "{\"a\": {\"b\": 1}}",
        "{\"debug\": 0, \"a\": {\"b\": 1}}" }) {
      ctx = context(json);
      ctx.pushSection(key);
      assertFalse(CorePredicates.DEBUG, ctx);  }
    }

  @Test
  public void testEquals() throws CodeException {
    CodeMaker mk = maker();
    assertTrue(EQUAL, context("3"), mk.args(" 3"));
    assertTrue(EQUAL, context("\"hello\""), mk.args(" \"hello\""));
    assertTrue(EQUAL, context("[1, 2, 3]"), mk.args(":[1, 2, 3]"));

    assertFalse(EQUAL, context("-1"), mk.args(" 3"));
    assertFalse(EQUAL, context("\"hello\""), mk.args(" \"goodbye\""));
    assertFalse(EQUAL, context("[1, 2, 3]"), mk.args(":1"));
  }

  @Test
  public void testEven() throws CodeException {
    assertTrue(EVEN, context("4"));
    assertTrue(EVEN, context("-4"));<commit_msg>[style] Consistent naming.<commit_after>/**
 * Copyright (c) 2014 SQUARESPACE, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.squarespace.template.plugins;

import static com.squarespace.template.Constants.EMPTY_ARGUMENTS;
import static com.squarespace.template.plugins.CorePredicates.EQUAL;
import static com.squarespace.template.plugins.CorePredicates.EVEN;
import static com.squarespace.template.plugins.CorePredicates.GREATER_THAN;
import static com.squarespace.template.plugins.CorePredicates.LESS_THAN;
import static com.squarespace.template.plugins.CorePredicates.LESS_THAN_OR_EQUAL;
import static com.squarespace.template.plugins.CorePredicates.ODD;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.squarespace.template.Arguments;
import com.squarespace.template.CodeException;
import com.squarespace.template.CodeMaker;
import com.squarespace.template.Constants;
import com.squarespace.template.Context;
import com.squarespace.template.Predicate;
import com.squarespace.template.UnitTestBase;


public class CorePredicatesTest extends UnitTestBase {

  @Test
  public void testDebug() throws CodeException {
    String[] key = new String[] { "a", "b" };
    Context ctx = context("{\"debug\": true, \"a\": {\"b\": 1}}");
    ctx.pushSection(key);
    assertTrue(CorePredicates.DEBUG, ctx);

    for (String json : new String[] {
        "{\"a\": {\"b\": 1}}",
        "{\"debug\": 0, \"a\": {\"b\": 1}}" }) {
      ctx = context(json);
      ctx.pushSection(key);
      assertFalse(CorePredicates.DEBUG, ctx);  }
    }

  @Test
  public void testEqual() throws CodeException {
    CodeMaker mk = maker();
    assertTrue(EQUAL, context("3"), mk.args(" 3"));
    assertTrue(EQUAL, context("\"hello\""), mk.args(" \"hello\""));
    assertTrue(EQUAL, context("[1, 2, 3]"), mk.args(":[1, 2, 3]"));

    assertFalse(EQUAL, context("-1"), mk.args(" 3"));
    assertFalse(EQUAL, context("\"hello\""), mk.args(" \"goodbye\""));
    assertFalse(EQUAL, context("[1, 2, 3]"), mk.args(":1"));
  }

  @Test
  public void testEven() throws CodeException {
    assertTrue(EVEN, context("4"));
    assertTrue(EVEN, context("-4"));
{'fraction_non_alphanumeric': 0.1454578889297536, 'fraction_numerical': 0.010297903641044501, 'mean_word_length': 4.406560636182903, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5045359', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1665, 'n_words': 439}