2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstccl.c,v 1.10 2006-01-29 21:59:13 adam Exp $
19 static struct ccl_tst query_str[] = {
20 { "x1", "@attr 4=2 @attr 1=1016 x1 "},
21 { "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "},
22 {"x1 and x2", "@and @attr 4=2 @attr 1=1016 x1 @attr 4=2 @attr 1=1016 x2 "},
23 { "ti=x3", "@attr 4=2 @attr 1=4 x3 "},
24 { "dc.title=x4", "@attr 1=/my/title x4 "},
27 { "spid%æserne", "@prox 0 1 0 2 k 2 @attr 4=2 @attr 1=1016 spid @attr 4=2 @attr 1=1016 æserne "},
28 { "date=1980", "@attr 2=3 1980 "},
29 { "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
30 { "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
31 { "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
32 { "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
33 { "date=-1980", "@attr 2=2 1980 "},
34 { "date=- 1980", "@attr 2=2 1980 "},
35 { "x=-1980", "@attr 2=3 -1980 "},
36 { "x=- 1980", "@attr 2=2 1980 "},
37 { "x= -1980", "@attr 2=3 -1980 "},
38 { "x=234-1990", "@attr 2=3 234-1990 "},
39 { "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
40 { "ti=a,b", "@attr 4=1 @attr 1=4 a,b "},
41 { "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "},
42 { "ti=a-b", "@attr 4=2 @attr 1=4 a-b "},
43 { "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "},
49 CCL_parser parser = ccl_parser_create ();
50 CCL_bibset bibset = ccl_qual_mk();
59 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
60 ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
61 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
62 ccl_qual_fitem(bibset, "r=r", "date");
63 ccl_qual_fitem(bibset, "r=o", "x");
66 strcpy(tstline, "ti u=4 s=pw t=l,r");
67 ccl_qual_line(bibset, tstline);
69 strcpy(tstline, "term 1=1016 s=al,pw # default term");
70 ccl_qual_line(bibset, tstline);
72 strcpy(tstline, "dc.title 1=/my/title");
73 ccl_qual_line(bibset, tstline);
75 strcpy(tstline, "date r=r # ordered relation");
76 ccl_qual_line(bibset, tstline);
78 strcpy(tstline, "x r=o # ordered relation");
79 ccl_qual_line(bibset, tstline);
82 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
83 "term 1=1016 s=al,pw\r\n"
85 "dc.title 1=/my/title\n"
94 parser->bibset = bibset;
96 for (i = 0; query_str[i].query; i++)
98 struct ccl_token *token_list;
99 struct ccl_rpn_node *rpn;
101 token_list = ccl_parser_tokenize(parser, query_str[i].query);
102 rpn = ccl_parser_find(parser, token_list);
103 ccl_token_del (token_list);
106 /* parse ok. check that result is there and match */
107 WRBUF wrbuf = wrbuf_alloc();
108 ccl_pquery(wrbuf, rpn);
110 /* check expect a result and that it matches */
111 YAZ_CHECK(query_str[i].result);
112 if (query_str[i].result)
114 YAZ_CHECK(!strcmp(wrbuf_buf(wrbuf), query_str[i].result));
117 wrbuf_free(wrbuf, 1);
121 /* parse failed. So we expect no result either */
122 YAZ_CHECK(!query_str[i].result);
125 ccl_parser_destroy (parser);
126 ccl_qual_rm(&bibset);
129 int main(int argc, char **argv)
131 YAZ_CHECK_INIT(argc, argv);
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab