Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 657df67

Browse files
committed
Added tests
1 parent 398f092 commit 657df67

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,12 @@ RUN(NAME test_dict_bool LABELS cpython llvm llvm_jit)
584584
RUN(NAME test_dict_increment LABELS cpython llvm llvm_jit)
585585
RUN(NAME test_dict_keys_values LABELS cpython llvm llvm_jit)
586586
RUN(NAME test_dict_nested1 LABELS cpython llvm llvm_jit)
587+
RUN(NAME test_dict_clear LABELS cpython llvm)
587588
RUN(NAME test_set_len LABELS cpython llvm llvm_jit)
588589
RUN(NAME test_set_add LABELS cpython llvm llvm_jit)
589590
RUN(NAME test_set_remove LABELS cpython llvm llvm_jit)
590591
RUN(NAME test_set_discard LABELS cpython llvm llvm_jit)
592+
RUN(NAME test_set_clear LABELS cpython llvm)
591593
RUN(NAME test_global_set LABELS cpython llvm llvm_jit)
592594
RUN(NAME test_for_loop LABELS cpython llvm llvm_jit c)
593595
RUN(NAME modules_01 LABELS cpython llvm llvm_jit c wasm wasm_x86 wasm_x64)

integration_tests/test_dict_clear.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def test_clear():
2+
a: dict[i32, i32] = {1:1, 2:2}
3+
4+
a.clear()
5+
a[3] = 3
6+
7+
assert len(a) == 1
8+
assert a.keys() == [3]
9+
assert a.values() == [3]
10+
11+
b: dict[str, str] = {'a':'a', 'b':'b'}
12+
13+
b.clear()
14+
b['c'] = 'c'
15+
16+
assert len(b) == 1
17+
assert b.keys() == ['c']
18+
assert b.values() == ['c']
19+
20+
test_clear()

integration_tests/test_set_clear.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def test_clear():
2+
a: set[i32] = {1, 2}
3+
4+
a.clear()
5+
a.add(3)
6+
7+
assert len(a) == 1
8+
# a.remove(3)
9+
# assert len(a) == 0
10+
11+
b: set[str] = {'a', 'b'}
12+
13+
b.clear()
14+
b.add('c')
15+
16+
assert len(b) == 1
17+
# b.remove('c')
18+
# assert len(b) == 0
19+
20+
21+
test_clear()

src/libasr/codegen/llvm_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6926,16 +6926,16 @@ namespace LCompilers {
69266926
llvm::Value* new_el_mask = LLVM::lfortran_calloc(context, *module, *builder, llvm_zero,
69276927
llvm_mask_size);
69286928
std::string el_type_code = ASRUtils::get_type_code(el_asr_type);
6929-
//llvm::Type* el_llvm_type = std::get<2>(typecode2settype[el_type_code]);
6930-
//int32_t el_type_size = std::get<1>(typecode2settype[el_type_code]);
6929+
llvm::Type* el_llvm_type = std::get<2>(typecode2settype[el_type_code]);
6930+
int32_t el_type_size = std::get<1>(typecode2settype[el_type_code]);
69316931

6932-
//llvm::Value* new_el_list = builder0.CreateAlloca(llvm_utils->list_api->get_list_type(el_llvm_type,
6933-
//el_type_code, el_type_size), nullptr);
6932+
llvm::Value* new_el_list = builder0.CreateAlloca(llvm_utils->list_api->get_list_type(el_llvm_type,
6933+
el_type_code, el_type_size), nullptr);
69346934
llvm_utils->list_api->list_init(el_type_code, el_list, *module, llvm_zero, llvm_zero);
69356935

69366936
llvm_utils->list_api->free_data(el_list, *module);
69376937
LLVM::lfortran_free(context, *module, *builder, LLVM::CreateLoad(*builder, get_pointer_to_mask(set)));
6938-
//LLVM::CreateStore(*builder, LLVM::CreateLoad(*builder, new_el_list), el_list);
6938+
LLVM::CreateStore(*builder, LLVM::CreateLoad(*builder, new_el_list), el_list);
69396939
LLVM::CreateStore(*builder, new_el_mask, get_pointer_to_mask(set));
69406940
}
69416941

0 commit comments

Comments
 (0)