Skip to content

Commit

Permalink
Testing: is_in_list expression
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Jan 10, 2024
1 parent 21a7625 commit ea84ba6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/grib_expression_class_is_in_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
grib_expression_is_in_list* e = (grib_expression_is_in_list*)g;
int err = 0;
char mybuf[1024] = {0,};
size_t size = 1024;
return GRIB_NOT_IMPLEMENTED;
// grib_expression_is_in_list* e = (grib_expression_is_in_list*)g;
// int err = 0;
// 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)
return err;
// if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS)
// return err;

if (grib_trie_get(list, mybuf))
*result = 1;
else
*result = 0;
// if (grib_trie_get(list, mybuf))
// *result = 1;
// else
// *result = 0;

return err;
// return err;
}

static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err)
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ if( HAVE_BUILD_TOOLS )
grib_ifsParam
grib_packing_order
filter_substr
filter_is_in_list
filter_transient_darray
grib_uerra
grib_ecpoint
Expand Down
45 changes: 45 additions & 0 deletions tests/filter_is_in_list.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea84ba6

Please sign in to comment.