all repos — min @ snap

A small but practical concatenative programming language.

tests/str.min

 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
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
'test load
'test import

"str" describe
  
  ("$1 - $2 - $3" (1 true "test") interpolate "1 - true - test" ==) assert

  ("$1 + $2 = $3" (2 2 (2 2 +)) apply interpolate "2 + 2 = 4" ==) assert

  (" test   " strip "test" ==) assert

  ("test" length 4 ==) assert

  ("a,b,c" "," split ("a" "b" "c") ==) assert

  ("abc" "" split ("a" "b" "c") ==) assert

  ("This is a test" 5 2 substr "is" ==) assert

  ("this" 2 3 substr "is" ==) assert

  ("This is a test" "is" indexof 2 ==) assert

  ("test #1" "[0-9]" search ("1") ==) assert 

  ("a" ord 97 ==) assert

  (97 chr "a" ==) assert

  ("This is test #1" "test #([0-9])" search ("test #1" "1") ==) assert 

  ("This is a random string" "random" match true ==) assert

  ("something is not something else" "some" "any" replace "anything is not anything else" ==) assert

  ("MiN is a concatenative programming language" "/^min/i" =~ ("MiN") ==) assert

  ("This is a difficult test" "s/difficult/simple/" =~ ("This is a simple test") ==) assert

  ("This is a DIFFICULT\n test" "s/difficult/simple/mis" =~ ("This is a simple\n test") ==) assert

  ("this is a test" uppercase "THIS IS A TEST" ==) assert

  ("THIS IS A TEST" lowercase "this is a test" ==) assert

  ("test" capitalize "Test" ==) assert

  ("this is a test" titleize "This Is A Test" ==) assert

  ("+" 3 repeat "+++" ==) assert

  ("test" 4 indent "    test" ==) assert

  ((1 3 "test") ", " join "1, 3, test" ==) assert

  ("PWD: $pwd" ("pwd" .) =% ("PWD: " .) => "" join ==) assert 

  ("1.2.3" from-semver {1 :major 2 :minor 3 :patch} ==) assert

  ({2 :major 25 :minor 300 :patch} to-semver "2.25.300" ==) assert

  ("2.3.6" semver-inc-major "3.0.0" ==) assert
  
  ("2.3.6" semver-inc-minor "2.4.0" ==) assert

  ("2.3.6" semver-inc-patch "2.3.7" ==) assert
  
  ("4.6.5" semver? true ==) assert
  
  ("4.6.5.3" semver? false ==) assert
  
  ("fix" "pre" prefix "prefix" ==) assert
  
  ("suf" "fix" suffix "suffix" ==) assert
  
  ("http://test.com?€%,,!{}" encode-url "http%3A%2F%2Ftest.com%3F%E2%82%AC%25%2C%2C%21%7B%7D" ==) assert
  
  ("http%3A%2F%2Ftest.com%3F%E2%82%AC%25%2C%2C%21%7B%7D" decode-url "http://test.com?€%,,!{}" ==) assert
  
  ("http://h3rald.com/a/b/c?test=1#123" parse-url {"123" :anchor "h3rald.com" :hostname "" :password "/a/b/c" :path "" :port "test=1" :query "http" :scheme "" :username} ==) assert
  
  report
  clear-stack