Testing: is_in_list expression

This commit is contained in:
Shahram Najm 2024-01-10 14:43:23 +00:00
parent 21a76256ce
commit ea84ba6381
3 changed files with 59 additions and 12 deletions

View File

@ -173,22 +173,23 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* result)
static int evaluate_double(grib_expression* g, grib_handle* h, double* result) static int evaluate_double(grib_expression* g, grib_handle* h, double* result)
{ {
grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; return GRIB_NOT_IMPLEMENTED;
int err = 0; // grib_expression_is_in_list* e = (grib_expression_is_in_list*)g;
char mybuf[1024] = {0,}; // int err = 0;
size_t size = 1024; // char mybuf[1024] = {0,};
// size_t size = 1024;
grib_trie* list = load_list(h->context, g, &err); // grib_trie* list = load_list(h->context, g, &err);
if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS) // if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS)
return err; // return err;
if (grib_trie_get(list, mybuf)) // if (grib_trie_get(list, mybuf))
*result = 1; // *result = 1;
else // else
*result = 0; // *result = 0;
return err; // return err;
} }
static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err)

View File

@ -97,6 +97,7 @@ if( HAVE_BUILD_TOOLS )
grib_ifsParam grib_ifsParam
grib_packing_order grib_packing_order
filter_substr filter_substr
filter_is_in_list
filter_transient_darray filter_transient_darray
grib_uerra grib_uerra
grib_ecpoint grib_ecpoint

45
tests/filter_is_in_list.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.ctest.sh
label="filter_is_in_list_test"
temp=temp.$label.txt
sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
# Evaluate long
${tools_dir}/grib_filter - $sample <<EOF
transient a_name="#";
if (is_in_list(a_name, "boot.def")) {
print "Found";
}
EOF
# Evaluate string
${tools_dir}/grib_filter - $sample <<EOF
transient a_name="#";
transient the_cond = (is_in_list(a_name, "boot.def"));
if (the_cond) {
print "Found";
}
EOF
# Illegal cases
${tools_dir}/grib_filter - $sample 2>$temp <<EOF
transient a_name="xyz";
if (is_in_list(a_name, "existential nihilism")) {
print "Found";
}
EOF
grep -q "unable to find def file" $temp
# Clean up
rm -f $temp