@@ -173,6 +173,9 @@ func TestOptionJSON(t *testing.T) {
173173 }, {
174174 json : `["DIFF_OFF"]` ,
175175 option : DIFF_OFF ,
176+ }, {
177+ json : `[{"file":"example.json"}]` ,
178+ option : File ("example.json" ),
176179 }}
177180 for _ , c := range cases {
178181 t .Run (c .json , func (t * testing.T ) {
@@ -552,6 +555,37 @@ func TestRefinePathMultiset(t *testing.T) {
552555 }
553556}
554557
558+ func TestFileOption (t * testing.T ) {
559+ // NewOption recognizes {"file":"example.json"}
560+ opt , err := NewOption (map [string ]any {"file" : "example.json" })
561+ require .NoError (t , err )
562+ fo , ok := opt .(fileOption )
563+ require .True (t , ok )
564+ require .Equal (t , "example.json" , fo .file )
565+
566+ // MarshalJSON produces {"file":"example.json"}
567+ b , err := json .Marshal (opt )
568+ require .NoError (t , err )
569+ require .Equal (t , `{"file":"example.json"}` , string (b ))
570+
571+ // Round-trip: File() -> marshal -> unmarshal via NewOption -> equal
572+ opt2 := File ("a.json" )
573+ b2 , err := json .Marshal (opt2 )
574+ require .NoError (t , err )
575+ var raw any
576+ err = json .Unmarshal (b2 , & raw )
577+ require .NoError (t , err )
578+ opt3 , err := NewOption (raw )
579+ require .NoError (t , err )
580+ fo3 , ok := opt3 .(fileOption )
581+ require .True (t , ok )
582+ require .Equal (t , "a.json" , fo3 .file )
583+
584+ // Wrong type for file value
585+ _ , err = NewOption (map [string ]any {"file" : 42 })
586+ require .Error (t , err )
587+ }
588+
555589func TestRefineEmptyAt (t * testing.T ) {
556590 // PathOption with empty At and non-nil path element should be skipped
557591 opts := newOptions ([]Option {PathOption (Path {}, SET )})
0 commit comments