Compare commits
2 commits
0f924355ca
...
c7d4d22636
Author | SHA1 | Date | |
---|---|---|---|
|
c7d4d22636 | ||
|
41a9c8ec05 |
2 changed files with 60 additions and 6 deletions
9
repl.rb
9
repl.rb
|
@ -19,19 +19,18 @@ module Rpn
|
|||
|
||||
def run
|
||||
Readline.completion_proc = proc do |s|
|
||||
directory_list = Dir.glob("#{s}*")
|
||||
if directory_list.positive?
|
||||
directory_list
|
||||
else
|
||||
Readline::HISTORY.grep(/^#{Regexp.escape(s)}/)
|
||||
end
|
||||
end
|
||||
Readline.completion_append_character = ' '
|
||||
|
||||
loop do
|
||||
input = Readline.readline( ' ', true )
|
||||
break if input.nil? || input == 'quit'
|
||||
|
||||
pp Readline::HISTORY if input == 'history'
|
||||
|
||||
input = '"rpn.rb version 0.0"' if %w[version uname].include?( input )
|
||||
|
||||
# Remove blank lines from history
|
||||
Readline::HISTORY.pop if input.empty?
|
||||
|
||||
|
|
55
spec/language_operations_spec.rb
Normal file
55
spec/language_operations_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# coding: utf-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
require_relative '../lib/core'
|
||||
|
||||
class TestParser < Test::Unit::TestCase
|
||||
def test_plus
|
||||
stack = Rpn::Core::Operations.add [{ value: 1, type: :numeric },
|
||||
{ value: 2, type: :numeric }]
|
||||
assert_equal [{ value: 3, type: :numeric }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: 1, type: :numeric },
|
||||
{ value: '"a"', type: :string }]
|
||||
assert_equal [{ value: '"1a"', type: :string }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: 1, type: :numeric },
|
||||
{ value: "'a'", type: :name }]
|
||||
assert_equal [{ value: '"1a"', type: :string }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: "'a'", type: :name },
|
||||
{ value: 1, type: :numeric }]
|
||||
assert_equal [{ value: "'a1'", type: :name }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: "'a'", type: :name },
|
||||
{ value: '"b"', type: :string }]
|
||||
assert_equal [{ value: "'ab'", type: :name }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: "'a'", type: :name },
|
||||
{ value: "'b'", type: :name }]
|
||||
assert_equal [{ value: "'ab'", type: :name }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: '"a"', type: :string },
|
||||
{ value: '"b"', type: :string }]
|
||||
assert_equal [{ value: '"ab"', type: :string }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: '"a"', type: :string },
|
||||
{ value: "'b'", type: :name }]
|
||||
assert_equal [{ value: '"ab"', type: :string }],
|
||||
stack
|
||||
|
||||
stack = Rpn::Core::Operations.add [{ value: '"a"', type: :string },
|
||||
{ value: 1, type: :numeric }]
|
||||
assert_equal [{ value: '"a1"', type: :string }],
|
||||
stack
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue