"""Tests for flow.core.variables.""" from flow.core.variables import substitute, substitute_template def test_substitute_dollar(): result = substitute("hello $NAME", {"NAME": "world"}) assert result == "hello world" def test_substitute_braces(): result = substitute("hello ${NAME}", {"NAME": "world"}) assert result == "hello world" def test_substitute_multiple(): result = substitute("$A and ${B}", {"A": "1", "B": "2"}) assert result == "1 and 2" def test_substitute_home(): result = substitute("dir=$HOME", {}) assert "$HOME" not in result def test_substitute_user(): import os result = substitute("u=$USER", {}) assert result == f"u={os.getenv('USER', '')}" def test_substitute_non_string(): assert substitute(123, {}) == 123 def test_substitute_template_basic(): result = substitute_template("nvim-{{os}}-{{arch}}.tar.gz", {"os": "linux", "arch": "x86_64"}) assert result == "nvim-linux-x86_64.tar.gz" def test_substitute_template_missing_key(): result = substitute_template("{{missing}}", {}) assert result == "{{missing}}" def test_substitute_template_non_string(): assert substitute_template(42, {}) == 42 def test_substitute_template_no_placeholders(): result = substitute_template("plain text", {"os": "linux"}) assert result == "plain text" def test_substitute_template_env_namespace(): result = substitute_template("{{ env.USER_EMAIL }}", {"env": {"USER_EMAIL": "you@example.com"}}) assert result == "you@example.com"