Skip to content

Commit 9b247f1

Browse files
committed
feat(string): adding string:repeat
1 parent 94b76c2 commit 9b247f1

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

String.ark

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@
129129
(set _index (- _index 1)) })
130130
_returnedString }))
131131

132+
# @brief Repeat a string
133+
# @param _string string to repeat
134+
# @param _count number of times to repeat said string
135+
# =begin
136+
# (import std.String)
137+
# (print (string:repeat "a" 5)) # aaaaa
138+
# =end
139+
# @author https://github.com/SuperFola
140+
(let repeat (fun (_string _count) {
141+
(assert (> _count 0) "count must be >= 1")
142+
(mut _i 0)
143+
(mut _output "")
144+
145+
(while (< _i _count) {
146+
(set _output (+ _output _string))
147+
(set _i (+ 1 _i)) })
148+
_output }))
149+
132150
# @brief Get a slice of a given string, from a given index with a given length
133151
# @param _string the string to get a slice of
134152
# @param _startingIndex the index in the string where to start slicing

tests/string-tests.ark

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
(test:eq "" (string:reverse ""))
2222
(test:eq "a" (string:reverse "a"))
2323

24+
(test:eq "" (string:repeat "" 5))
25+
(test:eq "a" (string:repeat "a" 1))
26+
(test:eq "aaaaa" (string:repeat "a" 5))
27+
2428
(test:eq "hello" (string:slice "hello world" 0 5))
2529
(test:eq "hello world" (string:slice "hello world" 0 100))
2630
(test:eq "h" (string:slice "hello world" 0 1))

tests/sys-tests.ark

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
(import std.Testing)
33

44
(test:suite sys {
5-
(test:eq builtin__sys:platform sys:platform)
6-
(test:expect (!= "" sys:platform))
5+
(test:case "platform" {
6+
(test:eq builtin__sys:platform sys:platform)
7+
(test:expect (!= "" sys:platform)) })
78

8-
(test:eq builtin__sys:args sys:args)
9-
(test:eq (type sys:args) "List") })
9+
(test:case "args" {
10+
(test:eq builtin__sys:args sys:args)
11+
(test:eq (type sys:args) "List") })
12+
13+
(test:case "programName" {
14+
(test:eq builtin__sys:programName sys:programName)
15+
(test:eq (type sys:programName) "String") })})

0 commit comments

Comments
 (0)