...

Text file src/cuelang.org/go/pkg/path/testdata/os.txtar

Documentation: cuelang.org/go/pkg/path/testdata

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

View as plain text