Skip to content

Commit

Permalink
Added php test
Browse files Browse the repository at this point in the history
  • Loading branch information
desdic committed Feb 25, 2024
1 parent a42477b commit d1ca7ec
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/php/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

// A person
class Person {
private $age;
function __construct($age) {
$this->age = $age;
}
function getAge() {
return $this->age;
}
};

function newPerson($age) {
return new Person($age);
}

/*
Create a person
*/
$p = newPerson(42);

$num1 = $p->getAge();
$num2 = newPerson(43);

NewPerson(53);
$num2->getAge();

echo($num1);
print($num2->getAge());

?>
55 changes: 55 additions & 0 deletions tests/php_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
describe("php", function()
local core = require("agrolens.core")
local buffers = nil
local eq = assert.equals

it("load", function()
vim.cmd.edit("tests/php/test.php")
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], "php"), "php")

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

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

eq(#entries, 3)
eq(entries[1].filename, "tests/php/test.php")
eq(entries[1].lnum, 6)
eq(entries[1].col, 2)

eq(entries[1].line, " function __construct($age) {")
eq(entries[2].line, " function getAge() {")
eq(entries[3].line, "function newPerson($age) {")
end)

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

eq(#entries, 5)
eq(entries[1].filename, "tests/php/test.php")
eq(entries[1].lnum, 21)
eq(entries[1].col, 0)

eq(entries[1].line, "$p = newPerson(42);")
eq(entries[2].line, "$num1 = $p->getAge();")
end)

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

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

eq(entries[1].line, "// A person")
eq(entries[2].line, "/*")
end)
end)

0 comments on commit d1ca7ec

Please sign in to comment.