mirror of
https://github.com/safiire/n65.git
synced 2025-04-06 10:37:36 +00:00
Setup RSpec rake task and wrote spec for MemorySpace (#2)
* Setup RSpec rake task and wrote spec for MemorySpace * Removed mintest rake task
This commit is contained in:
parent
1d03529b29
commit
c952f33d50
11
Rakefile
11
Rakefile
@ -1,13 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.pattern = 'test/test*.rb'
|
||||
begin
|
||||
require 'rspec/core/rake_task'
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
task(default: :spec)
|
||||
rescue LoadError
|
||||
warn("Couldn't load RSpec gem")
|
||||
end
|
||||
|
||||
## Check the syntax of all ruby files
|
||||
# Check the syntax of all Ruby files
|
||||
task :syntax do
|
||||
sh 'find . -name *.rb -type f -exec ruby -c {} \; -exec echo {} \;'
|
||||
end
|
||||
|
@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
||||
spec.add_development_dependency 'minitest'
|
||||
spec.add_development_dependency 'rake'
|
||||
spec.add_development_dependency 'rubocop'
|
||||
spec.add_development_dependency 'rspec'
|
||||
end
|
||||
|
4
spec/.rubocop.yml
Normal file
4
spec/.rubocop.yml
Normal file
@ -0,0 +1,4 @@
|
||||
inherit_from: ../.rubocop.yml
|
||||
|
||||
Metrics/BlockLength:
|
||||
Enabled: false
|
107
spec/lib/n65/memory_space_spec.rb
Normal file
107
spec/lib/n65/memory_space_spec.rb
Normal file
@ -0,0 +1,107 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../../lib/n65/memory_space'
|
||||
|
||||
RSpec.describe(N65::MemorySpace) do
|
||||
describe '.new' do
|
||||
context 'when provided a size and type' do
|
||||
let(:bank) { described_class.new(size, type) }
|
||||
let(:size) { 0x100 }
|
||||
let(:type) { :prog }
|
||||
|
||||
it 'returns a zeroed bank' do
|
||||
expect(bank.emit_bytes.all?(&:zero?)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the requested sized bank' do
|
||||
expect(bank.emit_bytes.size).to be(size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create_prog_rom' do
|
||||
context 'when creating a new prog rom' do
|
||||
let(:bank) { described_class.create_prog_rom }
|
||||
|
||||
it 'returns a zeroed bank' do
|
||||
expect(bank.emit_bytes.all?(&:zero?)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the correct sized bank' do
|
||||
expect(bank.emit_bytes.size).to eq(0x4000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create_char_rom' do
|
||||
context 'when creating a new prog rom' do
|
||||
let(:bank) { described_class.create_char_rom }
|
||||
|
||||
it 'returns a zeroed bank' do
|
||||
expect(bank.emit_bytes.all?(&:zero?)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the correct sized bank' do
|
||||
expect(bank.emit_bytes.size).to eq(0x2000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#read' do
|
||||
let(:address) { 0xC100 }
|
||||
let(:mirroed_address) { 0x8100 }
|
||||
let(:bank) { described_class.create_prog_rom }
|
||||
let(:data) { 'hi there'.bytes }
|
||||
|
||||
before { bank.write(address, data) }
|
||||
|
||||
context 'when reading from the bank' do
|
||||
it 'can read back from the 0xC000 base address' do
|
||||
expect(bank.read(address, data.size)).to eq(data)
|
||||
end
|
||||
|
||||
it 'can read back from the 0x8000 mirrored address' do
|
||||
expect(bank.read(mirroed_address, data.size)).to eq(data)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attempting to read out of bounds' do
|
||||
it 'throws an error' do
|
||||
expect { bank.read(0x0, 0x10) }.to raise_error(described_class::AccessOutsideProgRom)
|
||||
end
|
||||
|
||||
it 'throws an error' do
|
||||
expect { bank.read(0xffff, 0x10) }.to raise_error(described_class::AccessOutsideProgRom)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#write' do
|
||||
let(:address) { 0xC100 }
|
||||
let(:mirroed_address) { 0x8100 }
|
||||
let(:bank) { described_class.create_prog_rom }
|
||||
let(:data) { 'hi there'.bytes }
|
||||
|
||||
before { bank.write(mirroed_address, data) }
|
||||
|
||||
context 'when reading from the bank' do
|
||||
it 'can read back from the 0xC000 base address' do
|
||||
expect(bank.read(address, data.size)).to eq(data)
|
||||
end
|
||||
|
||||
it 'can read back from the 0x8000 mirrored address' do
|
||||
expect(bank.read(mirroed_address, data.size)).to eq(data)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attempting to write out of bounds' do
|
||||
it 'throws an error' do
|
||||
expect { bank.write(0x0, data) }.to raise_error(described_class::AccessOutsideProgRom)
|
||||
end
|
||||
|
||||
it 'throws an error' do
|
||||
expect { bank.write(0xffff, data) }.to raise_error(described_class::AccessOutsideProgRom)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user