<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.query.jpql.internal;

import junit.framework.TestCase;
import org.xwiki.query.jpql.internal.JPQLParser;

public class JPQLParserTest extends TestCase
{
    JPQLParser parser = new JPQLParser();

    public void testStartSpeed() throws Exception
    {
        // heat up parser engine for more accuracy test timing
        // this is needed because of much static data in the parser
        parser.parse("select a from A as a");
    }

    public void testJPQL() throws Exception
    {
        // quotes
        parser.parse("select a from A as a where a.f='str'");
        parser.parse("select a from A as a where a.f=\"str\"");

        // order by
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number");
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number desc");
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number asc");

        // member of
        parser.parse("select a from A as a where :param member of a.prop");

        // input parameters
        parser.parse("select a from A as a where a.p = ?1 or :name = a.p or ?2 member of a.p or a.p like :qwe");
    }

    public void testXWQLExtensions() throws Exception
    {<commit_msg>XWIKI-10217: ORDER BY does not work with XWQL with aggregate functions.<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.query.jpql.internal;

import junit.framework.TestCase;

public class JPQLParserTest extends TestCase
{
    JPQLParser parser = new JPQLParser();

    public void testStartSpeed() throws Exception
    {
        // heat up parser engine for more accuracy test timing
        // this is needed because of much static data in the parser
        parser.parse("select a from A as a");
    }

    public void testJPQL() throws Exception
    {
        // quotes
        parser.parse("select a from A as a where a.f='str'");
        parser.parse("select a from A as a where a.f=\"str\"");

        // order by
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number");
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number desc");
        parser.parse("select doc from Document doc, doc.object(XWiki.XWikiGroups) as g order by g.number asc");

        // Aggregate function in order by
        parser.parse("select g.name, count(g.number) from Document doc, doc.object(XWiki.XWikiGroups) as g "
                   + "group by g.name order by count(g.number)");

        // member of
        parser.parse("select a from A as a where :param member of a.prop");

        // input parameters
        parser.parse("select a from A as a where a.p = ?1 or :name = a.p or ?2 member of a.p or a.p like :qwe");
    }

    public void testXWQLExtensions() throws Exception
    {
{'fraction_non_alphanumeric': 0.08327994875080078, 'fraction_numerical': 0.007473841554559043, 'mean_word_length': 2.9762308998302207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4946691', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1256, 'n_words': 592}