github.com/goplus/gop@v1.2.6/x/gopprojs/proj_test.go (about)

     1  /*
     2   * Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved.
     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   *     http://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 gopprojs
    18  
    19  import "testing"
    20  
    21  // -----------------------------------------------------------------------------
    22  
    23  func TestIsLocal(t *testing.T) {
    24  	if !isLocal(".") || !isLocal("/") {
    25  		t.Fatal(`isLocal(".") || isLocal("/")`)
    26  	}
    27  	if !isLocal("c:/foo") {
    28  		t.Fatal(`isLocal("c:/foo")`)
    29  	}
    30  	if !isLocal("C:/foo") {
    31  		t.Fatal(`isLocal("C:/foo")`)
    32  	}
    33  	if isLocal("") {
    34  		t.Fatal(`isLocal("")`)
    35  	}
    36  }
    37  
    38  func TestParseOne(t *testing.T) {
    39  	proj, next, err := ParseOne("a.go", "b.go", "abc")
    40  	if err != nil || len(next) != 1 || next[0] != "abc" {
    41  		t.Fatal("ParseOne failed:", proj, next, err)
    42  	}
    43  }
    44  
    45  func TestParseAll_wildcard1(t *testing.T) {
    46  	projs, err := ParseAll("*.go")
    47  	if err != nil || len(projs) != 1 {
    48  		t.Fatal("ParseAll failed:", projs, err)
    49  	}
    50  	if proj, ok := projs[0].(*FilesProj); !ok || len(proj.Files) != 1 || proj.Files[0] != "*.go" {
    51  		t.Fatal("ParseAll failed:", projs)
    52  	}
    53  }
    54  
    55  func TestParseAll_wildcard2(t *testing.T) {
    56  	projs, err := ParseAll("t/*.go")
    57  	if err != nil || len(projs) != 1 {
    58  		t.Fatal("ParseAll failed:", projs, err)
    59  	}
    60  	if proj, ok := projs[0].(*FilesProj); !ok || len(proj.Files) != 1 || proj.Files[0] != "t/*.go" {
    61  		t.Fatal("ParseAll failed:", projs)
    62  	}
    63  }
    64  
    65  func TestParseAll_multiFiles(t *testing.T) {
    66  	projs, err := ParseAll("a.gop", "b.go")
    67  	if err != nil || len(projs) != 1 {
    68  		t.Fatal("ParseAll failed:", projs, err)
    69  	}
    70  	if proj, ok := projs[0].(*FilesProj); !ok || len(proj.Files) != 2 || proj.Files[0] != "a.gop" {
    71  		t.Fatal("ParseAll failed:", proj)
    72  	}
    73  	projs[0].projObj()
    74  }
    75  
    76  func TestParseAll_multiProjs(t *testing.T) {
    77  	projs, err := ParseAll("a/...", "./a/...", "/a")
    78  	if err != nil || len(projs) != 3 {
    79  		t.Fatal("ParseAll failed:", projs, err)
    80  	}
    81  	if proj, ok := projs[0].(*PkgPathProj); !ok || proj.Path != "a/..." {
    82  		t.Fatal("ParseAll failed:", proj)
    83  	}
    84  	if proj, ok := projs[1].(*DirProj); !ok || proj.Dir != "./a/..." {
    85  		t.Fatal("ParseAll failed:", proj)
    86  	}
    87  	if proj, ok := projs[2].(*DirProj); !ok || proj.Dir != "/a" {
    88  		t.Fatal("ParseAll failed:", proj)
    89  	}
    90  	for _, proj := range projs {
    91  		proj.projObj()
    92  	}
    93  }
    94  
    95  func TestParseAllErr(t *testing.T) {
    96  	_, err := ParseAll("a/...", "./a/...", "/a", "*.go")
    97  	if err != ErrMixedFilesProj {
    98  		t.Fatal("ParseAll:", err)
    99  	}
   100  }
   101  
   102  // -----------------------------------------------------------------------------