-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,234 additions
and
965 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: unit_test | ||
on: | ||
push: | ||
paths: | ||
- '*.lua' | ||
- 'test/*' | ||
pull_request: | ||
paths: | ||
- '*.lua' | ||
- 'test/*' | ||
|
||
jobs: | ||
unit_test: | ||
permissions: | ||
contents: read | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 1 | ||
matrix: | ||
version: [5.1, 5.2, 5.3, 5.4] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Lua | ||
run: sudo apt-get install lua${{ matrix.version }} liblua${{ matrix.version }}-dev luarocks | ||
|
||
- name: Configure Luarocks | ||
run: luarocks config lua_version ${{ matrix.version }} | ||
|
||
- name: Install lua-utf8 | ||
run: luarocks --local install luautf8 | ||
|
||
- name: Run Test | ||
working-directory: test | ||
run: ./test_all ${{ matrix.version }} |
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
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,63 @@ | ||
--[[ | ||
Test 8 bit encoding | ||
The test succeeds only in 8 bit encoding. | ||
-]] | ||
local unit_test = require("unit_test") | ||
local phrase = require("phrase") | ||
|
||
local test_8bit_encoding = {} | ||
|
||
function test_8bit_encoding.run_test() | ||
local ut = unit_test.new() | ||
|
||
-- select the first option. | ||
phrase.set_random_function(ut:get_stub_random()) | ||
|
||
-- override the function to check if some errors are detected. | ||
local error_messages = "" | ||
local error_is_expected = false -- It can be changed in the test functions. | ||
function phrase.output_error(err_msg) | ||
error_messages = error_messages .. err_msg | ||
if not error_is_expected then | ||
io.stderr:write(err_msg) | ||
end | ||
end | ||
|
||
-- Clear the error messages. | ||
ut:set_enter(function () | ||
error_messages = "" | ||
error_is_expected = false | ||
end) | ||
-- Check if some errors are detected. | ||
ut:set_leave(function () | ||
return error_is_expected ~= (error_messages == "") | ||
end) | ||
|
||
|
||
local tests = {} | ||
|
||
function tests.parse_error_message() | ||
local ph = phrase.new() | ||
error_is_expected = true | ||
ph:add([[ | ||
main {* ああ } = text1 | text2 | text3 ~ /pat1/repl1/ ~ /pat2/repl2/g | ||
]]) | ||
return error_messages == [[ | ||
Error in the phrase "main {* ああ } = text1 | text2 | text3 ...": | ||
Line#1, Column#18: "=" or ":=" is expected. | ||
]] | ||
end | ||
|
||
function tests.gsub_substitution() | ||
local ph = phrase.new() | ||
ph:add([[ | ||
main = あいう ~ /[あ]/か/]]) | ||
local r = ph:generate() | ||
return r == "か\129\130いう" | ||
end | ||
|
||
return ut:runner("8 Bit Encoding Test", tests, { verbose = false }) | ||
end | ||
|
||
return test_8bit_encoding |
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,9 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
VER=$1 | ||
|
||
luarocks config lua_version ${VER} | ||
eval `luarocks path` | ||
lua${VER} test_main_normal.lua | ||
lua${VER} test_encoding_error.lua |
This file was deleted.
Oops, something went wrong.
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,95 @@ | ||
--[[ | ||
Test to raise the encoding error | ||
The test under the condition that fails to require("lua-utf8"). | ||
--]] | ||
local unit_test = require("unit_test") | ||
|
||
-- must fail to require("lua-utf8") | ||
package.path = "./?.lua;../scripts/?.lua" | ||
package.cpath = "" | ||
local phrase = require("phrase") | ||
|
||
|
||
local test_encoding_error = {} | ||
|
||
function test_encoding_error.run_test() | ||
local ut = unit_test.new() | ||
|
||
-- select the first option. | ||
phrase.set_random_function(ut:get_stub_random()) | ||
|
||
-- override the function to check if some errors are detected. | ||
local error_messages = "" | ||
local error_is_expected = false -- It can be changed in the test functions. | ||
function phrase.output_error(err_msg) | ||
error_messages = error_messages .. err_msg | ||
if not error_is_expected then | ||
io.stderr:write(err_msg) | ||
end | ||
end | ||
|
||
-- Clear the error messages and the random sequence. | ||
ut:set_enter(function () | ||
phrase.require_utf8(false) | ||
ut:set_random_sequence({}) | ||
error_messages = "" | ||
error_is_expected = false | ||
end) | ||
-- Check if some errors are detected. | ||
ut:set_leave(function () | ||
return error_is_expected ~= (error_messages == "") | ||
end) | ||
|
||
|
||
local tests = {} | ||
|
||
function tests.new_fatal_error_without_parameter() | ||
phrase.require_utf8(true) | ||
error_is_expected = true | ||
local ph = phrase.new() | ||
return ph == nil | ||
end | ||
|
||
function tests.new_fatal_error_with_a_parameter() | ||
phrase.require_utf8(true) | ||
error_is_expected = true | ||
local ph = phrase.new([[main = A]]) | ||
return ph == nil | ||
end | ||
|
||
function tests.compile_fatal_error_without_parameter() | ||
phrase.require_utf8(true) | ||
error_is_expected = true | ||
local compiled = phrase.compile() | ||
return compiled == nil | ||
end | ||
|
||
function tests.compile_fatal_error_with_a_parameter() | ||
phrase.require_utf8(true) | ||
error_is_expected = true | ||
local compiled = phrase.compile([[main = A]]) | ||
return compiled == nil | ||
end | ||
|
||
function tests.compile_add_fatal_error() | ||
local compiled = phrase.compile([[A = 1]]) | ||
phrase.require_utf8(true) | ||
error_is_expected = true | ||
local result = compiled:add([[B = 2]]) | ||
return | ||
not result and | ||
compiled.type_compiled_syntax and | ||
compiled.data.type_syntax and | ||
compiled.data.assignments["A"] and | ||
not compiled.data.assignments["B"] | ||
end | ||
|
||
return ut:runner("Character Encoding Error Test", tests, { verbose = false }) | ||
end | ||
|
||
if test_encoding_error.run_test() > 0 then | ||
os.exit(1) | ||
else | ||
os.exit(0) | ||
end |
Oops, something went wrong.