Skip to content

Commit

Permalink
Added test for ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
desdic committed Feb 25, 2024
1 parent 9f5a712 commit a42477b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/ruby/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'date'

# A person
class Person
attr_reader :born, :name

def initialize(born, name)
@born = born
@name = name
end
end

def wrapped_string(dist)
"[#{dist.to_i}]"
end

def to_string(dist)
dist.to_i.to_s
end

def print_intro
puts 'Age of:'
end

=begin
Calculate days between birth and now
=end
def days_since_birth(born, convf = method(:wrapped_string))
now = DateTime.now
born_date = now - Date.strptime(born, '%m-%d-%Y')

convf.call(born_date)
end

donald = Person.new('07-09-1934', 'Donald Duck')
donald.born
born = donald.born

print_intro
days = days_since_birth(born, method(:to_string))

puts "#{donald.name} is #{days} days old"
60 changes: 60 additions & 0 deletions tests/ruby_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe("ruby", function()
local core = require("agrolens.core")
local buffers = nil
local eq = assert.equals

it("load", function()
vim.cmd.edit("tests/ruby/test.rb")
buffers = vim.api.nvim_list_bufs()
eq(#buffers, 1)

local content = vim.api.nvim_buf_get_lines(buffers[1], 0, -1, false)

-- make sure buffer has content
eq(string.match(content[1], "frozen_string_literal"), "frozen_string_literal")

core.get_captures({ queries = { "functions" }, bufids = buffers })
end)

it("functions", function()
local entries = core.get_captures({ queries = { "functions" }, bufids = buffers })

eq(#entries, 6)
eq(entries[1].filename, "tests/ruby/test.rb")
eq(entries[1].lnum, 7)
eq(entries[1].col, 2)

eq(entries[1].line, " attr_reader :born, :name")
eq(entries[2].line, " def initialize(born, name)")
eq(entries[3].line, "def wrapped_string(dist)")
eq(entries[4].line, "def to_string(dist)")
eq(entries[5].line, "def print_intro")
eq(entries[6].line, "def days_since_birth(born, convf = method(:wrapped_string))")
end)

it("callings", function()
local entries = core.get_captures({ queries = { "callings" }, bufids = buffers })

eq(#entries, 14)
eq(entries[1].filename, "tests/ruby/test.rb")
eq(entries[1].lnum, 3)
eq(entries[1].col, 0)

eq(entries[1].line, "require 'date'")
eq(entries[2].line, " attr_reader :born, :name")
eq(entries[3].line, ' "[#{dist.to_i}]"')
end)

it("comments", function()
local entries = core.get_captures({ queries = { "comments" }, bufids = buffers })

eq(#entries, 3)
eq(entries[1].filename, "tests/ruby/test.rb")
eq(entries[1].lnum, 1)
eq(entries[1].col, 0)

eq(entries[1].line, "# frozen_string_literal: true")
eq(entries[2].line, "# A person")
eq(entries[3].line, "=begin")
end)
end)

0 comments on commit a42477b

Please sign in to comment.