func BenchmarkNewMP3ID3v24(b *testing.B) {
	for i := 0; i < b.N; i++ {
		New(bytes.NewReader(mp3ID3v24File))
	}
}
BenchmarkNewMP3ID3v24 checks the performance of the New() function with a MP3 + ID3v2.4 file
package taggolib
import (
	"bytes"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"reflect"
	"testing"
)
var (
	flacFile = func() []byte {
		file, err := ioutil.ReadFile("./test/tone16bit.flac")
		if err != nil {
			log.Fatalf("Could not open test FLAC: %v", err)
		}
		return file
	}()
	mp3ID3v23File = func() []byte {
		file, err := ioutil.ReadFile("./test/tone16bit_id3v2.3.mp3")
		if err != nil {
			log.Fatalf("Could not open test MP3 + ID3v2.3: %v", err)
		}
		return file
	}()
	mp3ID3v24File = func() []byte {
		file, err := ioutil.ReadFile("./test/tone16bit_id3v2.4.mp3")
		if err != nil {
			log.Fatalf("Could not open test MP3 + ID3v2.4: %v", err)
		}
		return file
	}()
	mp3VBRFile = func() []byte {
		file, err := ioutil.ReadFile("./test/tone16bit_vbr.mp3")
		if err != nil {
			log.Fatalf("Could not open test MP3 VBR: %v", err)
		}
		return file
	}()
	oggVorbisFile = func() []byte {
		file, err := ioutil.ReadFile("./test/tone16bit.ogg")
		if err != nil {
			log.Fatalf("Could not open test Ogg Vorbis: %v", err)
		}
		return file
	}()
)
func ExampleNew() {
	file, err := os.Open("./test/tone16bit.flac")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()
	audio, err := New(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%s - %s - %s", audio.Artist(), audio.Album(), audio.Title())
}
func TestNew(t *testing.T) {
	var tests = []struct {
		stream     []byte
		parser     Parser
		err        error
		encoder    string
		tags       []string
		properties []int
	}{
		{flacFile, &flacParser{}, nil, "reference libFLAC 1.1.4 20070213", []string{"Artist", "Album", "Title"}, []int{5, 202, 16, 44100}},
		{mp3ID3v23File, &mp3Parser{}, nil, "Lavf53.21.1", []string{"Artist", "Album", "Title"}, []int{5, 32, 16, 44100}},
		{mp3ID3v24File, &mp3Parser{}, nil, "MP3FS", []string{"Artist", "Album", "Title"}, []int{5, 320, 16, 44100}},
		{mp3VBRFile, &mp3Parser{}, nil, "Lavf53.21.1", []string{"Artist", "Album", "Title"}, []int{5, 88, 16, 44100}},
		{oggVorbisFile, &oggVorbisParser{}, nil, "Lavf53.21.1", []string{"Artist", "Album", "Title"}, []int{5, 192, 16, 44100}},
		{[]byte("nonsense"), nil, errUnknownFormat, "", nil, nil},
	}
	for _, test := range tests {
		reader := bytes.NewReader(test.stream)
		parser, err := New(reader)
		if err != nil {
			if test.err == errUnknownFormat && !IsUnknownFormat(err) {
				t.Fatalf("unexpected error: %v", err)
			}
		}
		if reflect.TypeOf(parser) != reflect.TypeOf(test.parser) {
			t.Fatalf("unexpected parser type: %v", reflect.TypeOf(parser))
		}
		if parser == nil {
			continue
		}
		if parser.Encoder() != test.encoder {
			t.Fatalf("mismatched Encoder: %v != %v", parser.Encoder(), test.encoder)
		}
		if test.tags != nil {
			if parser.Artist() != test.tags[0] {
				t.Fatalf("mismatched tag Artist: %v != %v", parser.Artist(), test.tags[0])
			}
			if parser.Album() != test.tags[1] {
				t.Fatalf("mismatched tag Album: %v != %v", parser.Album(), test.tags[1])
			}
			if parser.Title() != test.tags[2] {
				t.Fatalf("mismatched tag Title: %v != %v", parser.Title(), test.tags[2])
			}
		}
		if test.properties != nil {
			if int(parser.Duration().Seconds()) != test.properties[0] {
				t.Fatalf("mismatched property Duration: %v != %v", parser.Duration().Seconds(), test.properties[0])
			}
			if parser.Bitrate() != test.properties[1] {
				t.Fatalf("mismatched property Bitrate: %v != %v", parser.Bitrate(), test.properties[1])
			}
			if parser.BitDepth() != test.properties[2] {
				t.Fatalf("mismatched property BitDepth: %v != %v", parser.BitDepth(), test.properties[2])
			}
			if parser.SampleRate() != test.properties[3] {
				t.Fatalf("mismatched property SampleRate: %v != %v", parser.SampleRate(), test.properties[3])
			}
		}
	}
}
func BenchmarkNewFLAC(b *testing.B) {
	for i := 0; i < b.N; i++ {
		New(bytes.NewReader(flacFile))
	}
}
func BenchmarkNewMP3ID3v23(b *testing.B) {
	for i := 0; i < b.N; i++ {
		New(bytes.NewReader(mp3ID3v23File))
	}
}