-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lua tests and fix for excessive binary_expression calculations (#16)
* Basic tests for Lua and commenting out of rule not working properly * Verify implementation of nesting logic for Lua * Reintroduce binary_expression due to regular logical operations calc not working * Add simple Lua test for logical operators * Rewrite Lua binary expression code to make tests pass
- Loading branch information
Showing
7 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
;;; lua-test.el --- Lua language tests for codemetrics.el -*- lexical-binding: t; -*- | ||
|
||
;; Copyright (C) 2024 Marie Katrine Ekeberg | ||
|
||
;; Author: Marie Katrine Ekeberg <mke@themkat.net> | ||
|
||
;; This program is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
;;; Commentary: | ||
;; | ||
|
||
;;; Code: | ||
(require 'codemetrics) | ||
(require 'lua-mode) | ||
|
||
(codemetrics-test lua-simple | ||
"test/lua/Simple.lua" | ||
lua-mode | ||
'(3 | ||
(function_declaration . 0) | ||
(binary_expression . 0) | ||
(function_call . 0) | ||
(binary_expression . 0) | ||
(function_call . 0) | ||
(for_statement . 1) | ||
(if_statement . 2) | ||
(binary_expression . 0))) | ||
|
||
(codemetrics-test lua-recursion | ||
"test/lua/Recursion.lua" | ||
lua-mode | ||
'(2 | ||
(function_declaration . 0) | ||
(if_statement . 1) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(function_call . 1) | ||
(binary_expression . 0))) | ||
|
||
(codemetrics-test lua-nesting | ||
"test/lua/Nesting.lua" | ||
lua-mode | ||
'(7 | ||
(while_statement . 1) | ||
(binary_expression . 0) | ||
(if_statement . 2) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(repeat_statement . 2) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(if_statement . 1) | ||
(binary_expression . 0) | ||
(goto_statement . 1))) | ||
|
||
(codemetrics-test lua-logical-operators | ||
"test/lua/LogicalOperators.lua" | ||
lua-mode | ||
'(2 | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 1) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 1) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0) | ||
(binary_expression . 0))) | ||
|
||
|
||
|
||
;;; lua-test.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
local simple_and = 1 == 1 and 1 == 2 | ||
local simple_or = 1 == 1 or 1 == 2 | ||
|
||
local mix_one = 2 == 2 and 1 == 1 or 2 == 3 | ||
local mix_two = 1 == 2 or 2 == 3 and 3 == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Testing various statements and nesting of those | ||
local my_arr = { 1, 3, 5, 10, 23 } | ||
local i = 1 | ||
local some_value = 0 | ||
|
||
::beginning_flow:: | ||
while i < 6 do | ||
if my_arr[i] % 2 == 0 then | ||
some_value = some_value + 1 | ||
break | ||
end | ||
|
||
local j = 0 | ||
repeat | ||
j = j + 1 | ||
until j == 10 | ||
end | ||
|
||
|
||
|
||
if 10 < some_value then | ||
goto beginning_flow | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function factorial(n) | ||
if 1 <= n then | ||
return 1 | ||
end | ||
|
||
return n * factorial(n - 1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function square(n) | ||
return n * n | ||
end | ||
|
||
print("Square of 3: " .. square(3)) | ||
|
||
for i=1,10 do | ||
if 1 == i then | ||
end | ||
end |