Skip to content

Commit

Permalink
Ignore name_location in deparse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msepga committed Sep 27, 2024
1 parent 65002f2 commit fe1b2e1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@

#include "deparse_tests.c"

// Removes the location values from the JSON parse tree string, replacing them with nothing
// (we don't use any special replacement value to avoid increasing the string size)
void remove_node_locations(char *parse_tree_json)
void remove_numeric_key(char *parse_tree_json, char* key)
{
char *tokstart;
char *p;
size_t remaining_len;

char search[100];

sprintf(search, "\"%s\":", key);

p = parse_tree_json;
while ((p = strstr(p, "\"location\":")) != NULL)
while ((p = strstr(p, search)) != NULL)
{
tokstart = p;
if (*(tokstart - 1) == ',')
tokstart--;
p += strlen("\"location\":");
p += strlen(search);
if (*p == '-')
p++;
while (*p >= '0' && *p <= '9')
Expand All @@ -36,6 +38,14 @@ void remove_node_locations(char *parse_tree_json)
}
}

// Removes the location values from the JSON parse tree string, replacing them with nothing
// (we don't use any special replacement value to avoid increasing the string size)
void remove_node_locations(char *parse_tree_json)
{
remove_numeric_key(parse_tree_json, "location");
remove_numeric_key(parse_tree_json, "name_location");
}

int run_test(const char *query, bool compare_query_text) {
PgQueryProtobufParseResult parse_result = pg_query_parse_protobuf(query);
if (parse_result.error) {
Expand Down

0 comments on commit fe1b2e1

Please sign in to comment.