...

Source file src/github.com/bazelbuild/buildtools/unused_deps/jar_manifest_test.go

Documentation: github.com/bazelbuild/buildtools/unused_deps

     1  /*
     2  Copyright 2018 Google LLC
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      https://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"errors"
    21  	"testing"
    22  )
    23  
    24  func TestManifestIndexNewline(t *testing.T) {
    25  	foo := []struct {
    26  		manifest string
    27  		newline  int
    28  		next     int
    29  		err      error
    30  	}{
    31  		{"\n", 0, 1, nil},
    32  		{"\r", 0, 1, nil},
    33  		{"\n\r", 0, 1, nil},
    34  		{"\r\n", 0, 2, nil},
    35  		{"a\na", 1, 2, nil},
    36  		{"a\ra", 1, 2, nil},
    37  		{"a\nb\ra", 1, 2, nil},
    38  		{"a\rb\na", 1, 2, nil},
    39  		{"a\n\rb\ra", 1, 2, nil},
    40  		{"a\r\nb\na", 1, 3, nil},
    41  		{"", -1, -1, errors.New("no newline in ''")},
    42  		{"aaa", -1, -1, errors.New("no newline in 'aaa'")},
    43  	}
    44  
    45  	errMismatch := func(e1, e2 error) bool {
    46  		return (e1 != nil || e2 != nil) && (e1 == nil || e2 == nil || e1.Error() != e2.Error())
    47  	}
    48  
    49  	for i, tt := range foo {
    50  		newline, next, err := manifestIndexNewline(tt.manifest)
    51  		if newline != tt.newline || next != tt.next || errMismatch(err, tt.err) {
    52  			t.Errorf("%d. manifestIndexNewline(%q) => (%d, %d, %q), want (%d, %d, %q)",
    53  				i, tt.manifest, newline, next, err, tt.newline, tt.next, tt.err)
    54  		}
    55  	}
    56  }
    57  

View as plain text