2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstccl.c,v 1.11 2006-07-31 11:42:32 adam Exp $
15 static int tst_ccl_query(CCL_bibset bibset,
19 CCL_parser parser = ccl_parser_create();
24 struct ccl_token *token_list;
25 struct ccl_rpn_node *rpn;
27 parser->bibset = bibset;
29 token_list = ccl_parser_tokenize(parser, query);
30 rpn = ccl_parser_find(parser, token_list);
31 ccl_token_del(token_list);
34 /* parse ok. check that result is there and match */
35 WRBUF wrbuf = wrbuf_alloc();
36 ccl_pquery(wrbuf, rpn);
38 /* check expect a result and that it matches */
39 if (result && !strcmp(wrbuf_buf(wrbuf), result))
54 ccl_parser_destroy (parser);
60 CCL_bibset bibset = ccl_qual_mk();
70 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
71 ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
72 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
73 ccl_qual_fitem(bibset, "r=r", "date");
74 ccl_qual_fitem(bibset, "r=o", "x");
77 strcpy(tstline, "ti u=4 s=pw t=l,r");
78 ccl_qual_line(bibset, tstline);
80 strcpy(tstline, "term 1=1016 s=al,pw # default term");
81 ccl_qual_line(bibset, tstline);
83 strcpy(tstline, "dc.title 1=/my/title");
84 ccl_qual_line(bibset, tstline);
86 strcpy(tstline, "date r=r # ordered relation");
87 ccl_qual_line(bibset, tstline);
89 strcpy(tstline, "x r=o # ordered relation");
90 ccl_qual_line(bibset, tstline);
93 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
94 "term 1=1016 s=al,pw\r\n"
96 "dc.title 1=/my/title\n"
106 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
107 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
108 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
110 "@attr 4=2 @attr 1=1016 x1 "
111 "@attr 4=2 @attr 1=1016 x2 "));
112 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
113 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
114 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
115 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
117 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
119 "@attr 4=2 @attr 1=1016 a "
120 "@attr 4=2 @attr 1=1016 b "));
121 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
123 "@attr 4=2 @attr 1=1016 a "
124 "@attr 4=2 @attr 1=1016 b "));
126 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
128 "@attr 4=2 @attr 1=1016 a "
129 "@attr 4=2 @attr 1=1016 b "));
131 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
132 "@prox 0 19 0 2 k 2 "
133 "@attr 4=2 @attr 1=1016 a "
134 "@attr 4=2 @attr 1=1016 b "));
136 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
138 "@attr 4=2 @attr 1=1016 spid "
139 "@attr 4=2 @attr 1=1016 æserne "));
141 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
143 "@attr 4=2 @attr 1=1016 a "
144 "@attr 4=2 @attr 1=1016 b "));
145 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
147 "@attr 4=2 @attr 1=1016 a "
148 "@attr 4=2 @attr 1=1016 b "));
150 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
151 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
152 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
153 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
154 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
155 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
156 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
157 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
158 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
159 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
160 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
161 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
162 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
163 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "));
164 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
165 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "));
166 ccl_qual_rm(&bibset);
169 int main(int argc, char **argv)
171 YAZ_CHECK_INIT(argc, argv);
180 * indent-tabs-mode: nil
182 * vim: shiftwidth=4 tabstop=8 expandtab