...

Source file src/github.com/bazelbuild/buildtools/buildifier/utils/utils_test.go

Documentation: github.com/bazelbuild/buildtools/buildifier/utils

     1  /*
     2  Copyright 2020 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 utils
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestIsStarlarkFile(t *testing.T) {
    24  	tests := []struct {
    25  		filename string
    26  		ok       bool
    27  	}{
    28  		{
    29  			filename: "BUILD",
    30  			ok:       true,
    31  		},
    32  		{
    33  			filename: "BUILD.bazel",
    34  			ok:       true,
    35  		},
    36  		{
    37  			filename: "BUILD.oss",
    38  			ok:       true,
    39  		},
    40  		{
    41  			filename: "BUILD.foo.bazel",
    42  			ok:       true,
    43  		},
    44  		{
    45  			filename: "BUILD.foo.oss",
    46  			ok:       true,
    47  		},
    48  		{
    49  			filename: "build.foo.bazel",
    50  			ok:       false,
    51  		},
    52  		{
    53  			filename: "build.foo.oss",
    54  			ok:       false,
    55  		},
    56  		{
    57  			filename: "build.oss",
    58  			ok:       false,
    59  		},
    60  		{
    61  			filename: "WORKSPACE",
    62  			ok:       true,
    63  		},
    64  		{
    65  			filename: "WORKSPACE.bazel",
    66  			ok:       true,
    67  		},
    68  		{
    69  			filename: "WORKSPACE.oss",
    70  			ok:       true,
    71  		},
    72  		{
    73  			filename: "WORKSPACE.foo.bazel",
    74  			ok:       true,
    75  		},
    76  		{
    77  			filename: "WORKSPACE.foo.oss",
    78  			ok:       true,
    79  		},
    80  		{
    81  			filename: "workspace.foo.bazel",
    82  			ok:       false,
    83  		},
    84  		{
    85  			filename: "workspace.foo.oss",
    86  			ok:       false,
    87  		},
    88  		{
    89  			filename: "workspace.oss",
    90  			ok:       false,
    91  		},
    92  		{
    93  			filename: "build.gradle",
    94  			ok:       false,
    95  		},
    96  		{
    97  			filename: "workspace.xml",
    98  			ok:       false,
    99  		},
   100  		{
   101  			filename: "foo.bzl",
   102  			ok:       true,
   103  		},
   104  		{
   105  			filename: "foo.BZL",
   106  			ok:       false,
   107  		},
   108  		{
   109  			filename: "build.bzl",
   110  			ok:       true,
   111  		},
   112  		{
   113  			filename: "workspace.sky",
   114  			ok:       true,
   115  		},
   116  		{
   117  			filename: "foo.star",
   118  			ok:       true,
   119  		},
   120  		{
   121  			filename: "foo.bar",
   122  			ok:       false,
   123  		},
   124  		{
   125  			filename: "foo.build",
   126  			ok:       false,
   127  		},
   128  		{
   129  			filename: "foo.workspace",
   130  			ok:       false,
   131  		},
   132  	}
   133  
   134  	for _, tc := range tests {
   135  		if isStarlarkFile(tc.filename) != tc.ok {
   136  			t.Errorf("Wrong result for %q, want %t", tc.filename, tc.ok)
   137  		}
   138  	}
   139  }
   140  

View as plain text