# test that chezmoi add --autotemplate on a file with a replacement creates a template in the source directory
exec chezmoi add --autotemplate $HOME${/}.template
cmp $CHEZMOISOURCEDIR/dot_template.tmpl golden/dot_template.tmpl

# test that chezmoi add --autotemplate on a symlink with a replacement creates a template in the source directory
symlink $HOME/.symlink -> .target-value
exec chezmoi add --autotemplate $HOME${/}.symlink
cmp $CHEZMOISOURCEDIR/symlink_dot_symlink.tmpl golden/symlink_dot_symlink.tmpl

# test that chezmoi add --autotemplate does not create a template if no replacements occurred
exec chezmoi add --autotemplate $HOME${/}.file
cmp $CHEZMOISOURCEDIR/dot_file golden/dot_file

# test that chezmoi add --autotemplate escapes brackets
exec chezmoi add --autotemplate $HOME${/}.vimrc
cmp $CHEZMOISOURCEDIR/dot_vimrc.tmpl golden/dot_vimrc.tmpl

-- golden/dot_file --
# contents of .file
-- golden/dot_template.tmpl --
key = {{ .variable }}
-- golden/dot_vimrc.tmpl --
set foldmarker={{ "{{" }},{{ "}}" }}
-- golden/symlink_dot_symlink.tmpl --
.target-{{ .variable }}
-- home/user/.config/chezmoi/chezmoi.toml --
[data]
    variable = "value"
-- home/user/.file --
# contents of .file
-- home/user/.template --
key = value
-- home/user/.vimrc --
set foldmarker={{,}}
