diff options
author | icebaker <icebaker@proton.me> | 2023-05-13 18:51:02 -0300 |
---|---|---|
committer | icebaker <icebaker@proton.me> | 2023-05-13 18:51:02 -0300 |
commit | 1fbdb24fff7cd84b5506cb0c7092fdcdc867ec12 (patch) | |
tree | d5d815cae646002f4833439d07c36bf9c1f68ed7 /spec/logic/cartridge | |
parent | 62939e4baafde86d0ef599f1c7dc07cce95b8a73 (diff) |
adding missing files
Diffstat (limited to 'spec/logic/cartridge')
-rw-r--r-- | spec/logic/cartridge/affixes_spec.rb | 91 | ||||
-rw-r--r-- | spec/logic/cartridge/interaction_spec.rb | 47 | ||||
-rw-r--r-- | spec/logic/cartridge/streaming_spec.rb | 75 |
3 files changed, 213 insertions, 0 deletions
diff --git a/spec/logic/cartridge/affixes_spec.rb b/spec/logic/cartridge/affixes_spec.rb new file mode 100644 index 0000000..8f08e1d --- /dev/null +++ b/spec/logic/cartridge/affixes_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'yaml' + +require_relative '../../../logic/cartridge/affixes' + +RSpec.describe NanoBot::Logic::Cartridge::Affixes do + context 'interfaces' do + let(:cartridge) { load_cartridge('affixes.yml') } + + it 'gets the expected affixes' do + expect(described_class.get(cartridge, :repl, :input, :prefix)).to eq('E') + expect(described_class.get(cartridge, :repl, :input, :suffix)).to eq('F') + expect(described_class.get(cartridge, :repl, :output, :prefix)).to eq('G') + expect(described_class.get(cartridge, :repl, :output, :suffix)).to eq('H') + + expect(described_class.get(cartridge, :eval, :input, :prefix)).to eq('I') + expect(described_class.get(cartridge, :eval, :input, :suffix)).to eq('J') + expect(described_class.get(cartridge, :eval, :output, :prefix)).to eq('K') + expect(described_class.get(cartridge, :eval, :output, :suffix)).to eq('L') + end + end + + context 'interfaces fallback' do + let(:cartridge) { load_cartridge('affixes.yml') } + + it 'gets the expected affixes' do + cartridge[:interfaces][:repl][:input].delete(:prefix) + cartridge[:interfaces][:repl][:input].delete(:suffix) + cartridge[:interfaces][:eval][:input].delete(:prefix) + cartridge[:interfaces][:eval][:input].delete(:suffix) + + cartridge[:interfaces][:repl][:output].delete(:prefix) + cartridge[:interfaces][:repl][:output].delete(:suffix) + cartridge[:interfaces][:eval][:output].delete(:prefix) + cartridge[:interfaces][:eval][:output].delete(:suffix) + + expect(described_class.get(cartridge, :repl, :input, :prefix)).to eq('A') + expect(described_class.get(cartridge, :repl, :input, :suffix)).to eq('B') + expect(described_class.get(cartridge, :repl, :output, :prefix)).to eq('C') + expect(described_class.get(cartridge, :repl, :output, :suffix)).to eq('D') + + expect(described_class.get(cartridge, :eval, :input, :prefix)).to eq('A') + expect(described_class.get(cartridge, :eval, :input, :suffix)).to eq('B') + expect(described_class.get(cartridge, :eval, :output, :prefix)).to eq('C') + expect(described_class.get(cartridge, :eval, :output, :suffix)).to eq('D') + end + end + + context 'interfaces nil' do + let(:cartridge) { load_cartridge('affixes.yml') } + + it 'gets the expected affixes' do + cartridge[:interfaces][:repl][:input][:prefix] = nil + cartridge[:interfaces][:repl][:input][:suffix] = nil + cartridge[:interfaces][:eval][:input][:prefix] = nil + cartridge[:interfaces][:eval][:input][:suffix] = nil + + cartridge[:interfaces][:repl][:output][:prefix] = nil + cartridge[:interfaces][:repl][:output][:suffix] = nil + cartridge[:interfaces][:eval][:output][:prefix] = nil + cartridge[:interfaces][:eval][:output][:suffix] = nil + + expect(described_class.get(cartridge, :repl, :input, :prefix)).to be_nil + expect(described_class.get(cartridge, :repl, :input, :suffix)).to be_nil + expect(described_class.get(cartridge, :repl, :output, :prefix)).to be_nil + expect(described_class.get(cartridge, :repl, :output, :suffix)).to be_nil + + expect(described_class.get(cartridge, :eval, :input, :prefix)).to be_nil + expect(described_class.get(cartridge, :eval, :input, :suffix)).to be_nil + expect(described_class.get(cartridge, :eval, :output, :prefix)).to be_nil + expect(described_class.get(cartridge, :eval, :output, :suffix)).to be_nil + end + end + + context 'default' do + let(:cartridge) { {} } + + it 'gets the expected affixes' do + expect(described_class.get(cartridge, :repl, :input, :prefix)).to be_nil + expect(described_class.get(cartridge, :repl, :input, :suffix)).to be_nil + expect(described_class.get(cartridge, :repl, :output, :prefix)).to eq("\n") + expect(described_class.get(cartridge, :repl, :output, :suffix)).to eq("\n") + + expect(described_class.get(cartridge, :eval, :input, :prefix)).to be_nil + expect(described_class.get(cartridge, :eval, :input, :suffix)).to be_nil + expect(described_class.get(cartridge, :eval, :output, :prefix)).to be_nil + expect(described_class.get(cartridge, :eval, :output, :suffix)).to eq("\n") + end + end +end diff --git a/spec/logic/cartridge/interaction_spec.rb b/spec/logic/cartridge/interaction_spec.rb new file mode 100644 index 0000000..347ac45 --- /dev/null +++ b/spec/logic/cartridge/interaction_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'yaml' + +require_relative '../../../logic/cartridge/interaction' + +RSpec.describe NanoBot::Logic::Cartridge::Interaction do + context 'input' do + let(:cartridge) { load_cartridge('affixes.yml') } + + it 'prepares the input' do + expect(described_class.input(cartridge, :repl, 'hello')).to eq( + { content: 'hello', fennel: nil, lua: nil, prefix: 'E', suffix: 'F' } + ) + + expect(described_class.input({}, :repl, 'hello')).to eq( + { content: 'hello', fennel: nil, lua: nil, prefix: nil, suffix: nil } + ) + + expect(described_class.input(cartridge, :eval, 'hello')).to eq( + { content: 'hello', fennel: nil, lua: nil, prefix: 'I', suffix: 'J' } + ) + + expect(described_class.input({}, :eval, 'hello')).to eq( + { content: 'hello', fennel: nil, lua: nil, prefix: nil, suffix: nil } + ) + end + + it 'prepares the non-streamming output' do + expect(described_class.output(cartridge, :repl, { message: 'hello' }, false, true)).to eq( + { message: { content: 'hello', fennel: nil, lua: nil } } + ) + + expect(described_class.output({}, :repl, { message: 'hello' }, false, true)).to eq( + { message: { content: 'hello', fennel: nil, lua: nil } } + ) + + expect(described_class.output(cartridge, :eval, { message: 'hello' }, false, true)).to eq( + { message: { content: 'hello', fennel: nil, lua: nil } } + ) + + expect(described_class.output({}, :eval, { message: 'hello' }, false, true)).to eq( + { message: { content: 'hello', fennel: nil, lua: nil } } + ) + end + end +end diff --git a/spec/logic/cartridge/streaming_spec.rb b/spec/logic/cartridge/streaming_spec.rb new file mode 100644 index 0000000..e5ad012 --- /dev/null +++ b/spec/logic/cartridge/streaming_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'yaml' + +require_relative '../../../logic/cartridge/streaming' + +RSpec.describe NanoBot::Logic::Cartridge::Streaming do + context 'provider' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:provider][:settings][:stream] = false + expect(described_class.enabled?(cartridge, :repl)).to be(false) + end + end + + context 'repl' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:interfaces][:repl][:output][:stream] = false + expect(described_class.enabled?(cartridge, :repl)).to be(false) + end + end + + context 'interface + repl' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:interfaces][:output][:stream] = false + cartridge[:interfaces][:repl][:output][:stream] = true + expect(described_class.enabled?(cartridge, :repl)).to be(true) + end + end + + context 'interface' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:interfaces][:output][:stream] = false + cartridge[:interfaces][:repl][:output].delete(:stream) + expect(described_class.enabled?(cartridge, :repl)).to be(false) + end + end + + context '- repl' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:interfaces][:repl][:output].delete(:stream) + expect(described_class.enabled?(cartridge, :repl)).to be(true) + end + end + + context '- interface' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:interfaces][:output].delete(:stream) + cartridge[:interfaces][:repl][:output].delete(:stream) + expect(described_class.enabled?(cartridge, :repl)).to be(true) + end + end + + context '- provider' do + let(:cartridge) { load_cartridge('streaming.yml') } + + it 'checks if stream is enabled' do + cartridge[:provider][:settings].delete(:stream) + cartridge[:interfaces][:output].delete(:stream) + cartridge[:interfaces][:repl][:output].delete(:stream) + expect(described_class.enabled?(cartridge, :repl)).to be(true) + end + end +end |