cuelang.org/go@v0.10.1/pkg/path/testdata/os.txtar (about)

     1  // Copyright 2020 CUE 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  #noformat
    16  
    17  -- in.cue --
    18  import "path"
    19  
    20  #OSes: [path.Unix, path.Windows, path.Plan9]
    21  #AnyOS: or(#OSes)
    22  
    23  // Test these OSes for all tests below.
    24  {
    25      [string]: {
    26          unix:    _
    27          plan9:   _
    28          windows: _
    29      }
    30  }
    31  
    32  Split: [OS=#AnyOS]: [ARG=string]: path.Split(ARG, OS)
    33  Split: default:     [ARG=string]: path.Split(ARG)
    34  Split: default:     Split.unix
    35  Split: [_]: {
    36      "/foo/bar/baz":       _
    37      "a/b":                _
    38      "//host/share/foo":   _
    39      #"\\host\share\foo"#: _
    40      "c:/foo/bar":         _
    41      #"c:\foo\bar"#:       _
    42  }
    43  
    44  SplitList: [OS=string]: [ARG=string]: path.SplitList(ARG, OS)
    45  SplitList: [_]: {
    46      "a:b":      _
    47      "a\u0000b": _
    48      "a;b":      _
    49  }
    50  
    51  Clean: [OS=#AnyOS]: [ARG=string]: path.Clean(ARG, OS)
    52  Clean: default:     [ARG=string]: path.Clean(ARG)
    53  Clean: default:     Clean.unix
    54  Clean: [_]: {
    55      "abc//def//ghi":      _
    56      #"c:\abc\def\..\.."#: _
    57  }
    58  
    59  Match: [OS=#AnyOS]: [Pattern=string]: [Name=string]: path.Match(Pattern, Name, OS)
    60  Match: default: [Pattern=string]: [Name=string]: path.Match(Pattern, Name)
    61  Match: default: Match.unix
    62  Match: [_]: {
    63      "*c":    "abc":               _
    64      "*.txt": "a/b.txt":           _
    65      "*.zip": #"c:\a\b\file.zip"#: _
    66  }
    67  
    68  Slash: [OS=string]: [ARG=string]: {
    69      to:   path.ToSlash(ARG, OS)
    70      from: path.FromSlash(ARG, OS)
    71  
    72      // should roundtrip
    73      to:   path.ToSlash(from, OS)
    74      from: path.FromSlash(to, OS)
    75  }
    76  Slash: [_]: {
    77      "":      _
    78      "/":     _
    79      "/a/b":  _
    80      "/a//b": _
    81  }
    82  
    83  Ext: [OS=#AnyOS]: [ARG=string]: path.Ext(ARG, OS)
    84  Ext: default:     [ARG=string]: path.Ext(ARG)
    85  Ext: default:     Ext.unix
    86  Ext: [_]: {
    87      // Same for all OS-es
    88      "path.go":    ".go"
    89      "path.pb.go": ".go"
    90      "a.dir/b":    ""
    91      "a.dir/b.go": ".go"
    92      "a.dir/":     ""
    93  
    94      // Differs on Windows.
    95      "a.dir\\foo": _
    96  }
    97  
    98  Resolve: [OS=#AnyOS]: [A1=_]: [A2=_]: path.Resolve(A1, A2, OS)
    99  Resolve: default:     [A1=_]: [A2=_]: path.Resolve(A1, A2)
   100  Resolve: default:     Resolve.unix
   101  Resolve: [_]: {
   102      "a/b/c": "d/e":   _
   103      "/a/b":  "/c/d":  _
   104      "c:/a":  #"d:\"#: _
   105  
   106      "//home/user/foo": "bar":             _
   107      "//home/user/foo": "//other/abs/foo": _
   108  }
   109  
   110  IsAbs: [OS=#AnyOS]: [ARG=string]: path.IsAbs(ARG, OS)
   111  IsAbs: default:     [ARG=string]: path.IsAbs(ARG)
   112  IsAbs: default:     IsAbs.unix
   113  IsAbs: [_]: {
   114      "":     _
   115      "/a":   _
   116      "a":    _
   117      "c:":   _
   118      "c:/":  _
   119      "c:\\": _
   120  
   121      "//home/user/foo": _
   122  }
   123  
   124  
   125  Volume: [OS=string]:   [ARG=string]: path.VolumeName(ARG, OS)
   126  Volume: [!="windows"]: [string]:     "" // non-windows is always ""
   127  Volume: [_]: {
   128      "c:/foo/bar": _
   129      "c:":         _
   130      "2:":         _
   131      "":           _
   132  
   133      #"\\\host"#:          _
   134      #"\\\host\"#:         _
   135      #"\\\host\share"#:    _
   136      #"\\\host\\share"#:   _
   137      #"\\host"#:           _
   138      #"//host"#:           _
   139      #"\\host\"#:          _
   140      #"//host/"#:          _
   141      #"\\host\share"#:     _
   142      #"//host/share"#:     _
   143      #"\\host\share\"#:    _
   144      #"//host/share/"#:    _
   145      #"\\host\share\foo"#: _
   146      #"//host/share/foo"#: _
   147  
   148      #"\\host\share\\foo\\\bar\\\\baz"#: _
   149      #"//host/share//foo///bar////baz"#: _
   150      #"\\host\share\foo\..\bar"#:        _
   151      #"//host/share/foo/../bar"#:        _
   152  }
   153  
   154  -- out/path --
   155  #OSes: ["unix", "windows", "plan9"]
   156  #AnyOS: "unix" | "windows" | "plan9"
   157  Split: {
   158  	default: {
   159  		"/foo/bar/baz": ["/foo/bar/", "baz"]
   160  		"a/b": ["a/", "b"]
   161  		"//host/share/foo": ["//host/share/", "foo"]
   162  		"\\\\host\\share\\foo": ["", "\\\\host\\share\\foo"]
   163  		"c:/foo/bar": ["c:/foo/", "bar"]
   164  		"c:\\foo\\bar": ["", "c:\\foo\\bar"]
   165  	}
   166  	unix: {
   167  		"/foo/bar/baz": ["/foo/bar/", "baz"]
   168  		"a/b": ["a/", "b"]
   169  		"//host/share/foo": ["//host/share/", "foo"]
   170  		"\\\\host\\share\\foo": ["", "\\\\host\\share\\foo"]
   171  		"c:/foo/bar": ["c:/foo/", "bar"]
   172  		"c:\\foo\\bar": ["", "c:\\foo\\bar"]
   173  	}
   174  	plan9: {
   175  		"/foo/bar/baz": ["/foo/bar/", "baz"]
   176  		"a/b": ["a/", "b"]
   177  		"//host/share/foo": ["//host/share/", "foo"]
   178  		"\\\\host\\share\\foo": ["", "\\\\host\\share\\foo"]
   179  		"c:/foo/bar": ["c:/foo/", "bar"]
   180  		"c:\\foo\\bar": ["", "c:\\foo\\bar"]
   181  	}
   182  	windows: {
   183  		"/foo/bar/baz": ["/foo/bar/", "baz"]
   184  		"a/b": ["a/", "b"]
   185  		"//host/share/foo": ["//host/share/", "foo"]
   186  		"\\\\host\\share\\foo": ["\\\\host\\share\\", "foo"]
   187  		"c:/foo/bar": ["c:/foo/", "bar"]
   188  		"c:\\foo\\bar": ["c:\\foo\\", "bar"]
   189  	}
   190  }
   191  SplitList: {
   192  	unix: {
   193  		"a:b": ["a", "b"]
   194  		"a\u0000b": ["a\u0000b"]
   195  		"a;b": ["a;b"]
   196  	}
   197  	plan9: {
   198  		"a:b": ["a:b"]
   199  		"a\u0000b": ["a", "b"]
   200  		"a;b": ["a;b"]
   201  	}
   202  	windows: {
   203  		"a:b": ["a:b"]
   204  		"a\u0000b": ["a\u0000b"]
   205  		"a;b": ["a", "b"]
   206  	}
   207  }
   208  Clean: {
   209  	default: {
   210  		"abc//def//ghi":        "abc/def/ghi"
   211  		"c:\\abc\\def\\..\\..": "c:\\abc\\def\\..\\.."
   212  	}
   213  	unix: {
   214  		"abc//def//ghi":        "abc/def/ghi"
   215  		"c:\\abc\\def\\..\\..": "c:\\abc\\def\\..\\.."
   216  	}
   217  	plan9: {
   218  		"abc//def//ghi":        "abc/def/ghi"
   219  		"c:\\abc\\def\\..\\..": "c:\\abc\\def\\..\\.."
   220  	}
   221  	windows: {
   222  		"abc//def//ghi":        "abc\\def\\ghi"
   223  		"c:\\abc\\def\\..\\..": "c:\\"
   224  	}
   225  }
   226  Match: {
   227  	default: {
   228  		"*c": {
   229  			abc: true
   230  		}
   231  		"*.txt": {
   232  			"a/b.txt": false
   233  		}
   234  		"*.zip": {
   235  			"c:\\a\\b\\file.zip": true
   236  		}
   237  	}
   238  	unix: {
   239  		"*c": {
   240  			abc: true
   241  		}
   242  		"*.txt": {
   243  			"a/b.txt": false
   244  		}
   245  		"*.zip": {
   246  			"c:\\a\\b\\file.zip": true
   247  		}
   248  	}
   249  	plan9: {
   250  		"*c": {
   251  			abc: true
   252  		}
   253  		"*.txt": {
   254  			"a/b.txt": false
   255  		}
   256  		"*.zip": {
   257  			"c:\\a\\b\\file.zip": true
   258  		}
   259  	}
   260  	windows: {
   261  		"*c": {
   262  			abc: true
   263  		}
   264  		"*.txt": {
   265  			"a/b.txt": true
   266  		}
   267  		"*.zip": {
   268  			"c:\\a\\b\\file.zip": false
   269  		}
   270  	}
   271  }
   272  Slash: {
   273  	unix: {
   274  		"": {
   275  			// should roundtrip
   276  			to:   ""
   277  			from: ""
   278  		}
   279  		"/": {
   280  			// should roundtrip
   281  			to:   "/"
   282  			from: "/"
   283  		}
   284  		"/a/b": {
   285  			// should roundtrip
   286  			to:   "/a/b"
   287  			from: "/a/b"
   288  		}
   289  		"/a//b": {
   290  			// should roundtrip
   291  			to:   "/a//b"
   292  			from: "/a//b"
   293  		}
   294  	}
   295  	plan9: {
   296  		"": {
   297  			// should roundtrip
   298  			to:   ""
   299  			from: ""
   300  		}
   301  		"/": {
   302  			// should roundtrip
   303  			to:   "/"
   304  			from: "/"
   305  		}
   306  		"/a/b": {
   307  			// should roundtrip
   308  			to:   "/a/b"
   309  			from: "/a/b"
   310  		}
   311  		"/a//b": {
   312  			// should roundtrip
   313  			to:   "/a//b"
   314  			from: "/a//b"
   315  		}
   316  	}
   317  	windows: {
   318  		"": {
   319  			// should roundtrip
   320  			to:   ""
   321  			from: ""
   322  		}
   323  		"/": {
   324  			// should roundtrip
   325  			to:   "/"
   326  			from: "\\"
   327  		}
   328  		"/a/b": {
   329  			// should roundtrip
   330  			to:   "/a/b"
   331  			from: "\\a\\b"
   332  		}
   333  		"/a//b": {
   334  			// should roundtrip
   335  			to:   "/a//b"
   336  			from: "\\a\\\\b"
   337  		}
   338  	}
   339  }
   340  Ext: {
   341  	default: {
   342  		// Same for all OS-es
   343  		"path.go":    ".go"
   344  		"path.pb.go": ".go"
   345  		"a.dir/b":    ""
   346  		"a.dir/b.go": ".go"
   347  		"a.dir/":     ""
   348  
   349  		// Differs on Windows.
   350  		"a.dir\\foo": ".dir\\foo"
   351  	}
   352  	unix: {
   353  		// Same for all OS-es
   354  		"path.go":    ".go"
   355  		"path.pb.go": ".go"
   356  		"a.dir/b":    ""
   357  		"a.dir/b.go": ".go"
   358  		"a.dir/":     ""
   359  
   360  		// Differs on Windows.
   361  		"a.dir\\foo": ".dir\\foo"
   362  	}
   363  	plan9: {
   364  		// Same for all OS-es
   365  		"path.go":    ".go"
   366  		"path.pb.go": ".go"
   367  		"a.dir/b":    ""
   368  		"a.dir/b.go": ".go"
   369  		"a.dir/":     ""
   370  
   371  		// Differs on Windows.
   372  		"a.dir\\foo": ".dir\\foo"
   373  	}
   374  	windows: {
   375  		// Same for all OS-es
   376  		"path.go":    ".go"
   377  		"path.pb.go": ".go"
   378  		"a.dir/b":    ""
   379  		"a.dir/b.go": ".go"
   380  		"a.dir/":     ""
   381  
   382  		// Differs on Windows.
   383  		"a.dir\\foo": ""
   384  	}
   385  }
   386  Resolve: {
   387  	default: {
   388  		"a/b/c": {
   389  			"d/e": "a/b/c/d/e"
   390  		}
   391  		"/a/b": {
   392  			"/c/d": "/c/d"
   393  		}
   394  		"c:/a": {
   395  			"d:\\": "c:/a/d:\\"
   396  		}
   397  		"//home/user/foo": {
   398  			bar:               "/home/user/foo/bar"
   399  			"//other/abs/foo": "/other/abs/foo"
   400  		}
   401  	}
   402  	unix: {
   403  		"a/b/c": {
   404  			"d/e": "a/b/c/d/e"
   405  		}
   406  		"/a/b": {
   407  			"/c/d": "/c/d"
   408  		}
   409  		"c:/a": {
   410  			"d:\\": "c:/a/d:\\"
   411  		}
   412  		"//home/user/foo": {
   413  			bar:               "/home/user/foo/bar"
   414  			"//other/abs/foo": "/other/abs/foo"
   415  		}
   416  	}
   417  	plan9: {
   418  		"a/b/c": {
   419  			"d/e": "a/b/c/d/e"
   420  		}
   421  		"/a/b": {
   422  			"/c/d": "/c/d"
   423  		}
   424  		"c:/a": {
   425  			"d:\\": "c:/a/d:\\"
   426  		}
   427  		"//home/user/foo": {
   428  			bar:               "/home/user/foo/bar"
   429  			"//other/abs/foo": "/other/abs/foo"
   430  		}
   431  	}
   432  	windows: {
   433  		"a/b/c": {
   434  			"d/e": "a\\b\\c\\d\\e"
   435  		}
   436  		"/a/b": {
   437  			"/c/d": "\\a\\b\\c\\d"
   438  		}
   439  		"c:/a": {
   440  			"d:\\": "d:\\"
   441  		}
   442  		"//home/user/foo": {
   443  			bar:               "\\\\home\\user\\foo\\bar"
   444  			"//other/abs/foo": "\\\\other\\abs\\foo"
   445  		}
   446  	}
   447  }
   448  IsAbs: {
   449  	default: {
   450  		"":                false
   451  		"/a":              true
   452  		a:                 false
   453  		"c:":              false
   454  		"c:/":             false
   455  		"c:\\":            false
   456  		"//home/user/foo": true
   457  	}
   458  	unix: {
   459  		"":                false
   460  		"/a":              true
   461  		a:                 false
   462  		"c:":              false
   463  		"c:/":             false
   464  		"c:\\":            false
   465  		"//home/user/foo": true
   466  	}
   467  	plan9: {
   468  		"":                false
   469  		"/a":              true
   470  		a:                 false
   471  		"c:":              false
   472  		"c:/":             false
   473  		"c:\\":            false
   474  		"//home/user/foo": true
   475  	}
   476  	windows: {
   477  		"":                false
   478  		"/a":              false
   479  		a:                 false
   480  		"c:":              false
   481  		"c:/":             true
   482  		"c:\\":            true
   483  		"//home/user/foo": true
   484  	}
   485  }
   486  Volume: {
   487  	unix: {
   488  		"c:/foo/bar":                                 ""
   489  		"c:":                                         ""
   490  		"2:":                                         ""
   491  		"":                                           ""
   492  		"\\\\\\host":                                 ""
   493  		"\\\\\\host\\":                               ""
   494  		"\\\\\\host\\share":                          ""
   495  		"\\\\\\host\\\\share":                        ""
   496  		"\\\\host":                                   ""
   497  		"//host":                                     ""
   498  		"\\\\host\\":                                 ""
   499  		"//host/":                                    ""
   500  		"\\\\host\\share":                            ""
   501  		"//host/share":                               ""
   502  		"\\\\host\\share\\":                          ""
   503  		"//host/share/":                              ""
   504  		"\\\\host\\share\\foo":                       ""
   505  		"//host/share/foo":                           ""
   506  		"\\\\host\\share\\\\foo\\\\\\bar\\\\\\\\baz": ""
   507  		"//host/share//foo///bar////baz":             ""
   508  		"\\\\host\\share\\foo\\..\\bar":              ""
   509  		"//host/share/foo/../bar":                    ""
   510  	}
   511  	plan9: {
   512  		"c:/foo/bar":                                 ""
   513  		"c:":                                         ""
   514  		"2:":                                         ""
   515  		"":                                           ""
   516  		"\\\\\\host":                                 ""
   517  		"\\\\\\host\\":                               ""
   518  		"\\\\\\host\\share":                          ""
   519  		"\\\\\\host\\\\share":                        ""
   520  		"\\\\host":                                   ""
   521  		"//host":                                     ""
   522  		"\\\\host\\":                                 ""
   523  		"//host/":                                    ""
   524  		"\\\\host\\share":                            ""
   525  		"//host/share":                               ""
   526  		"\\\\host\\share\\":                          ""
   527  		"//host/share/":                              ""
   528  		"\\\\host\\share\\foo":                       ""
   529  		"//host/share/foo":                           ""
   530  		"\\\\host\\share\\\\foo\\\\\\bar\\\\\\\\baz": ""
   531  		"//host/share//foo///bar////baz":             ""
   532  		"\\\\host\\share\\foo\\..\\bar":              ""
   533  		"//host/share/foo/../bar":                    ""
   534  	}
   535  	windows: {
   536  		"c:/foo/bar":                                 "c:"
   537  		"c:":                                         "c:"
   538  		"2:":                                         ""
   539  		"":                                           ""
   540  		"\\\\\\host":                                 ""
   541  		"\\\\\\host\\":                               ""
   542  		"\\\\\\host\\share":                          ""
   543  		"\\\\\\host\\\\share":                        ""
   544  		"\\\\host":                                   ""
   545  		"//host":                                     ""
   546  		"\\\\host\\":                                 ""
   547  		"//host/":                                    ""
   548  		"\\\\host\\share":                            "\\\\host\\share"
   549  		"//host/share":                               "//host/share"
   550  		"\\\\host\\share\\":                          "\\\\host\\share"
   551  		"//host/share/":                              "//host/share"
   552  		"\\\\host\\share\\foo":                       "\\\\host\\share"
   553  		"//host/share/foo":                           "//host/share"
   554  		"\\\\host\\share\\\\foo\\\\\\bar\\\\\\\\baz": "\\\\host\\share"
   555  		"//host/share//foo///bar////baz":             "//host/share"
   556  		"\\\\host\\share\\foo\\..\\bar":              "\\\\host\\share"
   557  		"//host/share/foo/../bar":                    "//host/share"
   558  	}
   559  }