from imecilabt_utils.bash_quote_util import need_bash_quote, bash_quote, bash_cmd_array_to_str


def test_need_bash_quote_0():
    assert need_bash_quote('') is True


def test_need_bash_quote_1():
    assert need_bash_quote('fooBar123') is False


def test_need_bash_quote_2():
    assert need_bash_quote('foo_B/ar-123:') is False


def test_need_bash_quote_3():
    assert need_bash_quote('foo Bar 123') is True


def test_need_bash_quote_4():
    assert need_bash_quote("foo'Bar'123") is True


def test_bash_quote_1():
    assert bash_quote("foobar") == "foobar"


def test_bash_quote_2():
    assert bash_quote("that's ok") == "'that'\\''s ok'"


def test_bash_quote_3():
    assert bash_quote("'foobar'") == "''\\''foobar'\\'''"


def test_bash_quote_4():
    assert bash_quote("\"foobar\"") == "'\"foobar\"'"


def test_bash_quote_5():
    assert bash_quote("'") == "''\\'''"  # could be simpler (see below) but this is correct
    # assert bash_quote("'") == "\\'"  # simpler form for single quote that would also be correct


def test_bash_cmd_array_to_str_1():
    assert bash_cmd_array_to_str(["foo", "-bar", "baz 42", "that's ok"]) == "foo -bar 'baz 42' 'that'\\''s ok'"
