libgo: update to Go 1.11
[official-gcc.git] / libgo / go / path / example_test.go
blob77fbfa99b73a260dbbe194a9560fe43bcc9931ec
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build gccgo_examples
7 package path
9 import (
10 "fmt"
11 "path"
14 func ExampleBase() {
15 fmt.Println(path.Base("/a/b"))
16 fmt.Println(path.Base("/"))
17 fmt.Println(path.Base(""))
18 // Output:
19 // b
20 // /
21 // .
24 func ExampleClean() {
25 paths := []string{
26 "a/c",
27 "a//c",
28 "a/c/.",
29 "a/c/b/..",
30 "/../a/c",
31 "/../a/b/../././/c",
32 "",
35 for _, p := range paths {
36 fmt.Printf("Clean(%q) = %q\n", p, path.Clean(p))
39 // Output:
40 // Clean("a/c") = "a/c"
41 // Clean("a//c") = "a/c"
42 // Clean("a/c/.") = "a/c"
43 // Clean("a/c/b/..") = "a/c"
44 // Clean("/../a/c") = "/a/c"
45 // Clean("/../a/b/../././/c") = "/a/c"
46 // Clean("") = "."
49 func ExampleDir() {
50 fmt.Println(path.Dir("/a/b/c"))
51 fmt.Println(path.Dir("a/b/c"))
52 fmt.Println(path.Dir("/a/"))
53 fmt.Println(path.Dir("a/"))
54 fmt.Println(path.Dir("/"))
55 fmt.Println(path.Dir(""))
56 // Output:
57 // /a/b
58 // a/b
59 // /a
60 // a
61 // /
62 // .
65 func ExampleExt() {
66 fmt.Println(path.Ext("/a/b/c/bar.css"))
67 fmt.Println(path.Ext("/"))
68 fmt.Println(path.Ext(""))
69 // Output:
70 // .css
75 func ExampleIsAbs() {
76 fmt.Println(path.IsAbs("/dev/null"))
77 // Output: true
80 func ExampleJoin() {
81 fmt.Println(path.Join("a", "b", "c"))
82 fmt.Println(path.Join("a", "b/c"))
83 fmt.Println(path.Join("a/b", "c"))
84 fmt.Println(path.Join("", ""))
85 fmt.Println(path.Join("a", ""))
86 fmt.Println(path.Join("", "a"))
87 // Output:
88 // a/b/c
89 // a/b/c
90 // a/b/c
92 // a
93 // a
96 func ExampleMatch() {
97 fmt.Println(path.Match("abc", "abc"))
98 fmt.Println(path.Match("a*", "abc"))
99 fmt.Println(path.Match("a*/b", "a/c/b"))
100 // Output:
101 // true <nil>
102 // true <nil>
103 // false <nil>
106 func ExampleSplit() {
107 fmt.Println(path.Split("static/myfile.css"))
108 fmt.Println(path.Split("myfile.css"))
109 fmt.Println(path.Split(""))
110 // Output:
111 // static/ myfile.css
112 // myfile.css