void ranges()

in native/src/tests.c [48:90]


void ranges() {
    TSParser *parser = ts_parser_new();
    TSLanguage *lang = tree_sitter_go();
    ts_parser_set_language(parser, lang);
    const char *str_go = "func hello() { sayHello() }";
    TSTree *tree = ts_parser_parse_string(
                                          parser,
                                          NULL,
                                          str_go,
                                          strlen(str_go)
                                          );
    const char *str_go2 = "func hello() { sayHello }";
    TSInputEdit e; // + 8
    e.start_byte = 15 + 8;
    e.old_end_byte = 15 + 8 + 2;
    e.new_end_byte = 15 + 8;
    ts_tree_edit(tree, &e);
    TSTree *tree2 = ts_parser_parse_string(parser, tree, str_go2, strlen(str_go2));
    uint32_t len;
    
    
    TSRange *ranges = ts_tree_get_changed_ranges(tree, tree2, &len);
    
    char *new_string = ts_node_string(ts_tree_root_node(tree2));
    printf("New Syntax tree: %s\n", new_string);
    char *old_string = ts_node_string(ts_tree_root_node(tree));
    printf("Old Syntax tree: %s\n", old_string);
    
    const char *str_go3 = "func hello() { sayHello() }";
    TSInputEdit e2; // + 8
    e2.start_byte = 15 + 8;
    e2.new_end_byte = 15 + 8 + 2;
    e2.old_end_byte = 15 + 8;
    ts_tree_edit(tree2, &e2);
    TSTree *tree3 = ts_parser_parse_string(parser, tree2, str_go3, strlen(str_go3));
    uint32_t len2;
    
    
    TSRange *ranges2 = ts_tree_get_changed_ranges(tree, tree2, &len2);
    
    char *new_string3 = ts_node_string(ts_tree_root_node(tree3));
    printf("New Syntax tree: %s\n", new_string3);
}