Warning, file /education/kturtle/spec/learn_spec.rb was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 # SPDX-FileCopyrightText: 2009 Cies Breijs 0002 # SPDX-FileCopyrightText: 2009 Niels Slot 0003 # 0004 # SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 require File.dirname(__FILE__) + '/spec_helper.rb' 0007 $i = Interpreter.instance 0008 0009 describe "learn (user defined commands)" do 0010 it "should work for commands without arguments" do 0011 $i.should_run_clean <<-EOS 0012 learn user_def { 0013 assert true 0014 } 0015 user_def 0016 EOS 0017 end 0018 0019 it "should work for commands with 1 argument" do 0020 $i.should_run_clean <<-EOS 0021 learn user_def $x { 0022 assert $x == 1 0023 } 0024 user_def 1 0025 EOS 0026 end 0027 0028 it "should work for commands with 2 mixed arguments" do 0029 $i.should_run_clean <<-EOS 0030 learn user_def $x, $y { 0031 assert $x == "kturtle" 0032 assert $y == 10 0033 } 0034 user_def "kturtle", 10 0035 EOS 0036 end 0037 0038 it "should work for commands with 3 mixed arguments" do 0039 $i.should_run_clean <<-EOS 0040 learn user_def $x, $y, $z { 0041 assert $x 0042 assert $y == "kturtle" 0043 assert $z == 10 0044 } 0045 user_def true, "kturtle", 10 0046 EOS 0047 end 0048 0049 it "should work with return values" do 0050 $i.should_run_clean <<-EOS 0051 learn user_def { 0052 return true 0053 } 0054 assert user_def 0055 0056 learn user_def2 { 0057 return "kturtle" 0058 } 0059 assert "kturtle" == user_def2 0060 EOS 0061 end 0062 0063 it "should produce an error when the number of arguments does not match" do 0064 $i.run <<-EOS 0065 learn user_def $x, $y, $z { 0066 0067 } 0068 user_def 1 0069 EOS 0070 $i.errors?.should be_true 0071 end 0072 0073 it "should produce an error when the scope is omitted" do 0074 $i.run <<-EOS 0075 learn user_def $x 0076 0077 user_def 0078 EOS 0079 $i.errors?.should be_true 0080 end 0081 0082 it "should allow recursion over one function" 0083 it "should allow recursion over two functions" 0084 end