test: Split util_test into readfile_test and readfile_js_test

This commit is contained in:
Hajime Hoshi 2016-03-17 00:05:46 +09:00
parent c100ff7989
commit 6c78837d06
3 changed files with 35 additions and 11 deletions

View File

@ -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)

View File

@ -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
}

31
readfile_test.go Normal file
View File

@ -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
}