test list operations
This commit is contained in:
parent
6562a4297e
commit
36ba5fa297
6 changed files with 134 additions and 85 deletions
33
spec/words_list_spec.rb
Normal file
33
spec/words_list_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# coding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
require 'rpl'
|
||||
|
||||
class TestLanguageList < MiniTest::Test
|
||||
include Types
|
||||
|
||||
def test_2list
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '1 2 3 dup →list'
|
||||
assert_equal [Types.new_object( RplList, '{ 1 2 3 }' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_from_list
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '{ 1 2 3 } list→'
|
||||
assert_equal [Types.new_object( RplNumeric, 1 ),
|
||||
Types.new_object( RplNumeric, 2 ),
|
||||
Types.new_object( RplNumeric, 3 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_dolist
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '{ 1 2 3 } « 3 + » dolist'
|
||||
assert_equal [Types.new_object( RplList, '{ 4 5 6 }' )],
|
||||
interpreter.stack
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ require 'minitest/autorun'
|
|||
|
||||
require 'rpl'
|
||||
|
||||
class TesttLanguageOperations < MiniTest::Test
|
||||
class TesttLanguageOperationsComplexes < MiniTest::Test
|
||||
include Types
|
||||
|
||||
def test_re
|
||||
|
|
|
@ -5,9 +5,11 @@ require 'minitest/autorun'
|
|||
|
||||
require 'rpl'
|
||||
|
||||
class TesttLanguageOperations < MiniTest::Test
|
||||
class TesttLanguageOperationsRealsAndComplexes < MiniTest::Test
|
||||
include Types
|
||||
|
||||
# TODO: test complexes
|
||||
|
||||
def test_add
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '1 2 +'
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'minitest/autorun'
|
|||
|
||||
require 'rpl'
|
||||
|
||||
class TesttLanguageOperations < MiniTest::Test
|
||||
class TesttLanguageOperationsReals < MiniTest::Test
|
||||
include Types
|
||||
|
||||
def test_percent
|
||||
|
|
|
@ -5,97 +5,18 @@ require 'minitest/autorun'
|
|||
|
||||
require 'rpl'
|
||||
|
||||
class TestLanguageString < MiniTest::Test
|
||||
class TestLanguageStringAndList < MiniTest::Test
|
||||
include Types
|
||||
|
||||
def test_to_string
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '2 →str'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"2"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_from_string
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"2" str→'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 2 )],
|
||||
interpreter.stack
|
||||
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"« dup * » \'carré\' sto" str→'
|
||||
|
||||
assert_equal [Types.new_object( RplProgram, '« dup * »' ),
|
||||
Types.new_object( RplName, 'carré' ),
|
||||
Types.new_object( RplName, 'sto' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_chr
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '71 chr'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"G"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_num
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"G" num'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 71 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_size
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"test" size'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 4 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_pos
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"test of POS" "of" pos'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 5 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_sub
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my string to sub" 4 6 sub'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"str"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_rev
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my string to sub" rev'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"my string to sub"'.reverse )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_split
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my string to sub" " " split'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"my"' ),
|
||||
Types.new_object( RplString, '"string"' ),
|
||||
Types.new_object( RplString, '"to"' ),
|
||||
Types.new_object( RplString, '"sub"' )],
|
||||
interpreter.stack
|
||||
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my,string,to sub" "," split'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"my"' ),
|
||||
Types.new_object( RplString, '"string"' ),
|
||||
Types.new_object( RplString, '"to sub"' )],
|
||||
interpreter.run '{ 1 2 3 } rev'
|
||||
assert_equal [Types.new_object( RplList, '{ 3 2 1 }' )],
|
||||
interpreter.stack
|
||||
end
|
||||
end
|
||||
|
|
93
spec/words_string_spec.rb
Normal file
93
spec/words_string_spec.rb
Normal file
|
@ -0,0 +1,93 @@
|
|||
# coding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
require 'rpl'
|
||||
|
||||
class TestLanguageString < MiniTest::Test
|
||||
include Types
|
||||
|
||||
def test_to_string
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '2 →str'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"2"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_from_string
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"2" str→'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 2 )],
|
||||
interpreter.stack
|
||||
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"« dup * » \'carré\' sto" str→'
|
||||
|
||||
assert_equal [Types.new_object( RplProgram, '« dup * »' ),
|
||||
Types.new_object( RplName, 'carré' ),
|
||||
Types.new_object( RplName, 'sto' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_chr
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '71 chr'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"G"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_num
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"G" num'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 71 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_size
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"test" size'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 4 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_pos
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"test of POS" "of" pos'
|
||||
|
||||
assert_equal [Types.new_object( RplNumeric, 5 )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_sub
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my string to sub" 4 6 sub'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"str"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
|
||||
def test_split
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my string to sub" " " split'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"my"' ),
|
||||
Types.new_object( RplString, '"string"' ),
|
||||
Types.new_object( RplString, '"to"' ),
|
||||
Types.new_object( RplString, '"sub"' )],
|
||||
interpreter.stack
|
||||
|
||||
interpreter = Rpl.new
|
||||
interpreter.run '"my,string,to sub" "," split'
|
||||
|
||||
assert_equal [Types.new_object( RplString, '"my"' ),
|
||||
Types.new_object( RplString, '"string"' ),
|
||||
Types.new_object( RplString, '"to sub"' )],
|
||||
interpreter.stack
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue