package mpvconf import ( "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestDefaultScopeAndLiteralValues(t *testing.T) { content := "\ufeff hwdec = auto\r\nhwdec=nvdec # effective\r\n[special]\r\nhwdec=no\r\nscale=bilinear\r\n[default] # resumes normal options\r\nscreenshot-template=\"shot, # %n\"\r\nscreenshot-avif-opts=crf=20,speed=6\r\nborder\r\n" assert.Equal(t, map[string]string{ "hwdec": "nvdec", "screenshot-template": "shot, # %n", "screenshot-avif-opts": "crf=20,speed=6", "border": "yes", }, Parse(content)) updated, change := Set(content, "hwdec", "auto-safe", true) assert.True(t, change.Found) assert.Equal(t, 1, change.Duplicates) assert.Equal(t, "nvdec", change.Previous) assert.Equal(t, "auto-safe", Parse(updated)["hwdec"]) assert.Contains(t, updated, "hwdec=auto-safe # effective\r\n") assert.Contains(t, updated, "[special]\r\nhwdec=no\r\nscale=bilinear\r\n[default]") assert.True(t, strings.HasPrefix(updated, "\ufeff")) assert.NotContains(t, strings.ReplaceAll(updated, "\r\n", ""), "\n") } func TestMissingOptionIsAddedOutsideProfiles(t *testing.T) { original := "# header\n[special]\nhwdec=no\nscale=bilinear" updated, change := Set(original, "hwdec", "auto", true) assert.False(t, change.Found) assert.Equal(t, "# header\nhwdec=auto\n[special]\nhwdec=no\nscale=bilinear", updated) assert.Equal(t, "auto", Parse(updated)["hwdec"]) } func TestQuotedValuesRoundTripWithoutCEscaping(t *testing.T) { for _, value := range []string{ `C:\Pictures\clip, shots\`, `shot # %n`, `"literal" 'quotes' #`, " café, 'x' \"y\" # ", "%literal", " trailing space ", } { t.Run(value, func(t *testing.T) { content, _ := Set("", "screenshot-template", value, true) assert.Equal(t, value, Parse(content)["screenshot-template"]) }) } require.Equal(t, `C:\shots\`, Parse("screenshot-directory=\"C:\\shots\\\" # comment")["screenshot-directory"]) } func TestOSCUpdatesPreserveProfileOverrideAndComment(t *testing.T) { original := "osc=yes\nosc = no # selected UI\n[cinema]\nosc=no\n" updated, _ := Set(original, "osc", "yes", true) assert.Equal(t, "osc = yes # selected UI\n[cinema]\nosc=no\n", updated) assert.Equal(t, "yes", Parse(updated)["osc"]) }