mirror of
https://github.com/safiire/n65.git
synced 2024-12-12 00:29:03 +00:00
Linted test files
This commit is contained in:
parent
f364a83db9
commit
4123bf0b06
@ -1,14 +1,11 @@
|
|||||||
gem 'minitest'
|
gem 'minitest'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
|
require_relative '../lib/n65'
|
||||||
require_relative '../lib/n65.rb'
|
|
||||||
|
|
||||||
|
|
||||||
class TestArithmeticSymbols < MiniTest::Test
|
class TestArithmeticSymbols < MiniTest::Test
|
||||||
include N65
|
include N65
|
||||||
|
|
||||||
|
|
||||||
def test_identify_plain_symbol
|
def test_identify_plain_symbol
|
||||||
re = Regexp.new(Regexes::Sym)
|
re = Regexp.new(Regexes::Sym)
|
||||||
assert_match(re, 'dog')
|
assert_match(re, 'dog')
|
||||||
@ -16,14 +13,12 @@ class TestArithmeticSymbols < MiniTest::Test
|
|||||||
assert_match(re, 'global.animal.dog')
|
assert_match(re, 'global.animal.dog')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_symbol_values
|
def test_symbol_values
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('variable', 0xff)
|
st.define_symbol('variable', 0xff)
|
||||||
assert_equal(0xff, st.resolve_symbol('variable'))
|
assert_equal(0xff, st.resolve_symbol('variable'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_perform_symbolic_arithmetic
|
def test_perform_symbolic_arithmetic
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('variable', 0x20)
|
st.define_symbol('variable', 0x20)
|
||||||
@ -31,7 +26,6 @@ class TestArithmeticSymbols < MiniTest::Test
|
|||||||
assert_equal(0x40, st.resolve_symbol('variable*2'))
|
assert_equal(0x40, st.resolve_symbol('variable*2'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_symbol_addition
|
def test_symbol_addition
|
||||||
program = <<-ASM
|
program = <<-ASM
|
||||||
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
|
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
|
||||||
@ -72,7 +66,4 @@ class TestArithmeticSymbols < MiniTest::Test
|
|||||||
]
|
]
|
||||||
assert_equal(binary, correct)
|
assert_equal(binary, correct)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,82 +1,77 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
gem 'minitest'
|
gem 'minitest'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
|
|
||||||
require_relative '../lib/n65/memory_space.rb'
|
require_relative '../lib/n65/memory_space'
|
||||||
|
|
||||||
|
|
||||||
class TestMemorySpace < MiniTest::Test
|
class TestMemorySpace < MiniTest::Test
|
||||||
include N65
|
include N65
|
||||||
|
|
||||||
def test_create_prog_rom
|
def test_create_prog_rom
|
||||||
## First just try to read alll of it
|
# First just try to read alll of it
|
||||||
space = MemorySpace.create_prog_rom
|
space = MemorySpace.create_prog_rom
|
||||||
contents = space.read(0x8000, 0x4000)
|
contents = space.read(0x8000, 0x4000)
|
||||||
assert_equal(contents.size, 0x4000)
|
assert_equal(contents.size, 0x4000)
|
||||||
assert(contents.all?{|byte| byte.zero?})
|
assert(contents.all?(&:zero?))
|
||||||
|
|
||||||
## It is mirrored so this should also work
|
# It is mirrored so this should also work
|
||||||
space = MemorySpace.create_prog_rom
|
space = MemorySpace.create_prog_rom
|
||||||
contents = space.read(0xC000, 0x4000)
|
contents = space.read(0xC000, 0x4000)
|
||||||
assert_equal(contents.size, 0x4000)
|
assert_equal(contents.size, 0x4000)
|
||||||
assert(contents.all?{|byte| byte.zero?})
|
assert(contents.all?(&:zero?))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_writing
|
def test_writing
|
||||||
## Write some bytes into prog 2 area
|
# Write some bytes into prog 2 area
|
||||||
space = MemorySpace.create_prog_rom
|
space = MemorySpace.create_prog_rom
|
||||||
space.write(0xC000, "hi there".bytes)
|
space.write(0xC000, 'hi there'.bytes)
|
||||||
|
|
||||||
## Read them back..
|
# Read them back..
|
||||||
contents = space.read(0xC000, 8)
|
contents = space.read(0xC000, 8)
|
||||||
assert_equal('hi there', contents.pack('C*'))
|
assert_equal('hi there', contents.pack('C*'))
|
||||||
|
|
||||||
## Should be mirrored in prog 1
|
# Should be mirrored in prog 1
|
||||||
contents = space.read(0x8000, 8)
|
contents = space.read(0x8000, 8)
|
||||||
assert_equal('hi there', contents.pack('C*'))
|
assert_equal('hi there', contents.pack('C*'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_reading_out_of_bounds
|
def test_reading_out_of_bounds
|
||||||
space = MemorySpace.create_prog_rom
|
space = MemorySpace.create_prog_rom
|
||||||
assert_raises(MemorySpace::AccessOutsideProgRom) do
|
assert_raises(MemorySpace::AccessOutsideProgRom) do
|
||||||
space.read(0x200, 10)
|
space.read(0x200, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
## But that is valid char rom area, so no explody
|
# But that is valid char rom area, so no explody
|
||||||
space = MemorySpace.create_char_rom
|
space = MemorySpace.create_char_rom
|
||||||
space.read(0x200, 10)
|
space.read(0x200, 10)
|
||||||
|
|
||||||
## But something like this should explode
|
# But something like this should explode
|
||||||
space = MemorySpace.create_char_rom
|
space = MemorySpace.create_char_rom
|
||||||
assert_raises(MemorySpace::AccessOutsideCharRom) do
|
assert_raises(MemorySpace::AccessOutsideCharRom) do
|
||||||
space.read(0x8001, 10)
|
space.read(0x8001, 10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# There seem to be problems writing bytes right to
|
||||||
####
|
# the end of the memory map, specifically where the
|
||||||
## There seem to be problems writing bytes right to
|
# vector table is in prog rom, so let's test that.
|
||||||
## the end of the memory map, specifically where the
|
|
||||||
## vector table is in prog rom, so let's test that.
|
|
||||||
def test_writing_to_end
|
def test_writing_to_end
|
||||||
space = MemorySpace.create_prog_rom
|
space = MemorySpace.create_prog_rom
|
||||||
bytes = [0xDE, 0xAD]
|
bytes = [0xDE, 0xAD]
|
||||||
|
|
||||||
## Write the NMI address to FFFA
|
# Write the NMI address to FFFA
|
||||||
space.write(0xFFFA, bytes)
|
space.write(0xFFFA, bytes)
|
||||||
|
|
||||||
## Write the entry point to FFFC
|
# Write the entry point to FFFC
|
||||||
space.write(0xFFFC, bytes)
|
space.write(0xFFFC, bytes)
|
||||||
|
|
||||||
## Write the irq to FFFE, and this fails, saying
|
# Write the irq to FFFE, and this fails, saying
|
||||||
## I'm trying to write to $10000 for some reason.
|
# I'm trying to write to $10000 for some reason.
|
||||||
space.write(0xFFFE, bytes)
|
space.write(0xFFFE, bytes)
|
||||||
|
|
||||||
## Write to the very first
|
# Write to the very first
|
||||||
space.write(0x8000, bytes)
|
space.write(0x8000, bytes)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
gem 'minitest'
|
gem 'minitest'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'minitest/unit'
|
require 'minitest/unit'
|
||||||
|
|
||||||
require_relative '../lib/n65/symbol_table.rb'
|
require_relative '../lib/n65/symbol_table'
|
||||||
require_relative '../lib/n65.rb'
|
require_relative '../lib/n65'
|
||||||
|
|
||||||
|
|
||||||
class TestSymbolTable < MiniTest::Test
|
class TestSymbolTable < MiniTest::Test
|
||||||
include N65
|
include N65
|
||||||
|
|
||||||
####
|
# Test that we can make simple global symbols
|
||||||
## Test that we can make simple global symbols
|
|
||||||
def test_define_global_symbols
|
def test_define_global_symbols
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('dog', 'woof')
|
st.define_symbol('dog', 'woof')
|
||||||
assert_equal('woof', st.resolve_symbol('dog'))
|
assert_equal('woof', st.resolve_symbol('dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test entering into a sub scope, and setting and retrieving values
|
||||||
####
|
|
||||||
## Test entering into a sub scope, and setting and retrieving values
|
|
||||||
def test_enter_scope
|
def test_enter_scope
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.enter_scope('animals')
|
st.enter_scope('animals')
|
||||||
@ -27,9 +25,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal('woof', st.resolve_symbol('dog'))
|
assert_equal('woof', st.resolve_symbol('dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Access something from an outer scope without dot syntax
|
||||||
####
|
|
||||||
## Access something from an outer scope without dot syntax
|
|
||||||
def test_outer_scope
|
def test_outer_scope
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.enter_scope('outer')
|
st.enter_scope('outer')
|
||||||
@ -39,9 +35,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal('woof', st.resolve_symbol('dog'))
|
assert_equal('woof', st.resolve_symbol('dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Access something from an outer scope without dot syntax
|
||||||
####
|
|
||||||
## Access something from an outer scope without dot syntax
|
|
||||||
def test_shadow
|
def test_shadow
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.enter_scope('outer')
|
st.enter_scope('outer')
|
||||||
@ -55,9 +49,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal('bark', st.resolve_symbol('outer.inner.dog'))
|
assert_equal('bark', st.resolve_symbol('outer.inner.dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test exiting a sub scope, and seeing that the variable is unavailable by simple name
|
||||||
####
|
|
||||||
## Test exiting a sub scope, and seeing that the variable is unavailable by simple name
|
|
||||||
def test_exit_scope
|
def test_exit_scope
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.enter_scope('animals')
|
st.enter_scope('animals')
|
||||||
@ -71,9 +63,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test exiting a sub scope, and being able to access a symbol through a full path
|
||||||
####
|
|
||||||
## Test exiting a sub scope, and being able to access a symbol through a full path
|
|
||||||
def test_exit_scope_full_path
|
def test_exit_scope_full_path
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.enter_scope('animals')
|
st.enter_scope('animals')
|
||||||
@ -85,9 +75,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal('woof', st.resolve_symbol('animals.dog'))
|
assert_equal('woof', st.resolve_symbol('animals.dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Have two symbols that are the same but are in different scopes
|
||||||
####
|
|
||||||
## Have two symbols that are the same but are in different scopes
|
|
||||||
def test_two_scopes_same_symbol
|
def test_two_scopes_same_symbol
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('dog', 'woof')
|
st.define_symbol('dog', 'woof')
|
||||||
@ -104,10 +92,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal('woofwoof', st.resolve_symbol('animals.dog'))
|
assert_equal('woofwoof', st.resolve_symbol('animals.dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# How do you get stuff out of the global scope when you are in a sub scope?
|
||||||
####
|
|
||||||
## How do you get stuff out of the global scope when you are in
|
|
||||||
## a sub scope?
|
|
||||||
def test_access_global_scope
|
def test_access_global_scope
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('dog', 'woof')
|
st.define_symbol('dog', 'woof')
|
||||||
@ -117,13 +102,11 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
st.define_symbol('pig', 'oink')
|
st.define_symbol('pig', 'oink')
|
||||||
assert_equal('oink', st.resolve_symbol('pig'))
|
assert_equal('oink', st.resolve_symbol('pig'))
|
||||||
|
|
||||||
## Ok, now I want to access global.dog basically from the previous scope
|
# Ok, now I want to access global.dog basically from the previous scope
|
||||||
assert_equal('woof', st.resolve_symbol('global.dog'))
|
assert_equal('woof', st.resolve_symbol('global.dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Now I want to just test making an anonymous scope
|
||||||
####
|
|
||||||
## Now I want to just test making an anonymous scope
|
|
||||||
def test_anonymous_scope
|
def test_anonymous_scope
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
st.define_symbol('dog', 'woof')
|
st.define_symbol('dog', 'woof')
|
||||||
@ -133,19 +116,17 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
st.define_symbol('pig', 'oink')
|
st.define_symbol('pig', 'oink')
|
||||||
assert_equal('oink', st.resolve_symbol('pig'))
|
assert_equal('oink', st.resolve_symbol('pig'))
|
||||||
|
|
||||||
## Ok, now I want to access global.dog basically from the previous scope
|
# Ok, now I want to access global.dog basically from the previous scope
|
||||||
assert_equal('woof', st.resolve_symbol('global.dog'))
|
assert_equal('woof', st.resolve_symbol('global.dog'))
|
||||||
|
|
||||||
## Now exit the anonymous scope and get dog
|
# Now exit the anonymous scope and get dog
|
||||||
st.exit_scope
|
st.exit_scope
|
||||||
assert_equal('woof', st.resolve_symbol('global.dog'))
|
assert_equal('woof', st.resolve_symbol('global.dog'))
|
||||||
assert_equal('woof', st.resolve_symbol('dog'))
|
assert_equal('woof', st.resolve_symbol('dog'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Now I want to test that I cannot exist the outer-most
|
||||||
####
|
# global scope by mistake
|
||||||
## Now I want to test that I cannot exist the outer-most
|
|
||||||
## global scope by mistake
|
|
||||||
def test_cant_exit_global
|
def test_cant_exit_global
|
||||||
st = SymbolTable.new
|
st = SymbolTable.new
|
||||||
assert_raises(SymbolTable::CantExitScope) do
|
assert_raises(SymbolTable::CantExitScope) do
|
||||||
@ -153,10 +134,8 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# I would like the name of the scope to take on the
|
||||||
####
|
# value of the program counter at that location.
|
||||||
## I would like the name of the scope to take on the
|
|
||||||
## value of the program counter at that location.
|
|
||||||
def test_scope_as_symbol
|
def test_scope_as_symbol
|
||||||
program = <<-ASM
|
program = <<-ASM
|
||||||
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
|
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
|
||||||
@ -172,7 +151,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
jmp global.main
|
jmp global.main
|
||||||
ASM
|
ASM
|
||||||
|
|
||||||
#### There really should be an evaluate string method
|
# There really should be an evaluate string method
|
||||||
assembler = Assembler.new
|
assembler = Assembler.new
|
||||||
program.split(/\n/).each do |line|
|
program.split(/\n/).each do |line|
|
||||||
assembler.assemble_one_line(line)
|
assembler.assemble_one_line(line)
|
||||||
@ -181,9 +160,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
assert_equal(0x8000, assembler.symbol_table.resolve_symbol('global.main'))
|
assert_equal(0x8000, assembler.symbol_table.resolve_symbol('global.main'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fix a bug where we can't see a forward declared symbol in a scope
|
||||||
####
|
|
||||||
## Fix a bug where we can't see a forward declared symbol in a scope
|
|
||||||
def test_foward_declaration_in_scope
|
def test_foward_declaration_in_scope
|
||||||
program = <<-ASM
|
program = <<-ASM
|
||||||
;;;;
|
;;;;
|
||||||
@ -208,7 +185,7 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
.
|
.
|
||||||
ASM
|
ASM
|
||||||
|
|
||||||
#### There really should be an evaluate string method
|
# There really should be an evaluate string method
|
||||||
assembler = Assembler.new
|
assembler = Assembler.new
|
||||||
program.split(/\n/).each do |line|
|
program.split(/\n/).each do |line|
|
||||||
assembler.assemble_one_line(line)
|
assembler.assemble_one_line(line)
|
||||||
@ -216,8 +193,9 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
puts YAML.dump(assembler.symbol_table)
|
puts YAML.dump(assembler.symbol_table)
|
||||||
assembler.fulfill_promises
|
assembler.fulfill_promises
|
||||||
|
|
||||||
#### The forward symbol should have been resolved to +3, and the ROM should look like this:
|
# The forward symbol should have been resolved to +3, and the ROM should look like this:
|
||||||
correct_rom = [0x4e, 0x45, 0x53, 0x1a, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
correct_rom = [
|
||||||
|
0x4e, 0x45, 0x53, 0x1a, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x78, # SEI
|
0x78, # SEI
|
||||||
0xd8, # CLD
|
0xd8, # CLD
|
||||||
0xa9, 0x0, # LDA immediate 0
|
0xa9, 0x0, # LDA immediate 0
|
||||||
@ -228,11 +206,9 @@ class TestSymbolTable < MiniTest::Test
|
|||||||
0x60 # RTS forward_symbol
|
0x60 # RTS forward_symbol
|
||||||
]
|
]
|
||||||
|
|
||||||
#### Grab the first 26 bytes of the rom and make sure they assemble to the above
|
# Grab the first 26 bytes of the rom and make sure they assemble to the above
|
||||||
emitted_rom = assembler.emit_binary_rom.bytes[0...26]
|
emitted_rom = assembler.emit_binary_rom.bytes[0...26]
|
||||||
assert_equal(correct_rom, emitted_rom)
|
assert_equal(correct_rom, emitted_rom)
|
||||||
#### Yup it is fixed now.
|
# Yup it is fixed now.
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user