Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: src/pkg/mime/type_test.go

Issue 160200044: [dev.power64] code review 160200044: build: merge default into dev.power64 (Closed)
Patch Set: diff -r be0c14f62257b42485019e9e1db23cf40d2e249f https://code.google.com/p/go Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/mime/type_plan9.go ('k') | src/pkg/mime/type_unix.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package mime 5 package mime
6 6
7 import "testing" 7 import (
8 » "testing"
9 )
8 10
9 var typeTests = initMimeForTests() 11 var typeTests = initMimeForTests()
10 12
11 func TestTypeByExtension(t *testing.T) { 13 func TestTypeByExtension(t *testing.T) {
12 for ext, want := range typeTests { 14 for ext, want := range typeTests {
13 val := TypeByExtension(ext) 15 val := TypeByExtension(ext)
14 if val != want { 16 if val != want {
15 t.Errorf("TypeByExtension(%q) = %q, want %q", ext, val, want) 17 t.Errorf("TypeByExtension(%q) = %q, want %q", ext, val, want)
16 } 18 }
17
18 } 19 }
19 } 20 }
20 21
21 func TestCustomExtension(t *testing.T) { 22 func TestTypeByExtensionCase(t *testing.T) {
22 » custom := "text/xml; charset=iso-8859-1" 23 » const custom = "test/test; charset=iso-8859-1"
23 » if error := AddExtensionType(".xml", custom); error != nil { 24 » const caps = "test/test; WAS=ALLCAPS"
24 » » t.Fatalf("error %s for AddExtension(%s)", error, custom) 25 » if err := AddExtensionType(".TEST", caps); err != nil {
26 » » t.Fatalf("error %s for AddExtension(%s)", err, custom)
25 } 27 }
26 » if registered := TypeByExtension(".xml"); registered != custom { 28 » if err := AddExtensionType(".tesT", custom); err != nil {
27 » » t.Fatalf("registered %s instead of %s", registered, custom) 29 » » t.Fatalf("error %s for AddExtension(%s)", err, custom)
30 » }
31
32 » // case-sensitive lookup
33 » if got := TypeByExtension(".tesT"); got != custom {
34 » » t.Fatalf("for .tesT, got %q; want %q", got, custom)
35 » }
36 » if got := TypeByExtension(".TEST"); got != caps {
37 » » t.Fatalf("for .TEST, got %q; want %s", got, caps)
38 » }
39
40 » // case-insensitive
41 » if got := TypeByExtension(".TesT"); got != custom {
42 » » t.Fatalf("for .TesT, got %q; want %q", got, custom)
28 } 43 }
29 } 44 }
45
46 func TestLookupMallocs(t *testing.T) {
47 n := testing.AllocsPerRun(10000, func() {
48 TypeByExtension(".html")
49 TypeByExtension(".HtML")
50 })
51 if n > 0 {
52 t.Errorf("allocs = %v; want 0", n)
53 }
54 }
OLDNEW
« no previous file with comments | « src/pkg/mime/type_plan9.go ('k') | src/pkg/mime/type_unix.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b