From 37e74b8274926e4421a6a7e537ca965c92bb90b8 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 15 Apr 2013 15:36:09 -0700 Subject: [PATCH] Add a basic test harness for running Automation tests --- aegisub/automation/.gitignore | 1 + aegisub/automation/Makefile | 16 + aegisub/automation/tests/aegisub.cpp | 29 ++ .../tests/{ => automation}/appended-lines.lua | 0 .../{ => automation}/basic-export-test.lua | 0 .../tests/{ => automation}/basic-tests.lua | 0 .../{ => automation}/config-dialog-test.lua | 0 .../tests/{ => automation}/furi-test.ass | 0 .../{ => automation}/gen-absurd-t-line.lua | 0 .../tests/{ => automation}/hello-world.lua | 0 .../kara-templater-retime.ass | 0 .../{ => automation}/karaoke-parse-test.lua | 0 .../progress-reporting-test.lua | 0 .../{ => automation}/selection-set-test.lua | 0 .../test-filter-name-clash.lua | 0 .../tests/{ => automation}/test-furi.lua | 0 .../test-tablecopy-recursive.lua | 0 .../{ => automation}/test-text_extents.lua | 0 .../{ => automation}/text-extents-test.lua | 0 .../{ => automation}/trace-level-test.lua | 0 .../tests/{ => automation}/unicode-test.lua | 0 aegisub/automation/tests/modules/re.moon | 319 ++++++++++++++++++ aegisub/automation/tests/runner.moon | 23 ++ 23 files changed, 388 insertions(+) create mode 100644 aegisub/automation/.gitignore create mode 100644 aegisub/automation/tests/aegisub.cpp rename aegisub/automation/tests/{ => automation}/appended-lines.lua (100%) rename aegisub/automation/tests/{ => automation}/basic-export-test.lua (100%) rename aegisub/automation/tests/{ => automation}/basic-tests.lua (100%) rename aegisub/automation/tests/{ => automation}/config-dialog-test.lua (100%) rename aegisub/automation/tests/{ => automation}/furi-test.ass (100%) rename aegisub/automation/tests/{ => automation}/gen-absurd-t-line.lua (100%) rename aegisub/automation/tests/{ => automation}/hello-world.lua (100%) rename aegisub/automation/tests/{ => automation}/kara-templater-retime.ass (100%) rename aegisub/automation/tests/{ => automation}/karaoke-parse-test.lua (100%) rename aegisub/automation/tests/{ => automation}/progress-reporting-test.lua (100%) rename aegisub/automation/tests/{ => automation}/selection-set-test.lua (100%) rename aegisub/automation/tests/{ => automation}/test-filter-name-clash.lua (100%) rename aegisub/automation/tests/{ => automation}/test-furi.lua (100%) rename aegisub/automation/tests/{ => automation}/test-tablecopy-recursive.lua (100%) rename aegisub/automation/tests/{ => automation}/test-text_extents.lua (100%) rename aegisub/automation/tests/{ => automation}/text-extents-test.lua (100%) rename aegisub/automation/tests/{ => automation}/trace-level-test.lua (100%) rename aegisub/automation/tests/{ => automation}/unicode-test.lua (100%) create mode 100644 aegisub/automation/tests/modules/re.moon create mode 100644 aegisub/automation/tests/runner.moon diff --git a/aegisub/automation/.gitignore b/aegisub/automation/.gitignore new file mode 100644 index 000000000..720ad35d4 --- /dev/null +++ b/aegisub/automation/.gitignore @@ -0,0 +1 @@ +aegisub.so.* diff --git a/aegisub/automation/Makefile b/aegisub/automation/Makefile index 2612b4a21..15b44658d 100644 --- a/aegisub/automation/Makefile +++ b/aegisub/automation/Makefile @@ -1,5 +1,21 @@ include ../Makefile.inc +LIB_SHARED = aegisub.so +LIB_VERSION = 0.1.0 + +CXXFLAGS += -I../libaegisub/include -I../src $(CXXFLAGS_WX) +CPPFLAGS += $(CPPFLAGS_BOOST) + +LIBS := -L../libaegisub -laegisub $(LIBS) +LIBS += $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU) $(LIBS_LUA) + +SRC += tests/aegisub.cpp ../src/auto4_regex.cpp + +test: $(LIB_SHARED) + moon tests/runner.moon + +.PHONY: test + # share/ DATA_AUTOMATION += \ autoload/clean-info.lua \ diff --git a/aegisub/automation/tests/aegisub.cpp b/aegisub/automation/tests/aegisub.cpp new file mode 100644 index 000000000..0a02b749d --- /dev/null +++ b/aegisub/automation/tests/aegisub.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2013, Thomas Goyne +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ + +#include "config.h" + +#include "auto4_lua_utils.h" + +namespace Automation4 { int regex_init(lua_State *L); } + +extern "C" int luaopen_aegisub(lua_State *L) { + lua_pushstring(L, "aegisub"); + lua_newtable(L); + set_field(L, "__init_regex", Automation4::regex_init); + lua_settable(L, LUA_GLOBALSINDEX); + return 1; +} diff --git a/aegisub/automation/tests/appended-lines.lua b/aegisub/automation/tests/automation/appended-lines.lua similarity index 100% rename from aegisub/automation/tests/appended-lines.lua rename to aegisub/automation/tests/automation/appended-lines.lua diff --git a/aegisub/automation/tests/basic-export-test.lua b/aegisub/automation/tests/automation/basic-export-test.lua similarity index 100% rename from aegisub/automation/tests/basic-export-test.lua rename to aegisub/automation/tests/automation/basic-export-test.lua diff --git a/aegisub/automation/tests/basic-tests.lua b/aegisub/automation/tests/automation/basic-tests.lua similarity index 100% rename from aegisub/automation/tests/basic-tests.lua rename to aegisub/automation/tests/automation/basic-tests.lua diff --git a/aegisub/automation/tests/config-dialog-test.lua b/aegisub/automation/tests/automation/config-dialog-test.lua similarity index 100% rename from aegisub/automation/tests/config-dialog-test.lua rename to aegisub/automation/tests/automation/config-dialog-test.lua diff --git a/aegisub/automation/tests/furi-test.ass b/aegisub/automation/tests/automation/furi-test.ass similarity index 100% rename from aegisub/automation/tests/furi-test.ass rename to aegisub/automation/tests/automation/furi-test.ass diff --git a/aegisub/automation/tests/gen-absurd-t-line.lua b/aegisub/automation/tests/automation/gen-absurd-t-line.lua similarity index 100% rename from aegisub/automation/tests/gen-absurd-t-line.lua rename to aegisub/automation/tests/automation/gen-absurd-t-line.lua diff --git a/aegisub/automation/tests/hello-world.lua b/aegisub/automation/tests/automation/hello-world.lua similarity index 100% rename from aegisub/automation/tests/hello-world.lua rename to aegisub/automation/tests/automation/hello-world.lua diff --git a/aegisub/automation/tests/kara-templater-retime.ass b/aegisub/automation/tests/automation/kara-templater-retime.ass similarity index 100% rename from aegisub/automation/tests/kara-templater-retime.ass rename to aegisub/automation/tests/automation/kara-templater-retime.ass diff --git a/aegisub/automation/tests/karaoke-parse-test.lua b/aegisub/automation/tests/automation/karaoke-parse-test.lua similarity index 100% rename from aegisub/automation/tests/karaoke-parse-test.lua rename to aegisub/automation/tests/automation/karaoke-parse-test.lua diff --git a/aegisub/automation/tests/progress-reporting-test.lua b/aegisub/automation/tests/automation/progress-reporting-test.lua similarity index 100% rename from aegisub/automation/tests/progress-reporting-test.lua rename to aegisub/automation/tests/automation/progress-reporting-test.lua diff --git a/aegisub/automation/tests/selection-set-test.lua b/aegisub/automation/tests/automation/selection-set-test.lua similarity index 100% rename from aegisub/automation/tests/selection-set-test.lua rename to aegisub/automation/tests/automation/selection-set-test.lua diff --git a/aegisub/automation/tests/test-filter-name-clash.lua b/aegisub/automation/tests/automation/test-filter-name-clash.lua similarity index 100% rename from aegisub/automation/tests/test-filter-name-clash.lua rename to aegisub/automation/tests/automation/test-filter-name-clash.lua diff --git a/aegisub/automation/tests/test-furi.lua b/aegisub/automation/tests/automation/test-furi.lua similarity index 100% rename from aegisub/automation/tests/test-furi.lua rename to aegisub/automation/tests/automation/test-furi.lua diff --git a/aegisub/automation/tests/test-tablecopy-recursive.lua b/aegisub/automation/tests/automation/test-tablecopy-recursive.lua similarity index 100% rename from aegisub/automation/tests/test-tablecopy-recursive.lua rename to aegisub/automation/tests/automation/test-tablecopy-recursive.lua diff --git a/aegisub/automation/tests/test-text_extents.lua b/aegisub/automation/tests/automation/test-text_extents.lua similarity index 100% rename from aegisub/automation/tests/test-text_extents.lua rename to aegisub/automation/tests/automation/test-text_extents.lua diff --git a/aegisub/automation/tests/text-extents-test.lua b/aegisub/automation/tests/automation/text-extents-test.lua similarity index 100% rename from aegisub/automation/tests/text-extents-test.lua rename to aegisub/automation/tests/automation/text-extents-test.lua diff --git a/aegisub/automation/tests/trace-level-test.lua b/aegisub/automation/tests/automation/trace-level-test.lua similarity index 100% rename from aegisub/automation/tests/trace-level-test.lua rename to aegisub/automation/tests/automation/trace-level-test.lua diff --git a/aegisub/automation/tests/unicode-test.lua b/aegisub/automation/tests/automation/unicode-test.lua similarity index 100% rename from aegisub/automation/tests/unicode-test.lua rename to aegisub/automation/tests/automation/unicode-test.lua diff --git a/aegisub/automation/tests/modules/re.moon b/aegisub/automation/tests/modules/re.moon new file mode 100644 index 000000000..808bda233 --- /dev/null +++ b/aegisub/automation/tests/modules/re.moon @@ -0,0 +1,319 @@ +-- Copyright (c) 2013, Thomas Goyne +-- +-- Permission to use, copy, modify, and distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +require 'aegisub' +require 'lunatest' +re = require 'aegisub.re' + +export test_compile = -> + r = re.compile '.' + + res = r\find 'abc' + assert_not_nil res + assert_equal 3, #res + + res = r\find 'bc' + assert_not_nil res + assert_equal 2, #res + +export test_compile_bad_call_is_error = -> + r = re.compile '.' + assert_error -> r.find 'bc' + +export test_find_bol_only_matches_once = -> + res = re.find 'aaa', '^a' + assert_not_nil res + assert_equal 1, #res + +export test_find_finds_characters_not_bytes = -> + res = re.find '☃☃', '.' + assert_not_nil res + assert_equal 2, #res + assert_equal '☃', res[1].str + assert_equal 1, res[1].first + assert_equal 3, res[1].last + assert_equal '☃', res[2].str + assert_equal 4, res[2].first + assert_equal 6, res[2].last + +export test_find_no_matches_returns_nil = -> + assert_nil(re.find 'a', 'b') + +export test_find_on_empty_string_returns_nil = -> + assert_nil(re.find '', '.') + +export test_find_plain = -> + res = re.find 'aa', '.' + assert_not_nil res + assert_equal 2, #res + assert_equal 'a', res[1].str + assert_equal 1, res[1].first + assert_equal 1, res[1].last + assert_equal 'a', res[2].str + assert_equal 2, res[2].first + assert_equal 2, res[2].last + +export test_find_zero_length_match = -> + res = re.find 'abc', '^' + assert_not_nil res + assert_equal 1, #res + assert_equal '', res[1].str + assert_equal 1, res[1].first + assert_equal 0, res[1].last + +export test_flags_in_wrong_position_is_error = -> + assert_error -> re.sub 'a', re.ICASE, 'b', 'c' + assert_error -> re.sub 'a', 'b', re.ICASE, 'c' + +export test_invalid_regex_syntax_is_error = -> + assert_error -> re.compile '(' + +export test_match_plain = -> + res = re.match '{250 1173 380}Help!', '(\\d+) (\\d+) (\\d+)' + assert_not_nil res + assert_equal 4, #res + assert_equal '250 1173 380', res[1].str + assert_equal 2, res[1].first + assert_equal 13, res[1].last + + assert_equal '250', res[2].str + assert_equal 2, res[2].first + assert_equal 4, res[2].last + + assert_equal '1173', res[3].str + assert_equal 6, res[3].first + assert_equal 9, res[3].last + + assert_equal '380', res[4].str + assert_equal 11, res[4].first + assert_equal 13, res[4].last + +export test_match_zero_length_match = -> + res = re.match 'abc', '^' + assert_not_nil res + assert_equal 1, #res + assert_equal '', res[1].str + assert_equal 1, res[1].first + assert_equal 0, res[1].last + +export test_split_delim_not_found_gives_input_string_in_table = -> + res = re.split 'abc', ',' + assert_not_nil res + assert_equal 1, #res + assert_equal 'abc', res[1] + +export test_split_empty_string_returns_empty_table = -> + res = re.split '', ',' + assert_not_nil res + assert_equal 0, #res + +export test_split_max_splits_noskip = -> + res = re.split 'a,,b,c', ',', false, 1 + assert_not_nil res + assert_equal 2, #res + assert_equal 'a', res[1] + assert_equal ',b,c', res[2] + +export test_split_max_splits_skip = -> + res = re.split 'a,,b,c', ',', true, 1 + assert_not_nil res + assert_equal 2, #res + assert_equal 'a', res[1] + assert_equal ',b,c', res[2] + + res = re.split 'a,,b,c,d', ',', true, 2 + assert_not_nil res + assert_equal 3, #res + assert_equal 'a', res[1] + assert_equal 'b', res[2] + assert_equal 'c,d', res[3] + +export test_split_multi_character_delimeter = -> + res = re.split 'a::b::c:d', '::' + assert_not_nil res + assert_equal 3, #res + assert_equal 'a', res[1] + assert_equal 'b', res[2] + assert_equal 'c:d', res[3] + +export test_split_plain = -> + res = re.split 'a,,b,c', ',' + assert_not_nil res + assert_equal 4, #res + assert_equal 'a', res[1] + assert_equal '', res[2] + assert_equal 'b', res[3] + assert_equal 'c', res[4] + +export test_split_skip_empty = -> + res = re.split 'a,,b,c', ',', true + assert_not_nil res + assert_equal 3, #res + assert_equal 'a', res[1] + assert_equal 'b', res[2] + assert_equal 'c', res[3] + +export test_sub_bad_find_is_error = -> + assert_error -> re.sub 'aa', 5, 'b' + +export test_sub_bad_haystack_is_error = -> + assert_error -> re.sub 5, 'a', 'b' + +export test_sub_bad_replacement_is_error = -> + assert_error -> re.sub 'aa', 'a', 5 + +export test_sub_capture_groups = -> + assert_equal 'aabbaabb', re.sub 'abab', '(a)(b)', (str) -> str .. str + +export test_sub_empty_string_returns_empty = -> + assert_equal '', re.sub '', 'b', 'c' + +export test_sub_function = -> + add_one = (str) -> tostring tonumber(str) + 1 + + res = re.sub '{\\k10}a{\\k15}b{\\k30}c', '\\\\k([[:digit:]]+)', add_one + assert_not_nil res + assert_equal '{\\k11}a{\\k16}b{\\k31}c', res + +export test_sub_function_no_capture_group_passes_full_match = -> + found = {} + drop_match = (str) -> + table.insert found, str + '' + + res = re.sub '{\\k10}a{\\k15}b{\\k30}c', '\\\\k[[:digit:]]+', drop_match + assert_not_nil res + assert_equal '{}a{}b{}c', res + + assert_equal 3, #found + assert_equal '\\k10', found[1] + assert_equal '\\k15', found[2] + assert_equal '\\k30', found[3] + +export test_sub_function_returning_non_string_returns_unchanged_input = -> + found = {} + mutate_external = (str) -> + table.insert found, str + nil + + res = re.sub '{\\k10}a{\\k15}b{\\k30}c', '\\\\k([[:digit:]]+)', mutate_external + assert_not_nil res + assert_equal '{\\k10}a{\\k15}b{\\k30}c', res + + assert_equal 3, #found + assert_equal '10', found[1] + assert_equal '15', found[2] + assert_equal '30', found[3] + +export test_sub_icase = -> + res = re.sub '{\\K10}a{\\K15}b{\\k30}c', '\\\\k', '\\\\kf', re.ICASE + assert_not_nil res + assert_equal '{\\kf10}a{\\kf15}b{\\kf30}c', res + +export test_sub_icase_greek = -> + res = re.sub '!συνεργ!', 'Συνεργ', 'foo', re.ICASE + assert_not_nil res + assert_equal '!foo!', res + +export test_sub_max_replace_count = -> + res = re.sub 'aaa', 'a', 'b', 2 + assert_not_nil res + assert_equal 'bba', res + +export test_sub_no_matches_leaves_unchanged = -> + assert_equal('a', re.sub 'a', 'b', 'c') + +export test_sub_plain = -> + res = re.sub '{\\k10}a{\\k15}b{\\k30}c', '\\\\k', '\\\\kf' + assert_not_nil res + assert_equal '{\\kf10}a{\\kf15}b{\\kf30}c', res + +export test_sub_zero_length_match_bol = -> + res = re.sub 'abc', '^', 'd' + assert_not_nil res + assert_equal 'dabc', res + +export test_sub_zero_length_match_bow = -> + res = re.sub 'abc abc', '\\<', 'd' + assert_not_nil res + assert_equal 'dabc dabc', res + +export test_sub_zero_length_match_bob = -> + res = re.sub 'abc', '\\A', 'd' + assert_not_nil res + assert_equal 'dabc', res + +assert_empty_match_and_return_d = (str) -> + assert_equal '', str + 'd' + +export test_sub_zero_length_match_bol_with_function_replacement = -> + res = re.sub 'abc', '^', assert_empty_match_and_return_d + assert_not_nil res + assert_equal 'dabc', res + +export test_sub_zero_length_match_bow_with_function_replacement = -> + res = re.sub 'abc abc', '\\<', assert_empty_match_and_return_d + assert_not_nil res + assert_equal 'dabc dabc', res + +export test_sub_zero_length_match_bob_with_function_replacement = -> + res = re.sub 'abc', '\\A', assert_empty_match_and_return_d + assert_not_nil res + assert_equal 'dabc', res + +export test_sub_zero_length_match_eol = -> + res = re.sub 'abc', '$', 'd' + assert_not_nil res + assert_equal 'abcd', res + +export test_sub_zero_length_match_eol_with_function_replacement = -> + res = re.sub 'abc', '$', assert_empty_match_and_return_d + assert_not_nil res + assert_equal 'abcd', res + +export test_sub_zero_length_match_mid = -> + res = re.sub 'abc', 'e?', 'd' + assert_not_nil res + assert_equal 'dadbdcd', res + + res = re.sub 'abc', 'b*', 'd' + assert_not_nil res + assert_equal 'daddcd', res + +export test_sub_zero_length_match_mid_with_function_replacement = -> + res = re.sub 'abc', 'e?', assert_empty_match_and_return_d + assert_not_nil res + assert_equal 'dadbdcd', res + +export test_zero_length_regex_is_error = -> + assert_error -> re.compile '' + +export test_split_word_boundary = -> + res = re.split 'aa bb cc', '\\b', true + assert_not_nil res + assert_equal 5, #res + assert_equal res[1], 'aa' + assert_equal res[2], ' ' + assert_equal res[3], 'bb' + assert_equal res[4], ' ' + assert_equal res[5], 'cc' + +export test_split_bob = -> + res = re.split 'aa bb cc', '\\A' + assert_not_nil res + assert_equal 2, #res + assert_equal '', res[1] + assert_equal 'aa bb cc', res[2] + diff --git a/aegisub/automation/tests/runner.moon b/aegisub/automation/tests/runner.moon new file mode 100644 index 000000000..8af7b1a01 --- /dev/null +++ b/aegisub/automation/tests/runner.moon @@ -0,0 +1,23 @@ +-- Copyright (c) 2013, Thomas Goyne +-- +-- Permission to use, copy, modify, and distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +require 'lunatest' +require 'lfs' + +package.path ..= 'include/?.lua;' + +for file in lfs.dir 'tests/modules' + require "tests.modules.#{file\gsub '\.[^.]+$', ''}" unless file\sub(1, 1) == '.' + +lunatest.run()