Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
dfb2af60
Commit
dfb2af60
authored
14 years ago
by
Ivan Krasin
Committed by
Russ Cox
14 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: add IsAbs
R=rsc, imkrasin, r CC=golang-dev
https://golang.org/cl/1969042
parent
e56c0555
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
src/pkg/path/path.go
src/pkg/path/path.go
+6
-0
src/pkg/path/path_test.go
src/pkg/path/path_test.go
+24
-0
No files found.
src/pkg/path/path.go
View file @
dfb2af60
...
...
@@ -208,3 +208,9 @@ func Base(name string) string {
}
return
name
}
// IsAbs returns true if the path is absolute.
func
IsAbs
(
path
string
)
bool
{
// TODO: Add Windows support
return
strings
.
HasPrefix
(
path
,
"/"
)
}
This diff is collapsed.
Click to expand it.
src/pkg/path/path_test.go
View file @
dfb2af60
...
...
@@ -307,3 +307,27 @@ func TestBase(t *testing.T) {
}
}
}
type
IsAbsTest
struct
{
path
string
isAbs
bool
}
var
isAbsTests
=
[]
IsAbsTest
{
IsAbsTest
{
""
,
false
},
IsAbsTest
{
"/"
,
true
},
IsAbsTest
{
"/usr/bin/gcc"
,
true
},
IsAbsTest
{
".."
,
false
},
IsAbsTest
{
"/a/../bb"
,
true
},
IsAbsTest
{
"."
,
false
},
IsAbsTest
{
"./"
,
false
},
IsAbsTest
{
"lala"
,
false
},
}
func
TestIsAbs
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
isAbsTests
{
if
r
:=
IsAbs
(
test
.
path
);
r
!=
test
.
isAbs
{
t
.
Errorf
(
"IsAbs(%q) = %v, want %v"
,
test
.
path
,
r
,
test
.
isAbs
)
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment