go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/util/extractor_util_test.go (about)

     1  // Copyright 2022 The LUCI Authors.
     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 util
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/smartystreets/goconvey/convey"
    21  )
    22  
    23  func TestExtractorUtil(t *testing.T) {
    24  	Convey("NormalizeFilePath", t, func() {
    25  		data := map[string]string{
    26  			"../a/b/c.cc":    "a/b/c.cc",
    27  			"a/b/./c.cc":     "a/b/c.cc",
    28  			"a/b/../c.cc":    "a/c.cc",
    29  			"a\\b\\.\\c.cc":  "a/b/c.cc",
    30  			"a\\\\b\\\\c.cc": "a/b/c.cc",
    31  			"//a/b/c.cc":     "a/b/c.cc",
    32  		}
    33  		for fp, nfp := range data {
    34  			So(NormalizeFilePath(fp), ShouldEqual, nfp)
    35  		}
    36  	})
    37  
    38  	Convey("GetCanonicalFileName", t, func() {
    39  		data := map[string]string{
    40  			"../a/b/c.cc":   "c",
    41  			"a/b/./d.dd":    "d",
    42  			"a/b/c.xx":      "c",
    43  			"a/b/c_impl.xx": "c",
    44  		}
    45  		for fp, name := range data {
    46  			So(GetCanonicalFileName(fp), ShouldEqual, name)
    47  		}
    48  	})
    49  
    50  	Convey("StripExtensionAndCommonSuffixFromFileName", t, func() {
    51  		data := map[string]string{
    52  			"a_file_impl_mac_test.cc": "a_file",
    53  			"src/b_file_x11_ozone.h":  "src/b_file",
    54  			"c_file.cc":               "c_file",
    55  		}
    56  		for k, v := range data {
    57  			So(StripExtensionAndCommonSuffixFromFileName(k), ShouldEqual, v)
    58  		}
    59  	})
    60  
    61  }