<commit_before>#include <stdlib.h>
#include <yaz/pquery.h>
#include <yaz/proto.h>

/** \brief build a 100 level query */
void test1()
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    char qstr[10000];
    int i;

    *qstr = '\0';
    for (i = 0; i<100; i++)
        strcat(qstr, "@and 1 ");
    strcat(qstr, "1");

    rpn_query = yaz_pqf_parse (parser, odr, qstr);

    if (!rpn_query)
        exit(1);

    if (!z_RPNQuery(odr, &rpn_query, 0, 0))
    {
        odr_perror(odr, "Encoding query");
        exit(1);
    }

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

/** \brief build a circular referenced query */
void test2()
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;

    rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");

    if (!rpn_query)
        exit(1);

    /* make a bad recursive refernce */
    rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;

    if (!z_RPNQuery(odr, &rpn_query, 0, 0))
        odr_perror(odr, "Encoding query");

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

int main(int argc, char **argv)
{<commit_msg>Make test fail if circular refenced ODR does not fail<commit_after>#include <stdlib.h>
#include <yaz/pquery.h>
#include <yaz/proto.h>

/** \brief build a 100 level query */
void test1()
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    char qstr[10000];
    int i;

    *qstr = '\0';
    for (i = 0; i<100; i++)
        strcat(qstr, "@and 1 ");
    strcat(qstr, "1");

    rpn_query = yaz_pqf_parse (parser, odr, qstr);

    if (!rpn_query)
        exit(1);

    if (!z_RPNQuery(odr, &rpn_query, 0, 0))
    {
        odr_perror(odr, "Encoding query");
        exit(1);
    }

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

/** \brief build a circular referenced query */
void test2()
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;

    rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");

    if (!rpn_query)
        exit(1);

    /* make the circular reference */
    rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;

    if (z_RPNQuery(odr, &rpn_query, 0, 0))  /* should fail */
        exit(2);

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}

int main(int argc, char **argv)
{
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.020531400966183576, 'mean_word_length': 2.9319620253164556, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '7443186', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1016, 'n_words': 222}