mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-03 23:33:41 +00:00 
			
		
		
		
	expand bash
This commit is contained in:
		@ -1,7 +1,7 @@
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
from ahriman.core.configuration.shell_interpolator import ExtendedTemplate, ShellInterpolator
 | 
			
		||||
from ahriman.core.configuration.shell_interpolator import ShellInterpolator
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _parser() -> dict[str, dict[str, str]]:
 | 
			
		||||
@ -27,14 +27,6 @@ def _parser() -> dict[str, dict[str, str]]:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extended_template() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must match colons in braces
 | 
			
		||||
    """
 | 
			
		||||
    assert ExtendedTemplate("$key:value").get_identifiers() == ["key"]
 | 
			
		||||
    assert ExtendedTemplate("${key:value}").get_identifiers() == ["key:value"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extract_variables() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must extract variables list
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										81
									
								
								tests/ahriman/core/configuration/test_shell_template.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								tests/ahriman/core/configuration/test_shell_template.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,81 @@
 | 
			
		||||
from ahriman.core.configuration.shell_template import ShellTemplate
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_shell_template_braceidpattern() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must match colons in braces
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("$k:value").get_identifiers() == ["k"]
 | 
			
		||||
    assert ShellTemplate("${k:value}").get_identifiers() == ["k:value"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_remove_back() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must remove substring from the back
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("${k%removeme}").shell_substitute({"k": "please removeme"}) == "please "
 | 
			
		||||
    assert ShellTemplate("${k%removeme*}").shell_substitute({"k": "please removeme removeme"}) == "please removeme "
 | 
			
		||||
    assert ShellTemplate("${k%removem?}").shell_substitute({"k": "please removeme removeme"}) == "please removeme "
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k%%removeme}").shell_substitute({"k": "please removeme removeme"}) == "please removeme "
 | 
			
		||||
    assert ShellTemplate("${k%%removeme*}").shell_substitute({"k": "please removeme removeme"}) == "please "
 | 
			
		||||
    assert ShellTemplate("${k%%removem?}").shell_substitute({"k": "please removeme removeme"}) == "please removeme "
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k%removeme}").shell_substitute({}) == "${k%removeme}"
 | 
			
		||||
    assert ShellTemplate("${k%%removeme}").shell_substitute({}) == "${k%%removeme}"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k%r3m0v3m3}").shell_substitute({"k": "please removeme"}) == "please removeme"
 | 
			
		||||
    assert ShellTemplate("${k%%r3m0v3m3}").shell_substitute({"k": "please removeme"}) == "please removeme"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_remove_front() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must remove substring from the front
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("${k#removeme}").shell_substitute({"k": "removeme please"}) == " please"
 | 
			
		||||
    assert ShellTemplate("${k#*removeme}").shell_substitute({"k": "removeme removeme please"}) == " removeme please"
 | 
			
		||||
    assert ShellTemplate("${k#removem?}").shell_substitute({"k": "removeme removeme please"}) == " removeme please"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k##removeme}").shell_substitute({"k": "removeme removeme please"}) == " removeme please"
 | 
			
		||||
    assert ShellTemplate("${k##*removeme}").shell_substitute({"k": "removeme removeme please"}) == " please"
 | 
			
		||||
    assert ShellTemplate("${k##removem?}").shell_substitute({"k": "removeme removeme please"}) == " removeme please"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k#removeme}").shell_substitute({}) == "${k#removeme}"
 | 
			
		||||
    assert ShellTemplate("${k##removeme}").shell_substitute({}) == "${k##removeme}"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k#r3m0v3m3}").shell_substitute({"k": "removeme please"}) == "removeme please"
 | 
			
		||||
    assert ShellTemplate("${k##r3m0v3m3}").shell_substitute({"k": "removeme please"}) == "removeme please"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_replace() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must perform regular replacement
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("${k/in/out}").shell_substitute({"k": "in replace in"}) == "out replace in"
 | 
			
		||||
    assert ShellTemplate("${k/in*/out}").shell_substitute({"k": "in replace in"}) == "out"
 | 
			
		||||
    assert ShellTemplate("${k/*in/out}").shell_substitute({"k": "in replace in replace"}) == "out replace"
 | 
			
		||||
    assert ShellTemplate("${k/i?/out}").shell_substitute({"k": "in replace in"}) == "out replace in"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k//in/out}").shell_substitute({"k": "in replace in"}) == "out replace out"
 | 
			
		||||
    assert ShellTemplate("${k//in*/out}").shell_substitute({"k": "in replace in"}) == "out"
 | 
			
		||||
    assert ShellTemplate("${k//*in/out}").shell_substitute({"k": "in replace in replace"}) == "out replace"
 | 
			
		||||
    assert ShellTemplate("${k//i?/out}").shell_substitute({"k": "in replace in replace"}) == "out replace out replace"
 | 
			
		||||
 | 
			
		||||
    assert ShellTemplate("${k/in/out}").shell_substitute({}) == "${k/in/out}"
 | 
			
		||||
    assert ShellTemplate("${k//in/out}").shell_substitute({}) == "${k//in/out}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_replace_back() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must replace substring from the back
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("${k/%in/out}").shell_substitute({"k": "in replace in"}) == "in replace out"
 | 
			
		||||
    assert ShellTemplate("${k/%in/out}").shell_substitute({"k": "in replace in "}) == "in replace in "
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_replace_front() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must replace substring from the front
 | 
			
		||||
    """
 | 
			
		||||
    assert ShellTemplate("${k/#in/out}").shell_substitute({"k": "in replace in"}) == "out replace in"
 | 
			
		||||
    assert ShellTemplate("${k/#in/out}").shell_substitute({"k": " in replace in"}) == " in replace in"
 | 
			
		||||
		Reference in New Issue
	
	Block a user