Skip to content

Commit

Permalink
add String#starts_with?:
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Dec 6, 2012
1 parent bec9b93 commit 27ce7ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/string.fy
Expand Up @@ -281,4 +281,8 @@ class String {
{ return false } if: blank? { return false } if: blank?
lowercase == self lowercase == self
} }

def starts_with?: string {
from: 0 to: (string size - 1) == string
}
} }
10 changes: 10 additions & 0 deletions tests/string.fy
Expand Up @@ -264,4 +264,14 @@ FancySpec describe: String with: {
"A" lowercase? is: false "A" lowercase? is: false
"abc" lowercase? is: true "abc" lowercase? is: true
} }

it: "returns true if its begins with another string" with: 'starts_with?: when: {
"" starts_with?: "" . is: true
"foo" starts_with?: "f" . is: true
"foo" starts_with?: "fo" . is: true
"foo" starts_with?: "foo" . is: true
"foo" starts_with?: "fooo" . is: false
"foo" starts_with?: "oo" . is: false
"foo" starts_with?: "" . is: false
}
} }

0 comments on commit 27ce7ef

Please sign in to comment.