Source file src/mime/type_unix_test.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build unix || (js && wasm)
     6  
     7  package mime
     8  
     9  import (
    10  	"testing"
    11  )
    12  
    13  func initMimeUnixTest(t *testing.T) {
    14  	once.Do(initMime)
    15  	err := loadMimeGlobsFile("testdata/test.types.globs2")
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  
    20  	loadMimeFile("testdata/test.types")
    21  }
    22  
    23  func TestTypeByExtensionUNIX(t *testing.T) {
    24  	initMimeUnixTest(t)
    25  	typeTests := map[string]string{
    26  		".T1":       "application/test",
    27  		".t2":       "text/test; charset=utf-8",
    28  		".t3":       "document/test",
    29  		".t4":       "example/test",
    30  		".png":      "image/png",
    31  		",v":        "",
    32  		"~":         "",
    33  		".foo?ar":   "",
    34  		".foo*r":    "",
    35  		".foo[1-3]": "",
    36  	}
    37  
    38  	for ext, want := range typeTests {
    39  		val := TypeByExtension(ext)
    40  		if val != want {
    41  			t.Errorf("TypeByExtension(%q) = %q, want %q", ext, val, want)
    42  		}
    43  	}
    44  }
    45  

View as plain text