1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
10 #include <yaz/wrbuf.h>
16 static int tst_query(const char *cql, const char *expected_ccl)
19 CQL_parser cp = cql_parser_create();
20 int r = cql_parser_string(cp, cql);
24 yaz_log(YLOG_WARN, "cql: parse error: %s", cql);
28 WRBUF w = wrbuf_alloc();
29 r = cql_to_ccl(cql_parser_result(cp), wrbuf_vp_puts, w);
31 if (expected_ccl && r == 0 && strcmp(wrbuf_cstr(w), expected_ccl) == 0)
35 else if (!expected_ccl)
38 ret = 1; /* expected conversion error, OK */
40 yaz_log(YLOG_WARN, "cql: expected conversion error: %s", cql);
44 yaz_log(YLOG_WARN, "cql: diff: %s", cql);
45 yaz_log(YLOG_WARN, " expected %s", expected_ccl);
46 yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(w));
50 cql_parser_destroy(cp);
56 YAZ_CHECK(tst_query("\"\"", "\"\""));
57 YAZ_CHECK(tst_query("x", "\"x\""));
58 YAZ_CHECK(tst_query("\"x\"", "\"x\""));
59 YAZ_CHECK(tst_query("\"xy\"", "\"xy\""));
61 YAZ_CHECK(tst_query("?", "#"));
62 YAZ_CHECK(tst_query("?a?", "#\"a\"#"));
63 YAZ_CHECK(tst_query("?a", "#\"a\""));
64 YAZ_CHECK(tst_query("a?", "\"a\"#"));
65 YAZ_CHECK(tst_query("\"?\"", "#"));
66 YAZ_CHECK(tst_query("\\?", "\"?\""));
67 YAZ_CHECK(tst_query("\"\\?\"", "\"?\""));
69 YAZ_CHECK(tst_query("*", "?"));
70 YAZ_CHECK(tst_query("*a*", "?\"a\"?"));
71 YAZ_CHECK(tst_query("*a", "?\"a\""));
72 YAZ_CHECK(tst_query("a*", "\"a\"?"));
73 YAZ_CHECK(tst_query("\"*\"", "?"));
74 YAZ_CHECK(tst_query("\\*", "\"*\""));
75 YAZ_CHECK(tst_query("\"\\*\"", "\"*\""));
77 YAZ_CHECK(tst_query("a b", "\"a\" \"b\""));
78 YAZ_CHECK(tst_query("ab bc", "\"ab\" \"bc\""));
80 YAZ_CHECK(tst_query("\\\\", "\"\\\"\""));
81 YAZ_CHECK(tst_query("\\\"", "\"\\\"\""));
83 YAZ_CHECK(tst_query("\\*", "\"*\""));
84 YAZ_CHECK(tst_query("\"\\*\"", "\"*\""));
85 YAZ_CHECK(tst_query("\\#", "\"#\""));
86 YAZ_CHECK(tst_query("\"\\#\"", "\"#\""));
88 YAZ_CHECK(tst_query("title=x", "title=\"x\""));
89 YAZ_CHECK(tst_query("title=x or author=y",
90 "(title=\"x\" or author=\"y\")"));
93 YAZ_CHECK(tst_query("title all x", "title=x"));
96 int main(int argc, char **argv)
98 YAZ_CHECK_INIT(argc, argv);
106 * c-file-style: "Stroustrup"
107 * indent-tabs-mode: nil
109 * vim: shiftwidth=4 tabstop=8 expandtab