@@ -51,6 +51,28 @@ func TestInsertOpenCodePluginKeepsExistingEntriesAndComments(t *testing.T) {
5151 }
5252}
5353
54+ func TestInsertOpenCodePluginKeepsASingleLineArrayOnOneLine (t * testing.T ) {
55+ existing := "{\n \" plugins\" : [\" ./other\" ],\n \" model\" : \" x\" \n }\n "
56+ out , changed , err := insertOpenCodePlugin (existing , `"/p/opencode-plugin"` , "/p/opencode-plugin" )
57+ if err != nil || ! changed {
58+ t .Fatalf ("insert = (%v, %v), want (true, nil)" , changed , err )
59+ }
60+ if want := " \" plugins\" : [\" /p/opencode-plugin\" , \" ./other\" ]," ; ! strings .Contains (out , want ) {
61+ t .Fatalf ("a one-line array must stay on one line:\n %s" , out )
62+ }
63+ }
64+
65+ func TestInsertOpenCodePluginIndentsIntoAMultiLineArray (t * testing.T ) {
66+ existing := "{\n \" plugins\" : [\n \" ./other\" \n ]\n }\n "
67+ out , changed , err := insertOpenCodePlugin (existing , `"/p/opencode-plugin"` , "/p/opencode-plugin" )
68+ if err != nil || ! changed {
69+ t .Fatalf ("insert = (%v, %v), want (true, nil)" , changed , err )
70+ }
71+ if want := "\n \" /p/opencode-plugin\" ,\n \" ./other\" \n " ; ! strings .Contains (out , want ) {
72+ t .Fatalf ("a multi-line array must keep one entry per line:\n %s" , out )
73+ }
74+ }
75+
5476func TestInsertOpenCodePluginAddsKeyWhenAbsent (t * testing.T ) {
5577 out , changed , err := insertOpenCodePlugin ("{\n \" model\" : \" x\" \n }\n " , `"/p/opencode-plugin"` , "/p/opencode-plugin" )
5678 if err != nil || ! changed {
0 commit comments