def test_str_var_slicing():
    """Test that we can slice into str vars."""
    str_var = Var(_js_expr="str").to(str)

    # Test that slicing gives a type of Var[str].
    assert isinstance(str_var[:1], Var)
    assert str_var[:1]._var_type is str

    # Test basic slicing.
    assert str(str_var[:1]) == 'str.split("").slice(undefined, 1).join("")'
    assert str(str_var[1:]) == 'str.split("").slice(1, undefined).join("")'
    assert str(str_var[:]) == 'str.split("").slice(undefined, undefined).join("")'
    assert str(str_var[1:2]) == 'str.split("").slice(1, 2).join("")'

    # Test negative slicing.
    assert str(str_var[:-1]) == 'str.split("").slice(undefined, -1).join("")'
    assert str(str_var[-1:]) == 'str.split("").slice(-1, undefined).join("")'
    assert str(str_var[:-2]) == 'str.split("").slice(undefined, -2).join("")'
    assert str(str_var[-2:]) == 'str.split("").slice(-2, undefined).join("")'
Test that we can slice into str vars.
tests/units/test_var.py