lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 157 forks source link

Added str.replace() #2587

Closed Kishan-Ved closed 4 months ago

Kishan-Ved commented 4 months ago

Towards: https://github.com/lcompilers/lpython/issues/2356

In this PR, I have implemented str.replace() completely. Relevant tests have also been added.

Parameters:

Kishan-Ved commented 4 months ago

I don't get any errors upon running ./run_tests.py locally. However, here, 2 checks fail due to this. Please let me know the fix for this. @Thirumalai-Shaktivel @Shaikh-Ubaid

Thirumalai-Shaktivel commented 4 months ago

It's the C test that fails, you can reproduce it using the following command:

$ cd integration_tests
$ ./run_tests.py -b c
Thirumalai-Shaktivel commented 4 months ago

Please mark this PR ready for review once it is ready!

Kishan-Ved commented 4 months ago

It's the C test that fails, you can reproduce it using the following command:

$ cd integration_tests
$ ./run_tests.py -b c

Fixed. Thank you @Thirumalai-Shaktivel .

Kishan-Ved commented 4 months ago

@Shaikh-Ubaid @Thirumalai-Shaktivel Please let me know if this is good to be merged.

Shaikh-Ubaid commented 4 months ago

I think the implementation fails for the following example:

% cat examples/expr2.py   
from lpython import i32

def main0():
    x: str
    x = "abc"
    print(x.replace("", ","))
    assert x.replace("", ",") == ",a,b,c,"

main0()
% python examples/expr2.py
,a,b,c,
% lpython examples/expr2.py
,a,b,c
AssertionError
Kishan-Ved commented 4 months ago

I think the implementation fails for the following example:

% cat examples/expr2.py   
from lpython import i32

def main0():
    x: str
    x = "abc"
    print(x.replace("", ","))
    assert x.replace("", ",") == ",a,b,c,"

main0()
% python examples/expr2.py
,a,b,c,
% lpython examples/expr2.py
,a,b,c
AssertionError

Fixed. Thanks.