From c7d4d226365d8015c40bcf99c59a6b9de53f5720 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 10 Nov 2021 16:44:57 +0100 Subject: [PATCH] test + --- spec/language_operations_spec.rb | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/language_operations_spec.rb diff --git a/spec/language_operations_spec.rb b/spec/language_operations_spec.rb new file mode 100644 index 0000000..5a19521 --- /dev/null +++ b/spec/language_operations_spec.rb @@ -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