<commit_before>/*
// Licensed to <NAME> under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership.
//
// <NAME> licenses this file to you 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 net.hydromatic.optiq.test;

import net.hydromatic.optiq.runtime.SqlFunctions;
import net.hydromatic.optiq.runtime.Utilities;

import junit.framework.TestCase;

import java.util.*;

import static net.hydromatic.optiq.runtime.SqlFunctions.*;

/**
 * Unit test for the methods in {@link SqlFunctions} that implement SQL
 * functions.
 */
public class SqlFunctionsTest extends TestCase {
    public void testCharLength() {
        assertEquals((Integer) 3, charLength("xyz"));
    }

    public void testConcat() {
        assertEquals("a bcd", concat("a b", "cd"));
        // The code generator will ensure that nulls are never passed in. If we
        // pass in null, it is treated like the string "null", as the following
        // tests show. Not the desired behavior for SQL.
        assertEquals("anull", concat("a", null));
        assertEquals("nullnull", concat(null, null));
        assertEquals("nullb", concat(null, "b"));
    }

    public void testLower() {
        assertEquals("a bcd", lower("A bCd"));
    }

    public void testUpper() {
        assertEquals("A BCD", upper("A bCd"));
    }

    public void testInitcap() {
        assertEquals("Aa", initcap("aA"));
        assertEquals("Zz", initcap("zz"));
        assertEquals("Az", initcap("AZ"));
        assertEquals("Try A Little  ", initcap("tRy a littlE  "));
        assertEquals("Won'T It?No", initcap("won't it?no"));
        assertEquals("1a", initcap("1A"));
        assertEquals(" B0123b", initcap(" b0123B"));
    }

    public void testLesser() {
        assertEquals("a", lesser("a", "bc"));
        assertEquals("ac", lesser("bc", "ac"));
        try {
            Object o = lesser("a", null);
            fail("Expected NPE, got " + o);
        } catch (NullPointerException e) {
            // ok
        }
        assertEquals("a", lesser(null, "a"));
        assertNull(lesser(null, null));
    }

    public void testGreater() {
        assertEquals("bc", greater("a", "bc"));
        assertEquals("bc", greater("bc", "ac"));
        try {
            Object o = greater("a", null);
            fail("Expected NPE, got " + o);
        } catch (NullPointerException e) {
            // ok
        }
        assertEquals("a", greater(null, "a"));
        assertNull(greater(null, null));
    }

    /** Test for {@link SqlFunctions#rtrim}. */
    public void testRtrim() {
        assertEquals("", rtrim(""));
        assertEquals("", rtrim("    "));
        assertEquals("   x", rtrim("   x  "));
        assertEquals("   x", rtrim("   x "));
        assertEquals("   x y", rtrim("   x y "));
        assertEquals("   x", rtrim("   x"));
        assertEquals("x", rtrim("x"));
    }

    /** Test for {@link SqlFunctions#ltrim}. */
    public void testLtrim() {
        assertEquals("", ltrim(""));
        assertEquals("", ltrim("    "));
        assertEquals("x  ", ltrim("   x  "));
        assertEquals("x ", ltrim("   x "));
        assertEquals("x y ", ltrim("x y "));
        assertEquals("x", ltrim("   x"));
        assertEquals("x", ltrim("x"));
    }<commit_msg>Fix for JDK 1.6.<commit_after>/*
// Licensed to <NAME> under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership.
//
// <NAME> licenses this file to you 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 net.hydromatic.optiq.test;

import net.hydromatic.optiq.runtime.SqlFunctions;
import net.hydromatic.optiq.runtime.Utilities;

import junit.framework.TestCase;

import java.util.*;

import static net.hydromatic.optiq.runtime.SqlFunctions.*;

/**
 * Unit test for the methods in {@link SqlFunctions} that implement SQL
 * functions.
 */
public class SqlFunctionsTest extends TestCase {
    public void testCharLength() {
        assertEquals((Integer) 3, charLength("xyz"));
    }

    public void testConcat() {
        assertEquals("a bcd", concat("a b", "cd"));
        // The code generator will ensure that nulls are never passed in. If we
        // pass in null, it is treated like the string "null", as the following
        // tests show. Not the desired behavior for SQL.
        assertEquals("anull", concat("a", null));
        assertEquals("nullnull", concat(null, null));
        assertEquals("nullb", concat(null, "b"));
    }

    public void testLower() {
        assertEquals("a bcd", lower("A bCd"));
    }

    public void testUpper() {
        assertEquals("A BCD", upper("A bCd"));
    }

    public void testInitcap() {
        assertEquals("Aa", initcap("aA"));
        assertEquals("Zz", initcap("zz"));
        assertEquals("Az", initcap("AZ"));
        assertEquals("Try A Little  ", initcap("tRy a littlE  "));
        assertEquals("Won'T It?No", initcap("won't it?no"));
        assertEquals("1a", initcap("1A"));
        assertEquals(" B0123b", initcap(" b0123B"));
    }

    public void testLesser() {
        assertEquals("a", lesser("a", "bc"));
        assertEquals("ac", lesser("bc", "ac"));
        try {
            Object o = lesser("a", null);
            fail("Expected NPE, got " + o);
        } catch (NullPointerException e) {
            // ok
        }
        assertEquals("a", lesser(null, "a"));
        assertNull(lesser((String) null, null));
    }

    public void testGreater() {
        assertEquals("bc", greater("a", "bc"));
        assertEquals("bc", greater("bc", "ac"));
        try {
            Object o = greater("a", null);
            fail("Expected NPE, got " + o);
        } catch (NullPointerException e) {
            // ok
        }
        assertEquals("a", greater(null, "a"));
        assertNull(greater((String) null, null));
    }

    /** Test for {@link SqlFunctions#rtrim}. */
    public void testRtrim() {
        assertEquals("", rtrim(""));
        assertEquals("", rtrim("    "));
        assertEquals("   x", rtrim("   x  "));
        assertEquals("   x", rtrim("   x "));
        assertEquals("   x y", rtrim("   x y "));
        assertEquals("   x", rtrim("   x"));
        assertEquals("x", rtrim("x"));
    }

    /** Test for {@link SqlFunctions#ltrim}. */
    public void testLtrim() {
        assertEquals("", ltrim(""));
        assertEquals("", ltrim("    "));
        assertEquals("x  ", ltrim("   x  "));
        assertEquals("x ", ltrim("   x "));
        assertEquals("x y ", ltrim("x y "));
        assertEquals("x", ltrim("   x"));
        assertEquals("x", ltrim("x"));
    }
{'fraction_non_alphanumeric': 0.15466183887236518, 'fraction_numerical': 0.004138109401267296, 'mean_word_length': 2.607276119402985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2890833', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2117, 'n_words': 695}