all repos — min @ 0755480db9d686d8b9b799428081841566ecc0c2

A small but practical concatenative programming language.

tests/lang.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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
'test load
'test import

"lang" describe

  (2 'a define
    (3 a + (5 'a define a) -> +) -> a + 12 ==) assert

  (symbols "a" in? false ==) assert

  ('abcdefg defined? false ==) assert
  
  5 :five
  (symbols "five" in?) assert

  (
    ((1 2 3 4 5 6)) :test-data

    (
      :item
      "_$1" (item) => % :namesym
      (item dup *) namesym define
      namesym ROOT publish
    ) :def

    test-data (def) foreach

    _2 _5 _1 + +
    30 ==
  ) assert
  
  
  ~five
  (symbols "five" in? false  ==) assert

  {
    (+) :myplus
  } +mymath

  (symbols "mymath" in?) assert
  
  ('mymath import symbols "myplus" in?) assert

  ('mymath import 2 3 myplus 5 ==) assert

  (2 3 mymath ^myplus 5 ==) assert

  ; Extend an existing scope
  ;(
  ;  ('mymath import 
  ;   (-) :myminus
  ;  ) @mymath 5 2 mymath ^myminus 3 ==) assert
  ; 
  ;(mymath inspect ("myminus" "myplus") ==) assert

  ("3 4 +" eval 7 ==) assert

  ("2 2 +" "tests/testload.min" fwrite 'testload load 4 ==) assert
  "tests/testload.min" rm

  (2 2 mymath ^myplus 4 ==) assert
  

  (2 quote (2) ==) assert

  ((2 3) dequote get-stack (2 3) ==) assert

  (3 (succ) 3 times 6 ==) assert

  ((2 3 >) ("YES") ("NO") if "NO" ==) assert
  ((2 3 <) ("YES") ("NO") if "YES" ==) assert

  ("NO" (2 3 >) ("YES") when "NO" ==) assert

  ((2 3 <) ("YES") when "YES" ==) assert

  ((2 3 >) ("YES") unless "YES" ==) assert


  (5 (dup 0 ==) (1 +) (dup 1 -) ( * ) linrec 120 ==) assert ;factorial of 5

  (
   (
    (pop) 
    ('error dget) 
    ("finally")
    ) try get-stack ("MinEmptyStackError" "finally") ==) assert 

  ("aaaa" :cd cd "aaaa" ==) assert ;It is possible to shadow sealed symbols in child scopes

  (((2 :a1 'a1 seal 3 :a1) ("failed")) try "failed" ==) assert

  (
    1 :a1
    'a1 seal
    'a1 unseal
    2 :a1
    2 a1 ==) assert

  (
   (
    ({"TestError" :error "Test Message" :message} raise)
    (/error)
    ) try "TestError" ==) assert

  (
   (("test" (1 2) :)) try get-stack ("test") ==) assert

  (
   (
    (() 1 get)
    (1)
    ) try 1 ==) assert

  ((a b +) {4 :a 5 :b} with 9 ==) assert

  ("{\"a\": 1, \"b\": 2.3}" from-json {1 :a 2.3 :b} ==) assert

  ((1 2 3 "aaa" 'q q true) to-json "\r\n" "" replace "\n" "" replace " " "" replace "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]"  ==) assert

  ((1 2 3 "aaa" 'q q true) to-json from-json (1 2 3 "aaa" 'q q true)  ==) assert

  (((1 2 3)) :sym1 >sym1 stored-symbols "sym1" in?) assert

  (<sym1 symbols "sym1" in?) assert

  ('sym1 remove-symbol stored-symbols "sym1" in? false ==) assert

  (0 :temp (1 2 3) (temp + @temp) foreach 6 temp ==) assert

  ((1 +) :mysucc 'mysucc source (1 +) ==) assert

  (6 
    (
      ((3 ==) (false))
      ((3 <) (false))
      ((3 >) (true))
    ) case
  ) assert

  (time scope-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp" "to-timestamp") ==) assert

  (sys scope-sigils ("!" "$" "&") ==) assert

  ({3 :a 5 :b} scope-symbols ("a" "b") ==) assert

  (opts {} ==) assert

  (args first "\.min$" match) assert

  (3 string "3" ==) assert
  
  ("false" bool false ==) assert
  
  ("" bool false ==) assert
  
  (0 bool false ==) assert
  
  (false bool false ==) assert
  
  (0.0 bool false ==) assert
  
  ("something" bool true ==) assert

  ("345" int 345 ==) assert

  (true int 1 ==) assert

  (3.5 int 3 ==) assert

  (3.5 float 3.5 ==) assert

  (3 float 3.0 ==) assert

  (false float 0.0 ==) assert

  ("3.678" float 3.678 ==) assert

  (
    {1 :a 2 :b 3 :c} (
      (dup /a  succ succ %a)
      (dup /b  succ %b)
    ) tap
    {3 :a 3 :b 3 :c} ==
  ) assert

  (
    {} :data
    data (
      1 %a
      2 %b
    ) tap
    {1 :a 2 :b} ==
  ) assert

  (
    "" :s1
    "test" (
      (' "1" swap append "" join)
      (' "2" swap append "" join)
      (' "3" swap append "" join @s1 s1)
    ) tap!
    s1 "test123" ==
  ) assert

  (3.4 "test" 1 (int string num) expect (3.4 "test" 1) ==) assert

  ("2 2 +" "testread.min" fwrite "testread.min" read (2 2 +) ==) assert

  "testread.min" rm

  ("aaa bbb ccc 2 2 + (2 3 4)" parse (aaa bbb ccc 2 2 + (2 3 4)) ==) assert

  (lite? false ==) assert

  report
  ; Tidy up
  clear-stack