github.com/coreos/mantle@v0.13.0/lang/reader/reader_test.go (about)

     1  // Copyright 2016 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package reader
    16  
    17  import (
    18  	"io"
    19  	"strings"
    20  	"testing"
    21  )
    22  
    23  func TestAtReader(t *testing.T) {
    24  	ra := strings.NewReader("this is a test")
    25  	rd := atReader{ra, 0}
    26  
    27  	buf := make([]byte, 4)
    28  	_, err := rd.Read(buf)
    29  	if err != nil {
    30  		t.Error(err)
    31  	}
    32  	if string(buf) != "this" {
    33  		t.Errorf("Unexpected: %q", string(buf))
    34  	}
    35  
    36  	_, err = rd.Read(buf)
    37  	if err != nil {
    38  		t.Error(err)
    39  	}
    40  	if string(buf) != " is " {
    41  		t.Errorf("Unexpected: %q", string(buf))
    42  	}
    43  
    44  	r := AtReader(ra)
    45  	switch typ := r.(type) {
    46  	case *strings.Reader:
    47  	default:
    48  		t.Errorf("Unexpected type %T", typ)
    49  	}
    50  
    51  	var rn io.ReaderAt
    52  	r = AtReader(rn)
    53  	switch typ := r.(type) {
    54  	case *atReader:
    55  	default:
    56  		t.Errorf("Unexpected type %T", typ)
    57  	}
    58  }