fix: parse array variable from command

This commit is contained in:
2024-05-09 13:08:21 +03:00
parent 46b3c82aca
commit f8b725d175
7 changed files with 109 additions and 66 deletions

View File

@@ -1,3 +1,6 @@
import pytest
import shlex
from pathlib import Path
from pytest_mock import MockerFixture
from unittest.mock import MagicMock, call
@@ -48,6 +51,35 @@ def test_from_env() -> None:
assert PkgbuildPatch.from_env("KEY") == PkgbuildPatch("KEY", "")
def test_parse() -> None:
"""
must parse string correctly
"""
assert PkgbuildPatch.parse("VALUE") == "VALUE"
assert PkgbuildPatch.parse("(ARRAY VALUE)") == ["ARRAY", "VALUE"]
assert PkgbuildPatch.parse("""("QU'OUTED" ARRAY VALUE)""") == ["QU'OUTED", "ARRAY", "VALUE"]
def test_unquote() -> None:
"""
must remove quotation marks
"""
for source in (
"abc",
"ab'c",
"ab\"c",
):
assert PkgbuildPatch.unquote(shlex.quote(source)) == source
def test_unquote_error() -> None:
"""
must raise value error on invalid quotation
"""
with pytest.raises(ValueError):
PkgbuildPatch.unquote("ab'c")
def test_serialize() -> None:
"""
must correctly serialize string values