From 6c78837d0680b2ad239c4834caccf07e55736288 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 17 Mar 2016 00:05:46 +0900 Subject: [PATCH] test: Split util_test into readfile_test and readfile_js_test --- exp/audio/audio.go | 1 + util_test.go => readfile_js_test.go | 14 +++---------- readfile_test.go | 31 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) rename util_test.go => readfile_js_test.go (96%) create mode 100644 readfile_test.go diff --git a/exp/audio/audio.go b/exp/audio/audio.go index 5c7dab1d4..18a0a4e0a 100644 --- a/exp/audio/audio.go +++ b/exp/audio/audio.go @@ -51,6 +51,7 @@ func (s *mixedPlayersStream) Read(b []byte) (int, error) { return 0, nil } + // TODO: This assumes that channelNum is a power of 2. const mask = ^(channelNum*bytesPerSample - 1) if len(s.context.players) == 0 { l := min(len(b), x-s.writtenBytes) diff --git a/util_test.go b/readfile_js_test.go similarity index 96% rename from util_test.go rename to readfile_js_test.go index e910c095b..d31fa8485 100644 --- a/util_test.go +++ b/readfile_js_test.go @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build js + package ebiten_test import ( - "bytes" "encoding/base64" "errors" - "github.com/gopherjs/gopherjs/js" "io" - "io/ioutil" "strings" ) @@ -106,19 +105,12 @@ SUVORK5CYII=`, } func readFile(path string) (io.Reader, error) { - if js.Global == nil { - b, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - return bytes.NewBuffer(b), nil - } // According to https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md, // syscall can be available on the unstable version of npm. // Let's not use os package here. str, ok := data[path] if !ok { - return nil, errors.New("not found") + return nil, errors.New("ebiten_test: not found") } return base64.NewDecoder(base64.StdEncoding, strings.NewReader(str)), nil } diff --git a/readfile_test.go b/readfile_test.go new file mode 100644 index 000000000..5d257c3a5 --- /dev/null +++ b/readfile_test.go @@ -0,0 +1,31 @@ +// Copyright 2016 Hajime Hoshi +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !js + +package ebiten_test + +import ( + "bytes" + "io" + "io/ioutil" +) + +func readFile(path string) (io.Reader, error) { + b, err := ioutil.ReadFile(path) + if err != nil { + return nil, err + } + return bytes.NewBuffer(b), nil +}