nendo 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,7 @@
32
32
  var))
33
33
 
34
34
  (test* "disasm info"
35
- " file: ./test/util-test.nnd
35
+ " file: ./test/nendo-util-test.nnd
36
36
  lineno: 30
37
37
  source:
38
38
  (define
@@ -69,7 +69,7 @@ trampCall(
69
69
  ___lambda = lambda { |_var|
70
70
  begin
71
71
  trampCall(_var)
72
- rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:32\"] + __e.backtrace ) ; raise __e
72
+ rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:32\"] + __e.backtrace ) ; raise __e
73
73
  end
74
74
  } ; ___lambda.call(
75
75
  trampCall( self.__PLMARK_METHOD( '+',
@@ -77,12 +77,12 @@ trampCall(
77
77
  if @global_lisp_binding.has_key?('__PLMARK') then
78
78
  trampCall(@__PLMARK)
79
79
  else raise NameError.new( \"Error: undefined variable __PLMARK\", \"__PLMARK\" ) end
80
- rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:31\"] + __e.backtrace ) ; raise __e
80
+ rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:31\"] + __e.backtrace ) ; raise __e
81
81
  end ,
82
82
  [
83
83
  begin
84
84
  trampCall(_arg1)
85
- rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:31\"] + __e.backtrace ) ; raise __e
85
+ rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:31\"] + __e.backtrace ) ; raise __e
86
86
  end ,
87
87
  1
88
88
  ]
data/test/nendo_spec.rb CHANGED
@@ -142,7 +142,6 @@ describe Nendo, "Japanese characters in regex " do
142
142
  end
143
143
  it "should" do
144
144
  @matchData.should be_true
145
- pending( "JRuby can't compute correctly" ) if defined? JRUBY_VERSION
146
145
  @matchData[0].should == "あいうえお"
147
146
  @matchData[1].should == "あ"
148
147
  end
@@ -182,6 +181,8 @@ describe Evaluator, "When use Evaluator's util methods" do
182
181
  @evaluator.toRubySymbol( '^' ).should == '__NKMARK'
183
182
  @evaluator.toRubySymbol( "_" ).should == "__"
184
183
  @evaluator.toRubySymbol( '~' ).should == '__CHMARK'
184
+ @evaluator.toRubySymbol( '...' ).should == '__DOTDOTDOT'
185
+ @evaluator.toRubySymbol( '<...>' ).should == '__LTMARK_DOTDOTDOT_GTMARK'
185
186
  @evaluator.toRubySymbol( "a?" ).should == "_a_QUMARK"
186
187
  @evaluator.toRubySymbol( "a?" ).should == "_a_QUMARK"
187
188
  @evaluator.toRubySymbol( "a!" ).should == "_a_EXMARK"
@@ -200,6 +201,8 @@ describe Evaluator, "When use Evaluator's util methods" do
200
201
  @evaluator.toLispSymbol( "_a_b" ).should == "a_b"
201
202
  @evaluator.toLispSymbol( "_a_b_c" ).should == "a_b_c"
202
203
  @evaluator.toLispSymbol( "_A_B_C" ).should == "A_B_C"
204
+ @evaluator.toLispSymbol( "__DOTDOTDOT" ).should == "..."
205
+ @evaluator.toLispSymbol( "__LTMARK_DOTDOTDOT_GTMARK" ).should == "<...>"
203
206
  @evaluator.toRubyValue( "a" ).should == "a"
204
207
  @evaluator.toRubyValue( "b" ).should == "b"
205
208
  @evaluator.toRubyValue( "true" ).should == "true"
@@ -223,19 +226,19 @@ describe Nendo, "when call evalStr() with literals" do
223
226
  @nendo.evalStr( " 1.1 " ).should == "1.1"
224
227
  @nendo.evalStr( " 1.0 " ).should == "1.0"
225
228
  @nendo.evalStr( ' "a" ' ).should == '"a"'
226
- @nendo.evalStr( ' "日本語" ' ).should == '"日本語"'
227
229
  @nendo.evalStr( ' "\n" ' ).should == "\"\n\""
228
230
  @nendo.evalStr( ' "\r" ' ).should == "\"\\r\""
229
231
  @nendo.evalStr( ' "\t" ' ).should == "\"\\t\""
230
232
  @nendo.evalStr( ' "a" ' ).should == '"a"'
231
233
  @nendo.evalStr( ' "a\"b" ' ).should == '"a\"b"'
232
- @nendo.evalStr( ' "日\"本\"語" ' ).should == '"日\"本\"語"'
233
234
  @nendo.evalStr( " true " ).should == "#t"
234
235
  @nendo.evalStr( " false " ).should == "#f"
235
236
  @nendo.evalStr( " nil " ).should == "nil"
236
237
  @nendo.evalStr( " #t " ).should == "#t"
237
238
  @nendo.evalStr( " #f " ).should == "#f"
238
-
239
+ pending( "JRuby can't compute correctly" ) if defined? JRUBY_VERSION
240
+ @nendo.evalStr( ' "日本語" ' ).should == '"日本語"'
241
+ @nendo.evalStr( ' "日\"本\"語" ' ).should == '"日\"本\"語"'
239
242
  end
240
243
  end
241
244
 
@@ -297,8 +300,8 @@ describe Nendo, "when reference global-variables." do
297
300
  it "should" do
298
301
  @nendo.evalStr( " (pair? *load-path*) " ).should == "#t"
299
302
  @nendo.evalStr( " (string? (car *load-path*)) " ).should == "#t"
300
- @nendo.evalStr( " (car *load-path*) " ).should == "\"./spec\""
301
- @nendo.evalStr( " (car (cdr *load-path*)) " ).should == "\"./lib\""
303
+ @nendo.evalStr( " (to-arr *load-path*) " ).should include( "./spec")
304
+ @nendo.evalStr( " (to-arr *load-path*) " ).should include( "./lib")
302
305
  @nendo.evalStr( " (string? (*FILE*)) " ).should == "#t"
303
306
  @nendo.evalStr( " (number? (*LINE*)) " ).should == "#t"
304
307
  @nendo.evalStr( " *nendo-version* " ).should == '"' + Nendo::Core.version + '"'
@@ -516,6 +519,33 @@ describe Nendo, "when call evalStr() with `modulo' function" do
516
519
  end
517
520
  end
518
521
 
522
+ describe Nendo, "when use quote and syntax-quote " do
523
+ before do
524
+ @nendo = Nendo::Core.new()
525
+ end
526
+ it "should" do
527
+ @nendo.evalStr( " '() " ).should == "()"
528
+ @nendo.evalStr( " '1 " ).should == "1"
529
+ @nendo.evalStr( " '\"str\" " ).should == '"str"'
530
+ @nendo.evalStr( " '(1 . 2) " ).should == "(1 . 2)"
531
+ @nendo.evalStr( " (quote ())" ).should == "()"
532
+ @nendo.evalStr( " (quote 1)" ).should == "1"
533
+ @nendo.evalStr( " (quote \"str\") " ).should == '"str"'
534
+ @nendo.evalStr( " (quote (1 . 2)) " ).should == "(1 . 2)"
535
+ @nendo.evalStr( " (syntax-quote ())" ).should == "()"
536
+ @nendo.evalStr( " (syntax-quote 1)" ).should == "1"
537
+ @nendo.evalStr( " (syntax-quote \"str\") " ).should == '"str"'
538
+ @nendo.evalStr( " (syntax-quote (1 . 2)) " ).should == "(1 . 2)"
539
+ @nendo.evalStr( " (quote quote) " ).should == "'"
540
+ @nendo.evalStr( " 'quote " ).should == "'"
541
+ @nendo.evalStr( " ''1 " ).should == "'1"
542
+ @nendo.evalStr( " (quote syntax-quote) " ).should == "syntax-quote"
543
+ @nendo.evalStr( " (syntax-quote '1) " ).should == "'1"
544
+ @nendo.evalStr( " (syntax-quote (quote 1)) " ).should == "'1"
545
+ @nendo.evalStr( " (quote (syntax-quote 1)) " ).should == "(syntax-quote 1)"
546
+ end
547
+ end
548
+
519
549
  describe Nendo, "when read various list expressions" do
520
550
  before do
521
551
  @nendo = Nendo::Core.new()
@@ -865,10 +895,51 @@ describe Nendo, "when call evalStr() with built-in special forms" do
865
895
  @nendo.evalStr( " (apply1 + (range 10 1))" ).should == "55"
866
896
  @nendo.evalStr( " (apply1 cons '(1 2))" ).should == "(1 . 2)"
867
897
  @nendo.evalStr( " (apply1 list '(1 2 3))" ).should == "(1 2 3)"
868
- lambda { @nendo.evalStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError )
898
+ lambda { @nendo.evalStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError, /My Runtime Error/ )
899
+ lambda { @nendo.evalStr( " (error \"My Runtime Error\" '(a b c)) " ) }.should raise_error( RuntimeError, /My Runtime Error [(]a b c[)]/ )
869
900
  end
870
901
  end
871
902
 
903
+ describe Nendo, "when call evalStr() with built-in special forms (renamed symbol)" do
904
+ before do
905
+ @nendo = Nendo::Core.new()
906
+ @nendo.loadInitFile
907
+ end
908
+ it "should" do
909
+ @nendo.evalStr( " (/nendo/core/begin 1) " ).should == "1"
910
+ @nendo.evalStr( " (/nendo/core/begin 1 2) " ).should == "2"
911
+ @nendo.evalStr( " (/nendo/core/begin 1 2 3) " ).should == "3"
912
+ @nendo.evalStr( " (/nendo/core/set! x 2) (/nendo/core/set! y (/nendo/core/begin (/nendo/core/set! x (* x 2)) (/nendo/core/set! x (* x 2)) (/nendo/core/set! x (* x 2)) 100)) (+ x y)" ).should == "116"
913
+ @nendo.evalStr( " (/nendo/core/let () 100) " ).should == "100"
914
+ @nendo.evalStr( " (/nendo/core/let ((a 11)) a) " ).should == "11"
915
+ @nendo.evalStr( " (/nendo/core/let ((a 11) (b 22)) (+ a b)) " ).should == "33"
916
+ @nendo.evalStr( " (/nendo/core/let ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
917
+ @nendo.evalStr( " (/nendo/core/let ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
918
+ @nendo.evalStr( " (/nendo/core/let ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
919
+ @nendo.evalStr( " (/nendo/core/letrec () 100) " ).should == "100"
920
+ @nendo.evalStr( " (/nendo/core/letrec ((a 11)) a) " ).should == "11"
921
+ @nendo.evalStr( " (/nendo/core/letrec ((a 11) (b 22)) (+ a b)) " ).should == "33"
922
+ @nendo.evalStr( " (/nendo/core/letrec ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
923
+ @nendo.evalStr( " (/nendo/core/letrec ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
924
+ @nendo.evalStr( " (/nendo/core/letrec ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
925
+ @nendo.evalStr( " (/nendo/core/letrec ( (func1 (/nendo/core/lambda (x) 13)) (func2 (/nendo/core/lambda (x) (* 2 (func1)))) ) (list (func2) (func1))) " ).should == "(26 13)"
926
+ @nendo.evalStr( " (/nendo/core/letrec ( (func2 (/nendo/core/lambda (x) (* 2 (func1)))) (func1 (/nendo/core/lambda (x) 7)) ) (list (func2) (func1))) " ).should == "(14 7)"
927
+ @nendo.evalStr( " (/nendo/core/if true 't 'f)" ).should == "t"
928
+ @nendo.evalStr( " (/nendo/core/if true '(1) '(2))" ).should == "(1)"
929
+ @nendo.evalStr( " (/nendo/core/if false 't 'f)" ).should == "f"
930
+ @nendo.evalStr( " (/nendo/core/if false '(1) '(2))" ).should == "(2)"
931
+ @nendo.evalStr( " (/nendo/core/set! x 0) (/nendo/core/if true (set! x 1) (set! x 2)) x" ).should == "1"
932
+ @nendo.evalStr( " (/nendo/core/set! x 0) (/nendo/core/if false (set! x 1) (set! x 2)) x" ).should == "2"
933
+ @nendo.evalStr( " (/nendo/core/set! func (/nendo/core/lambda (arg1) arg1)) (list (func 1) (func 2))" ).should == "(1 2)"
934
+ @nendo.evalStr( " ((/nendo/core/lambda (arg1) arg1) 3)" ).should == "3"
935
+ @nendo.evalStr( " ((/nendo/core/lambda (arg1) arg1) (+ 1 2 3))" ).should == "6"
936
+ @nendo.evalStr( " ((/nendo/core/if #t + *) 3 4)" ).should == "7"
937
+ @nendo.evalStr( " ((/nendo/core/if #f + *) 3 4)" ).should == "12"
938
+ lambda { @nendo.evalStr( " (/nendo/core/error \"My Runtime Error\") " ) }.should raise_error( RuntimeError )
939
+ end
940
+ end
941
+
942
+
872
943
  describe Nendo, "when call evalStr() with global and lexical scope variable" do
873
944
  before do
874
945
  @nendo = Nendo::Core.new()
@@ -1176,9 +1247,15 @@ describe Nendo, "when call functions in init.nnd " do
1176
1247
  @nendo.evalStr( " (to-s 10) " ).should == '"10"'
1177
1248
  @nendo.evalStr( " (to_s 10) " ).should == '"10"'
1178
1249
  @nendo.evalStr( " (x->string 10) " ).should == '"10"'
1250
+ @nendo.evalStr( " (number->string 11) " ).should == '"11"'
1179
1251
  @nendo.evalStr( " (to-s 2.1) " ).should == '"2.1"'
1180
1252
  @nendo.evalStr( " (to_s 2.1) " ).should == '"2.1"'
1181
1253
  @nendo.evalStr( " (x->string 2.1) " ).should == '"2.1"'
1254
+ @nendo.evalStr( " (number->string 2.2) " ).should == '"2.2"'
1255
+ @nendo.evalStr( ' (string-append) ' ).should == '""'
1256
+ @nendo.evalStr( ' (string-append "a") ' ).should == '"a"'
1257
+ @nendo.evalStr( ' (string-append "a" "b") ' ).should == '"ab"'
1258
+ @nendo.evalStr( ' (string-append "a" "B" "c" "D" "e") ' ).should == '"aBcDe"'
1182
1259
  @nendo.evalStr( " (to_i \"22\") " ).should == '22'
1183
1260
  @nendo.evalStr( " (to-i \"22\") " ).should == '22'
1184
1261
  @nendo.evalStr( " (to_i \"10000\") " ).should == '10000'
@@ -1187,6 +1264,23 @@ describe Nendo, "when call functions in init.nnd " do
1187
1264
  @nendo.evalStr( " (let1 aaa (+ 2 3) aaa) " ).should == "5"
1188
1265
  @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (+ aaa bbb))) " ).should == "777"
1189
1266
  @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (set! bbb 555) (+ aaa bbb))) " ).should == "888"
1267
+ @nendo.evalStr( " (memq 'b '(a b c d)) " ).should == "(b c d)"
1268
+ @nendo.evalStr( " (memq 'c '(a b c d)) " ).should == "(c d)"
1269
+ @nendo.evalStr( " (memq 'd '(a b c d)) " ).should == "(d)"
1270
+ @nendo.evalStr( " (memq 'e '(a b c d)) " ).should == "#f"
1271
+ @nendo.evalStr( " (memq 'e '(a b c d . e)) " ).should == "#f"
1272
+ @nendo.evalStr( ' (memq "b" \'("a" "b" "c" "d")) ' ).should == '("b" "c" "d")'
1273
+ @nendo.evalStr( ' (memv "b" \'("a" "b" "c" "d")) ' ).should == '("b" "c" "d")'
1274
+ @nendo.evalStr( ' (memv "c" \'("a" "b" "c" "d")) ' ).should == '("c" "d")'
1275
+ @nendo.evalStr( ' (memv "d" \'("a" "b" "c" "d")) ' ).should == '("d")'
1276
+ @nendo.evalStr( ' (memv "e" \'("a" "b" "c" "d")) ' ).should == '#f'
1277
+ @nendo.evalStr( ' (memv "e" \'("a" "b" "c" "d" . "e")) ' ).should == '#f'
1278
+ @nendo.evalStr( ' (memv \'("b") \'(("a") ("b") ("c") ("d"))) ' ).should == '#f'
1279
+ @nendo.evalStr( ' (member \'("b") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("b") ("c") ("d"))'
1280
+ @nendo.evalStr( ' (member \'("c") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("c") ("d"))'
1281
+ @nendo.evalStr( ' (member \'("d") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("d"))'
1282
+ @nendo.evalStr( ' (member \'("e") \'(("a") ("b") ("c") ("d"))) ' ).should == '#f'
1283
+ @nendo.evalStr( ' (member \'("e") \'(("a") ("b") ("c") ("d") . ("e"))) ' ).should == '#f'
1190
1284
  @nendo.evalStr( " (let1 v (map (lambda (x) x) '(1 2 3)) v) " ).should == "(1 2 3)"
1191
1285
  @nendo.evalStr( " (let ((v (map (lambda (x) x) '(1 2 3)))) v) " ).should == "(1 2 3)"
1192
1286
  @nendo.evalStr( " (cond (true 1) (false 2)) " ).should == "1"
@@ -1270,12 +1364,18 @@ describe Nendo, "when call functions in init.nnd " do
1270
1364
  @nendo.evalStr( " (find (lambda (x) (= x 2)) '(1 2 3)) " ).should == "2"
1271
1365
  @nendo.evalStr( " (find (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "1"
1272
1366
  @nendo.evalStr( " (find (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "2"
1367
+ @nendo.evalStr( " (eq? find any)" ).should == "#f"
1368
+ @nendo.evalStr( " (find even? '(1 2 3)) " ).should == "2"
1273
1369
  @nendo.evalStr( " (filter-map (lambda (x) x) '()) " ).should == "()"
1274
1370
  @nendo.evalStr( " (filter-map (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1275
1371
  @nendo.evalStr( " (filter-map (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(#t)"
1276
1372
  @nendo.evalStr( " (filter-map (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(#t #t)"
1277
1373
  @nendo.evalStr( " (filter-map (lambda (x) (if (= x 2) (* x 10) false)) '(1 2 3)) " ).should == "(20)"
1278
1374
  @nendo.evalStr( " (filter-map (lambda (x) (if (not (= x 2)) (* x 10) false)) '(1 2 3)) " ).should == "(10 30)"
1375
+ @nendo.evalStr( " (any even? '(1 2 3)) " ).should == "#t"
1376
+ @nendo.evalStr( " (any even? '(1 3)) " ).should == "#f"
1377
+ @nendo.evalStr( " (any odd? '(1 3)) " ).should == "#t"
1378
+ @nendo.evalStr( " (any (lambda (x) x) '(1 2 3)) " ).should == "1"
1279
1379
  @nendo.evalStr( " " +
1280
1380
  "(let1 result '()" +
1281
1381
  " (do" +
@@ -1692,30 +1792,18 @@ describe Nendo, "when use hash-table feature " do
1692
1792
  @nendo.evalStr( " (hash-table-num-entries h)" ).should == "1"
1693
1793
  @nendo.evalStr( " (hash-table-clear! h)" ).should == "{}"
1694
1794
  @nendo.evalStr( " (hash-table-num-entries h)" ).should == "0"
1695
- @nendo.evalStr( " (set! h (hash-table '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-keys h)" ).should == "(\"a\" \"b\" \"c\")"
1696
- @nendo.evalStr( " (set! h (hash-table '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-values h)" ).should == "((\"AAA\") (\"BBB\") (\"CCC\" 100))"
1697
- @nendo.evalStr( " (set! h (hash-table '(\"a\" . \"AAA\") '(\"b\" . \"BBB\") '(\"c\" . \"CCC\"))) h" ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
1795
+ @nendo.evalStr( " (set! h (hash-table eq? '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-keys h)" ).should == "(\"a\" \"b\" \"c\")"
1796
+ @nendo.evalStr( " (set! h (hash-table eq? '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-values h)" ).should == "((\"AAA\") (\"BBB\") (\"CCC\" 100))"
1797
+ @nendo.evalStr( " (set! h (hash-table eq? '(\"a\" . \"AAA\") '(\"b\" . \"BBB\") '(\"c\" . \"CCC\"))) h" ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
1698
1798
  @nendo.evalStr( " (hash-table-keys h)" ).should == '("a" "b" "c")'
1699
1799
  @nendo.evalStr( " (hash-table-values h)" ).should == '("AAA" "BBB" "CCC")'
1700
1800
  @nendo.evalStr( " (hash-table-map h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1701
1801
  @nendo.evalStr( " (hash-table-for-each h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1702
- @nendo.evalStr( " (set! h (hash-table '(a AAA) '(b BBB))) (hash-table->alist h)" ).should == "((a AAA) (b BBB))"
1703
- @nendo.evalStr( " (set! h (hash-table '(a . AAA) '(b BBB))) (hash-table->alist h)" ).should == "((a . AAA) (b BBB))"
1704
- @nendo.evalStr( " (set! h (hash-table '(a AAA) '(b . BBB))) (hash-table->alist h)" ).should == "((a AAA) (b . BBB))"
1705
- @nendo.evalStr( " (set! h (hash-table '(a . AAA) '(b . BBB))) (hash-table->alist h)" ).should == "((a . AAA) (b . BBB))"
1706
- @nendo.evalStr( " (define alist (hash-table->alist h)) alist" ).should == "((a . AAA) (b . BBB))"
1707
- @nendo.evalStr( " (define h2 (alist->hash-table alist)) h2" ).should == "{:a=>:AAA, :b=>:BBB}"
1708
1802
  @nendo.evalStr( " (set! h (make-hash-table)) " ).should == "{}"
1709
- @nendo.evalStr( " (hash-table-push! h 'a :AAA_1) (hash-table->alist h)" ).should == "((a :AAA_1))"
1710
- @nendo.evalStr( " (hash-table-push! h 'a :AAA_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1))"
1711
- @nendo.evalStr( " (hash-table-push! h 'b :BBB_1) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_1))"
1712
- @nendo.evalStr( " (hash-table-push! h 'b :BBB_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_2 :BBB_1))"
1713
- @nendo.evalStr( " (set! h (hash-table '(true . 1) '(false . 2) '(nil . 3))) h" ).should == "{true=>1, false=>2, nil=>3}"
1714
- @nendo.evalStr( " (hash-table->alist h) " ).should == "((#t . 1) (#f . 2) (nil . 3))"
1715
- @nendo.evalStr( " (hash-table-keys h) " ).should == "(#t #f nil)"
1716
- @nendo.evalStr( " (set! h (hash-table '(1 . true) '(2 . false) '(3 . nil))) h" ).should == "{1=>true, 2=>false, 3=>nil}"
1717
- @nendo.evalStr( " (hash-table->alist h) " ).should == "((1 . #t) (2 . #f) (3 . nil))"
1718
- @nendo.evalStr( " (hash-table-keys h) " ).should == "(1 2 3)"
1803
+ @nendo.evalStr( " (set! h (hash-table eq? '(true . 1) '(false . 2) '(nil . 3))) h" ).should == "{true=>1, false=>2, nil=>3}"
1804
+ @nendo.evalStr( " (hash-table-keys h) " ).should == "(#t #f nil)"
1805
+ @nendo.evalStr( " (set! h (hash-table eq? '(1 . true) '(2 . false) '(3 . nil))) h" ).should == "{1=>true, 2=>false, 3=>nil}"
1806
+ @nendo.evalStr( " (hash-table-keys h) " ).should == "(1 2 3)"
1719
1807
  end
1720
1808
  end
1721
1809
 
@@ -1774,6 +1862,13 @@ describe Nendo, "tail call optimization " do
1774
1862
  @nendo.evalStr( " (setup-tailcall-mark '(begin (print \"abc\") 1 2 3)) " ).should == "(begin (print \"abc\") 1 2 3)"
1775
1863
  @nendo.evalStr( " (setup-tailcall-mark '(begin 1 2 (print \"abc\") 3)) " ).should == "(begin 1 2 (print \"abc\") 3)"
1776
1864
  @nendo.evalStr( " (setup-tailcall-mark '(begin 1 2 3 (print \"abc\"))) " ).should == "(begin 1 2 3 (%tailcall (print \"abc\")))"
1865
+ @nendo.evalStr( " (setup-tailcall-mark '(lambda (x) x)) " ).should == "(lambda (x) x)"
1866
+ @nendo.evalStr( " (setup-tailcall-mark '(macro (x) x)) " ).should == "(macro (x) x)"
1867
+ @nendo.evalStr( " (setup-tailcall-mark '(%syntax (x) x)) " ).should == "(%syntax (x) x)"
1868
+ @nendo.evalStr( " (setup-tailcall-mark '(%syntax (a b c) (begin a b c))) " ).should == "(%syntax (a b c) (begin a b c))"
1869
+ @nendo.evalStr( " (setup-tailcall-mark '(lambda (x) (%syntax (y) x))) " ).should == "(lambda (x) (%syntax (y) x))"
1870
+ @nendo.evalStr( " (setup-tailcall-mark '(lambda (x) (syntax-quote x))) " ).should == "(lambda (x) (syntax-quote x))"
1871
+ @nendo.evalStr( " (setup-tailcall-mark '(lambda (x) (quote x))) " ).should == "(lambda (x) 'x)"
1777
1872
  @nendo.evalStr( "" +
1778
1873
  "(setup-tailcall-mark"+
1779
1874
  " '(lambda '(x)"+
@@ -1836,7 +1931,7 @@ describe Nendo, "tail call optimization " do
1836
1931
  end
1837
1932
 
1838
1933
 
1839
- describe Nendo, "optional argument parser " do
1934
+ describe Nendo, "When use optional argument parser " do
1840
1935
  before do
1841
1936
  @nendo = Nendo::Core.new()
1842
1937
  @nendo.loadInitFile
@@ -1851,65 +1946,25 @@ describe Nendo, "optional argument parser " do
1851
1946
  end
1852
1947
  end
1853
1948
 
1854
-
1855
- describe Nendo, "(load path) and *load-path*" do
1856
- before do
1857
- @nendo = Nendo::Core.new()
1858
- @nendo.loadInitFile
1859
- end
1860
- it "should" do
1861
- @nendo.evalStr( ' (when (load "nendo/test") #t) ' ).should == "#t"
1862
- @nendo.evalStr( ' (when (load "nendo/test.nnd") #t) ' ).should == "#t"
1863
- @nendo.evalStr( ' (when (load "nendo/test.nnd") #t) ' ).should == "#t"
1864
- @nendo.evalStr( ' (when (load "./lib/nendo/test.nnd") #t) ' ).should == "#t"
1865
- @nendo.evalStr( ' (when (load "../nendo/lib/nendo/test.nnd") #t) ' ).should == "#t"
1866
- @nendo.evalStr( ' (when (use nendo.test) #t) ' ).should == "#t"
1867
- @nendo.evalStr( ' (set! *load-path* (list "a" "b")) ' ).should == '("a" "b")'
1868
- @nendo.evalStr( ' (add-load-path "./lib") ' ).should == '("./lib" "a" "b")'
1869
- @nendo.evalStr( ' (add-load-path "./bin" #t) ' ).should == '("./lib" "a" "b" "./bin")'
1870
- @nendo.evalStr( ' (when (load "nendo/test") #t) ' ).should == "#t"
1871
- lambda{ @nendo.evalStr( " (when (load \"nendo/not-exist-file\") #t) " ) }.should raise_error(RuntimeError)
1872
- end
1873
- end
1874
-
1875
-
1876
- describe Nendo, "nendo.test library " do
1949
+ describe Nendo, "When use :optional argument feature " do
1877
1950
  before do
1878
1951
  @nendo = Nendo::Core.new()
1879
1952
  @nendo.loadInitFile
1880
1953
  end
1881
1954
  it "should" do
1882
- @nendo.evalStr( ' (when (load "nendo/test") #t) ' ).should == "#t"
1883
- @nendo.evalStr( " (when (File.exist? *test-record-file*) (File.unlink *test-record-file*)) #t" ).should == "#t"
1884
- @nendo.evalStr( " (test-output-file (.open \"/dev/null\" \"w\")) #t" ).should == "#t"
1885
- @nendo.evalStr( " (test-start \"EMPTY\") " ).should == '"EMPTY"'
1886
- @nendo.evalStr( " (test-section \"EMPTY-SECTION\") " ).should == '"EMPTY-SECTION"'
1887
- @nendo.evalStr( " (test-end) " ).should == '0'
1888
- @nendo.evalStr( " *test-counts* " ).should == '#(0 0 0 0)'
1889
-
1890
- @nendo.evalStr( " (test-start \"SUCCESS\") " ).should == '"SUCCESS"'
1891
- @nendo.evalStr( " (test-section \"SUCCESS-SECTION\") " ).should == '"SUCCESS-SECTION"'
1892
- @nendo.evalStr( " (test \"test 1\" 1 (lambda () 1)) *test-counts*" ).should == '#(1 1 0 0)'
1893
- @nendo.evalStr( " (test* \"test 2\" 1 1 eq?) *test-counts*" ).should == '#(2 2 0 0)'
1894
- @nendo.evalStr( " (test* \"test 3\" (+ 2 2) (* 2 2) eqv?) *test-counts*" ).should == '#(3 3 0 0)'
1895
- @nendo.evalStr( " (test* \"test 4\" \"abc\" (+ \"a\" \"b\" \"c\")) *test-counts*" ).should == '#(4 4 0 0)'
1896
- @nendo.evalStr( " (test* \"test 5\" '(1 . 2) (cons 1 2)) *test-counts*" ).should == '#(5 5 0 0)'
1897
- @nendo.evalStr( " (test-end) " ).should == '0'
1898
- @nendo.evalStr( " *test-counts* " ).should == '#(5 5 0 0)'
1899
-
1900
- @nendo.evalStr( " (test-start \"FAIL\") " ).should == '"FAIL"'
1901
- @nendo.evalStr( " (test-section \"FAIL-SECTION\") " ).should == '"FAIL-SECTION"'
1902
- @nendo.evalStr( " (test \"test 6\" 1 (lambda () 2)) *test-counts*" ).should == '#(6 5 1 0)'
1903
- @nendo.evalStr( " (test* \"test 7\" 1 2 eqv?) *test-counts*" ).should == '#(7 5 2 0)'
1904
- @nendo.evalStr( " (test* \"test 8\" '(1) '(1) eq?) *test-counts*" ).should == '#(8 5 3 0)'
1905
- @nendo.evalStr( " (test* \"test 9\" \"ABC\" (+ \"a\" \"b\" \"c\")) *test-counts*" ).should == '#(9 5 4 0)'
1906
- @nendo.evalStr( " (test* \"test 10\" '(1 . 2) (cons 10 20)) *test-counts*" ).should == '#(10 5 5 0)'
1907
- @nendo.evalStr( " (test-end) " ).should == '5'
1908
- @nendo.evalStr( " *test-counts* " ).should == '#(10 5 5 0)'
1909
-
1910
- @nendo.evalStr( " (define data #f) data" ).should == "#f"
1911
- @nendo.evalStr( " (with-open *test-record-file* (lambda (in) (set! data (in.readline.chomp)))) data " ).should ==
1912
- '"Total: 10 tests, 5 passed, 5 failed, 0 aborted."'
1955
+ @nendo.evalStr( '(define (func arg1 arg2) (list arg1 arg2)) (func 1 2)' ).should == "(1 2)"
1956
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 #f)"
1957
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 #t)"
1958
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 3)"
1959
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3)) (func 1 2 30)' ).should == "(1 2 30)"
1960
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3)) (func 1 2 40)' ).should == "(1 2 40)"
1961
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2 50)' ).should == "(1 2 50)"
1962
+ @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2 "String")' ).should == '(1 2 "String")'
1963
+
1964
+ @nendo.evalStr( '(define func (lambda (arg1 arg2) (list arg1 arg2))) (func 1 2)' ).should == '(1 2)'
1965
+ lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
1966
+ lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
1967
+ lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
1913
1968
  end
1914
1969
  end
1915
1970
 
data/test/srfi-1-test.nnd CHANGED
@@ -22,9 +22,6 @@
22
22
  (for-each display xs)
23
23
  (newline))
24
24
 
25
- (define (fixme token)
26
- (printf "FIXME!: %s test was pending.\n" token))
27
-
28
25
  (define (fail token . more)
29
26
  (error (sprintf "Error: test failed: %s" token))
30
27
  #f)
@@ -533,6 +530,13 @@
533
530
  (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
534
531
  (fail 'delete!:1))
535
532
 
533
+ (or (let* ((x (list 1 48 2 5 37))
534
+ (cells (pair-fold cons '() x))
535
+ (r (delete! 5 x >)))
536
+ (and (equal? r '(48 5 37))
537
+ (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
538
+ (fail 'delete!:2))
539
+
536
540
  (or (equal? '((a . 3) (b . 7) (c . 1))
537
541
  (delete-duplicates '((a . 3) (b . 7) (a . 9) (c . 1))
538
542
  (lambda (x y) (eq? (car x) (car y)))))
@@ -545,7 +549,7 @@
545
549
  (r (delete-duplicates! x)))
546
550
  (and (equal? '(a b c z) r)
547
551
  (every (lambda (x) (memq x cells)) (pair-fold cons '() r))))
548
- (fixme 'delete-duplicates!:1))
552
+ (fail 'delete-duplicates!:1))
549
553
 
550
554
  (or (equal? '(3 . #t) (assoc 6
551
555
  '((4 . #t) (3 . #t) (5 . #t))
@@ -0,0 +1,63 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;
3
+ ;; srfi-2-test.nnd - test suite for srfi-2
4
+ ;;
5
+ ;; Copyright (c) 2000-2010 Shiro Kawai <shiro@acm.org>
6
+ ;;
7
+ ;; Redistribution and use in source and binary forms, with or without
8
+ ;; modification, are permitted provided that the following conditions
9
+ ;; are met:
10
+ ;;
11
+ ;; 1. Redistributions of source code must retain the above copyright
12
+ ;; notice, this list of conditions and the following disclaimer.
13
+ ;;
14
+ ;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;; notice, this list of conditions and the following disclaimer in the
16
+ ;; documentation and/or other materials provided with the distribution.
17
+ ;;
18
+ ;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;; may be used to endorse or promote products derived from this
20
+ ;; software without specific prior written permission.
21
+ ;;
22
+ ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+
34
+
35
+ (use nendo.test)
36
+ (test-start "srfi-2 (and-let*)")
37
+
38
+ ;;===================================================================
39
+ ;;-------------------------------------------------------------------
40
+ (test-section "srfi-2")
41
+ (use srfi-2)
42
+ (test-module 'srfi-2)
43
+
44
+ (define (srfi-2-look-up key alist)
45
+ (and-let* ((x (assq key alist))) (cdr x)))
46
+ (test* "and-let*" 3
47
+ (srfi-2-look-up 'c '((a . 1) (b . 2) (c . 3))))
48
+ (test* "and-let*" #f
49
+ (srfi-2-look-up 'd '((a . 1) (b . 2) (c . 3))))
50
+ (test* "and-let*" 3
51
+ (let ((x 3))
52
+ (and-let* (((positive? x))
53
+ (y x))
54
+ y)))
55
+ (test* "and-let*" #f
56
+ (let ((x -3))
57
+ (and-let* (((positive? x))
58
+ (y x))
59
+ y)))
60
+
61
+
62
+ ;;===================================================================
63
+ (test-end)
@@ -0,0 +1,89 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;
3
+ ;; srfi-26-test.nnd - Test suite for srfi-26
4
+ ;;
5
+ ;; Copyright (c) 2000-2010 Shiro Kawai <shiro@acm.org>
6
+ ;;
7
+ ;; Redistribution and use in source and binary forms, with or without
8
+ ;; modification, are permitted provided that the following conditions
9
+ ;; are met:
10
+ ;;
11
+ ;; 1. Redistributions of source code must retain the above copyright
12
+ ;; notice, this list of conditions and the following disclaimer.
13
+ ;;
14
+ ;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;; notice, this list of conditions and the following disclaimer in the
16
+ ;; documentation and/or other materials provided with the distribution.
17
+ ;;
18
+ ;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;; may be used to endorse or promote products derived from this
20
+ ;; software without specific prior written permission.
21
+ ;;
22
+ ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+
34
+
35
+ (use nendo.test)
36
+ (test-start "srfi-26 (cut cute)")
37
+
38
+ ;;===================================================================
39
+ ;;-------------------------------------------------------------------
40
+ (test-section "srfi-26")
41
+ (use srfi-26)
42
+ (test-module 'srfi-26)
43
+
44
+ ;; The test cases are taken from the SRFI-26 test program by Sebastian Egner.
45
+ (test* "cut list" '() ((cut list)))
46
+ (test* "cut list <...>" '() ((cut list <...>)))
47
+ (test* "cut list 1" '(1) ((cut list 1)))
48
+ (test* "cut list <>" '(1) ((cut list <>) 1))
49
+ (test* "cut list <...>" '(1) ((cut list <...>) 1))
50
+ (test* "cut list 1 2" '(1 2) ((cut list 1 2)))
51
+ (test* "cut list 1 <>" '(1 2) ((cut list 1 <>) 2))
52
+ (test* "cut list 1 <...>" '(1 2) ((cut list 1 <...>) 2))
53
+ (test* "cut list 1 <...>" '(1 2 3 4) ((cut list 1 <...>) 2 3 4))
54
+ (test* "cut list 1 <> 3 <>" '(1 2 3 4) ((cut list 1 <> 3 <>) 2 4))
55
+ (test* "cut list 1 <> 3 <...>" '(1 2 3 4 5 6) ((cut list 1 <> 3 <...>) 2 4 5 6))
56
+ ;;
57
+ ;; FIXME!: these test was pending. (by Kiyoka Nishiyama)
58
+ ;; because it doesn't pass `cut' syntax from chibi-scheme-0.3
59
+ ;;
60
+ ;;(test* "cut (eval order)" '(ok)
61
+ ;; (let* ((x 'wrong) (y (cut list x))) (set! x 'ok) (y)))
62
+ ;;(test* "cut (eval order)" 2
63
+ ;; (let ((a 0))
64
+ ;; (map (cut + (begin (set! a (+ a 1)) a) <>)
65
+ ;; '(1 2))
66
+ ;; a))
67
+
68
+ (test* "cute list" '() ((cute list)))
69
+ (test* "cute list <...>" '() ((cute list <...>)))
70
+ (test* "cute list 1" '(1) ((cute list 1)))
71
+ (test* "cute list <>" '(1) ((cute list <>) 1))
72
+ (test* "cute list <...>" '(1) ((cute list <...>) 1))
73
+ (test* "cute list 1 2" '(1 2) ((cute list 1 2)))
74
+ (test* "cute list 1 <>" '(1 2) ((cute list 1 <>) 2))
75
+ (test* "cute list 1 <...>" '(1 2) ((cute list 1 <...>) 2))
76
+ (test* "cute list 1 <...>" '(1 2 3 4) ((cute list 1 <...>) 2 3 4))
77
+ (test* "cute list 1 <> 3 <>" '(1 2 3 4) ((cute list 1 <> 3 <>) 2 4))
78
+ (test* "cute list 1 <> 3 <...>" '(1 2 3 4 5 6) ((cute list 1 <> 3 <...>) 2 4 5 6))
79
+ (test* "cute (eval order)" '(ok)
80
+ (let* ((x 'ok) (y (cute list x))) (set! x 'wrong) (y)))
81
+ (test* "cute (eval order)" 1
82
+ (let ((a 0))
83
+ (map (cute + (begin (set! a (+ a 1)) a) <>)
84
+ '(1 2))
85
+ a))
86
+
87
+
88
+ ;;===================================================================
89
+ (test-end)