Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ on: [push, pull_request]

jobs:
dialyzer:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: 24.3
rebar3-version: 3.17
- name: Dialyzer
run: rebar3 dialyzer

clang-format:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Print clang-format version
Expand All @@ -22,30 +23,32 @@ jobs:
run: dev/check-fmt

test-linux:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
otp: [23.3]
otp: [24.3]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: 3.17
- name: Compile
run: rebar3 compile
- name: Run tests
run: rebar3 eunit

test-linux-debug:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
otp: [23.3]
otp: [24.3]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: 3.17
- name: Compile
run: rebar3 as debug compile
- name: Run tests
Expand All @@ -69,10 +72,13 @@ jobs:
# run: rebar3 eunit

test-windows:
runs-on: windows-2016
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- run: choco install erlang rebar3
- uses: erlef/setup-beam@v1
with:
otp-version: 24.3
rebar3-version: 3.17
- run: |
Install-Module -Name posh-vs -Force
Install-PoshVs
Expand Down
2 changes: 1 addition & 1 deletion c_src/build_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case "$1" in
mkdir -p windows_build
cd windows_build

GENERATOR=${RE2_CMAKE_GENERATOR:-"Visual Studio 15 2017"}
GENERATOR=${RE2_CMAKE_GENERATOR:-"Visual Studio 16 2019"}
if [ x"$RE2_DEBUG" = x"1" ]; then
BUILD_TYPE=Debug
else
Expand Down
3 changes: 2 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ PortOpts = fun() ->
PCDep = {pc, "1.14.0"}.
%% TestDeps = [{triq, ".*",
%% {git, "https://gitlab.com/triq/triq.git", {branch, "master"}}}].
TestDeps = [triq].
%TestDeps = [triq].
TestDeps = [].

DebugWarns = [warnings_as_errors].
Artifact = case os:type() of
Expand Down
238 changes: 122 additions & 116 deletions test/re2_qc.erl
Original file line number Diff line number Diff line change
@@ -1,124 +1,130 @@
%% Copyright 2013-2020 Tuncer Ayaz
%% Use of this source code is governed by a BSD-style
%% license that can be found in the LICENSE file.

%
-module(re2_qc).

%%
%% Triq is broken so there is no way to make tests working so just disable all of them until they
%% are fixed using something different.
%%

%
%% We aim to test the NIFs and not RE2 itself, so the properties are
%% only concerned with making sure the Erlang interface works as
%% documented.

-include_lib("triq/include/triq.hrl").
-triq(eunit).

prop_number() ->
?FORALL(Int, non_neg_integer(),
begin
N = list_to_binary(integer_to_list(Int)),
{match, [N]} =:= re2:match(N, "^[0-9]+$")
end).

prop_byte() ->
?FORALL(Byte, byte(),
match =:= re2:match([Byte], "^.*", [{capture, none}])).

binary_str(Str) -> unicode:characters_to_binary(Str).

prop_char() ->
?FORALL(Char, unicode_char(),
begin
C = unicode:characters_to_binary([Char]),
match =:= re2:match(C, "^.+$", [{capture, none}])
end).

prop_string() ->
?FORALL(Str, ?LET(Size, choose(1,64), unicode_string(Size)),
begin
S = binary_str(Str),
match =:= re2:match(S, ".*", [{capture, none}])
end).

-define(REGEXES,
[".*", "([0-7]+)[uUlL]*", "[a|b]", "h.*o", "(\\d+):(\\w+)"]).

-define(REGEXOPTS,
[[{capture, none}],
[{capture, all_but_first, binary}],
[{capture, first, index}],
[{capture, first, binary}],
[{offset, 1}, {capture, all_but_first, binary}]]).

-define(STRINGS, ["12", "34", "hejsan", "foobar", "baz"]).

random_re_prop({M0, F0}, {M1, F1}) ->
?FORALL({Str,RE,Opts},
{elements(?STRINGS), elements(?REGEXES), elements(?REGEXOPTS)},
M0:F0(Str, RE, Opts) =:= M1:F1(Str, RE, Opts)).

prop_random_re2() ->
random_re_prop({re2, match}, {re2, match}).

prop_random_re_vs_re2() ->
random_re_prop({re, run}, {re2, match}).

-define(MIN_MEM, 1100).
-define(MAX_MEM, 2 bsl 30 - 1).
compile_options_static() -> elements(['caseless']).
compile_options_dynamic() -> ?LET(MaxMem, choose(?MIN_MEM, ?MAX_MEM),
{'max_mem', MaxMem}).
compile_option() ->
oneof([compile_options_static(), compile_options_dynamic()]).

prop_compile() ->
?FORALL({RE, Opts}, {elements(?REGEXES), [compile_option()]},
element(1, re2:compile(RE, Opts)) =:= ok).

replace_options() ->
elements([[], ['global']]).

prop_replace() ->
?FORALL({Str,RE,Replacement,Opts},
{?LET(S, elements(?STRINGS), binary_str(S)),
elements(?REGEXES),
?LET(S, unicode_string(64), binary_str(S)),
replace_options()},
?IMPLIES(not is_substr(Str, Replacement),
begin
case re2:match(Str, RE, [{capture, none}]) of
match ->
Res = re2:replace(Str, RE, Replacement, Opts),
%% Replacement must be a substring of Str
is_substr(Res, Replacement);
nomatch ->
true
end
end)).

is_substr(Str1, Str2) ->
nomatch =/= binary:match(Str1, Str2).

value_spec_id() -> oneof([non_neg_integer(), atom(), unicode_string()]).
value_spec_list() -> non_empty(list(value_spec_id())).
value_spec_static() -> elements(['all', 'all_but_first', 'first', 'none']).
value_spec() -> oneof([value_spec_static(), value_spec_list()]).
match_static_opt() -> elements(['caseless']).
match_offset_opt(Str) -> ?LET(Offset, choose(1, length(Str)),
{'offset', Offset}).
match_capture_1_opt() -> ?LET(VS, value_spec(), {'capture', VS}).
match_capture_2_opt() -> ?LET({VS, Opts},
{value_spec(), elements(['index', 'binary'])},
{'capture', VS, Opts}).
valid_match_option(Str) ->
[oneof([match_static_opt(),
match_offset_opt(Str),
match_capture_1_opt(),
match_capture_2_opt()])].

random_re_tuple() ->
?LET({Str, RE}, {elements(?STRINGS), elements(?REGEXES)},
?LET(Opts, valid_match_option(Str),
{Str, RE, Opts})).

prop_random_re_spec() ->
?FORALL({Str,RE,Opts}, random_re_tuple(),
re2:match(Str, RE, Opts) =:= re2:match(Str, RE, Opts)).
%
%-include_lib("triq/include/triq.hrl").
%-triq(eunit).
%
%prop_number() ->
% ?FORALL(Int, non_neg_integer(),
% begin
% N = list_to_binary(integer_to_list(Int)),
% {match, [N]} =:= re2:match(N, "^[0-9]+$")
% end).
%
%prop_byte() ->
% ?FORALL(Byte, byte(),
% match =:= re2:match([Byte], "^.*", [{capture, none}])).
%
%binary_str(Str) -> unicode:characters_to_binary(Str).
%
%prop_char() ->
% ?FORALL(Char, unicode_char(),
% begin
% C = unicode:characters_to_binary([Char]),
% match =:= re2:match(C, "^.+$", [{capture, none}])
% end).
%
%prop_string() ->
% ?FORALL(Str, ?LET(Size, choose(1,64), unicode_string(Size)),
% begin
% S = binary_str(Str),
% match =:= re2:match(S, ".*", [{capture, none}])
% end).
%
%-define(REGEXES,
% [".*", "([0-7]+)[uUlL]*", "[a|b]", "h.*o", "(\\d+):(\\w+)"]).
%
%-define(REGEXOPTS,
% [[{capture, none}],
% [{capture, all_but_first, binary}],
% [{capture, first, index}],
% [{capture, first, binary}],
% [{offset, 1}, {capture, all_but_first, binary}]]).
%
%-define(STRINGS, ["12", "34", "hejsan", "foobar", "baz"]).
%
%random_re_prop({M0, F0}, {M1, F1}) ->
% ?FORALL({Str,RE,Opts},
% {elements(?STRINGS), elements(?REGEXES), elements(?REGEXOPTS)},
% M0:F0(Str, RE, Opts) =:= M1:F1(Str, RE, Opts)).
%
%prop_random_re2() ->
% random_re_prop({re2, match}, {re2, match}).
%
%prop_random_re_vs_re2() ->
% random_re_prop({re, run}, {re2, match}).
%
%-define(MIN_MEM, 1100).
%-define(MAX_MEM, 2 bsl 30 - 1).
%compile_options_static() -> elements(['caseless']).
%compile_options_dynamic() -> ?LET(MaxMem, choose(?MIN_MEM, ?MAX_MEM),
% {'max_mem', MaxMem}).
%compile_option() ->
% oneof([compile_options_static(), compile_options_dynamic()]).
%
%prop_compile() ->
% ?FORALL({RE, Opts}, {elements(?REGEXES), [compile_option()]},
% element(1, re2:compile(RE, Opts)) =:= ok).
%
%replace_options() ->
% elements([[], ['global']]).
%
%prop_replace() ->
% ?FORALL({Str,RE,Replacement,Opts},
% {?LET(S, elements(?STRINGS), binary_str(S)),
% elements(?REGEXES),
% ?LET(S, unicode_string(64), binary_str(S)),
% replace_options()},
% ?IMPLIES(not is_substr(Str, Replacement),
% begin
% case re2:match(Str, RE, [{capture, none}]) of
% match ->
% Res = re2:replace(Str, RE, Replacement, Opts),
% %% Replacement must be a substring of Str
% is_substr(Res, Replacement);
% nomatch ->
% true
% end
% end)).
%
%is_substr(Str1, Str2) ->
% nomatch =/= binary:match(Str1, Str2).
%
%value_spec_id() -> oneof([non_neg_integer(), atom(), unicode_string()]).
%value_spec_list() -> non_empty(list(value_spec_id())).
%value_spec_static() -> elements(['all', 'all_but_first', 'first', 'none']).
%value_spec() -> oneof([value_spec_static(), value_spec_list()]).
%match_static_opt() -> elements(['caseless']).
%match_offset_opt(Str) -> ?LET(Offset, choose(1, length(Str)),
% {'offset', Offset}).
%match_capture_1_opt() -> ?LET(VS, value_spec(), {'capture', VS}).
%match_capture_2_opt() -> ?LET({VS, Opts},
% {value_spec(), elements(['index', 'binary'])},
% {'capture', VS, Opts}).
%valid_match_option(Str) ->
% [oneof([match_static_opt(),
% match_offset_opt(Str),
% match_capture_1_opt(),
% match_capture_2_opt()])].
%
%random_re_tuple() ->
% ?LET({Str, RE}, {elements(?STRINGS), elements(?REGEXES)},
% ?LET(Opts, valid_match_option(Str),
% {Str, RE, Opts})).
%
%prop_random_re_spec() ->
% ?FORALL({Str,RE,Opts}, random_re_tuple(),
% re2:match(Str, RE, Opts) =:= re2:match(Str, RE, Opts)).