aboutsummaryrefslogtreecommitdiff
path: root/challenge-253/barroff/nim/ch_1.nim
blob: 19daff58c5e05f0eb03dfb04e023ec411ca0b0b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import std/unittest

from std/strutils import split

# run tests with following command:
# nim c -r ch_1.nim

proc split_strings(separator: char, words: openArray[string]): seq[string] =
  for word in words:
    for s in split(word, separator):
      if len(s) > 0:
        result.add(s)


suite "split strings":
  test """("one.two.three","four.five","six")""":
    let
      words = ["one.two.three", "four.five", "six"]
      separator = '.'

    check(split_strings(separator, words) == @["one", "two", "three", "four",
        "five", "six"])

  test """("$perl$$", "$$raku$")""":
    let
      words = ["$perl$$", "$$raku$"]
      separator = '$'

    check(split_strings(separator, words) == @["perl", "raku"])