"""Tests for flow.core.template.""" import os from flow.core.template import substitute, substitute_template class TestSubstitute: def test_replaces_dollar_var(self): assert substitute("hello $NAME", {"NAME": "world"}) == "hello world" def test_replaces_braced_var(self): assert substitute("hello ${NAME}", {"NAME": "world"}) == "hello world" def test_falls_back_to_env(self, monkeypatch): monkeypatch.setenv("FOO", "bar") assert substitute("$FOO", {}) == "bar" def test_preserves_unknown_vars(self): assert substitute("$UNKNOWN", {}) == "$UNKNOWN" def test_non_string_passthrough(self): assert substitute(42, {}) == 42 class TestSubstituteTemplate: def test_replaces_double_braces(self): assert substitute_template("nvim-{{os}}", {"os": "linux"}) == "nvim-linux" def test_env_dot_notation(self, monkeypatch): monkeypatch.setenv("USER", "tomas") result = substitute_template("{{ env.USER }}", {"env": dict(os.environ)}) assert result == "tomas" def test_nested_dict_lookup(self): ctx = {"platform": {"arch": "arm64"}} assert substitute_template("{{ platform.arch }}", ctx) == "arm64" def test_preserves_unknown_templates(self): assert substitute_template("{{ unknown }}", {}) == "{{ unknown }}" def test_non_string_passthrough(self): assert substitute_template(42, {}) == 42 def test_whitespace_in_braces(self): assert substitute_template("{{ os }}", {"os": "linux"}) == "linux"