@@ -91,6 +91,47 @@ func TestGetFormatByExt(t *testing.T) {
9191 require .False (t , found )
9292}
9393
94+ func TestGetFormatByFilename (t * testing.T ) {
95+ noExtNoDelimMediaType := media .TextType
96+ noExtNoDelimMediaType .Suffix = ""
97+ noExtNoDelimMediaType .Delimiter = ""
98+
99+ noExtMediaType := media .TextType
100+ noExtMediaType .Suffix = ""
101+
102+ var (
103+ noExtDelimFormat = Format {
104+ Name : "NEM" ,
105+ MediaType : noExtNoDelimMediaType ,
106+ BaseName : "_redirects" ,
107+ }
108+ noExt = Format {
109+ Name : "NEX" ,
110+ MediaType : noExtMediaType ,
111+ BaseName : "next" ,
112+ }
113+ )
114+
115+ formats := Formats {AMPFormat , HTMLFormat , noExtDelimFormat , noExt , CalendarFormat }
116+ f , found := formats .FromFilename ("my.amp.html" )
117+ require .True (t , found )
118+ require .Equal (t , AMPFormat , f )
119+ f , found = formats .FromFilename ("my.ics" )
120+ require .True (t , found )
121+ f , found = formats .FromFilename ("my.html" )
122+ require .True (t , found )
123+ require .Equal (t , HTMLFormat , f )
124+ f , found = formats .FromFilename ("my.nem" )
125+ require .True (t , found )
126+ require .Equal (t , noExtDelimFormat , f )
127+ f , found = formats .FromFilename ("my.nex" )
128+ require .True (t , found )
129+ require .Equal (t , noExt , f )
130+ f , found = formats .FromFilename ("my.css" )
131+ require .False (t , found )
132+
133+ }
134+
94135func TestDecodeFormats (t * testing.T ) {
95136
96137 mediaTypes := media.Types {media .JSONType , media .XMLType }
0 commit comments