@@ -120,6 +120,42 @@ func TestAddMatcher(t *testing.T) {
120120 }
121121}
122122
123+ func TestAddChild (t * testing.T ) {
124+ parentType := AddType ("fooparent" , "foo/parent" )
125+ parentFn := func (buf []byte ) bool {
126+ return len (buf ) >= 2 && buf [0 ] == 0x00 && buf [1 ] == 0x00
127+ }
128+ parentMatcher := AddMatcher (parentType , parentFn )
129+
130+ childType := AddType ("foochild" , "foo/child" )
131+ childFn := func (buf []byte ) bool {
132+ return len (buf ) > 2 &&
133+ buf [0 ] == 0x00 && buf [1 ] == 0x00 && buf [2 ] == 0x00
134+ }
135+ parentMatcher .AddChild (childType , childFn )
136+
137+ if ! Is ([]byte {0x00 , 0x00 }, "fooparent" ) {
138+ t .Fatalf ("Parent cannot match" )
139+ }
140+
141+ if ! Is ([]byte {0x00 , 0x00 , 0x00 }, "foochild" ) {
142+ t .Fatalf ("Child cannot match" )
143+ }
144+
145+ if ! Is ([]byte {0x00 , 0x00 , 0x00 }, "fooparent" ) {
146+ t .Fatalf ("Parent does not match child" )
147+ }
148+
149+ if ! IsSupported ("foochild" ) {
150+ t .Fatalf ("Not supported extension" )
151+ }
152+
153+ if ! IsMIMESupported ("foo/child" ) {
154+ t .Fatalf ("Not supported MIME type" )
155+ }
156+
157+ }
158+
123159func TestMatchMap (t * testing.T ) {
124160 cases := []struct {
125161 buf []byte
0 commit comments