glib2 3.0.7 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +24 -12
- data/ext/glib2/extconf.rb +1 -0
- data/ext/glib2/glib2.def +4 -0
- data/ext/glib2/rbglib-variant.c +163 -12
- data/ext/glib2/rbglib.c +31 -8
- data/ext/glib2/rbglib.h +15 -1
- data/ext/glib2/rbglib2conversions.h +3 -0
- data/ext/glib2/rbglib_iochannel.c +0 -3
- data/ext/glib2/rbglib_iochannel_win32_socket.c +0 -1
- data/ext/glib2/rbglib_matchinfo.c +179 -0
- data/ext/glib2/rbglib_regex.c +484 -0
- data/ext/glib2/rbgobj_value.c +7 -1
- data/ext/glib2/rbgprivate.h +2 -0
- data/ext/glib2/rbgutil.c +7 -0
- data/ext/glib2/rbgutil.h +2 -0
- data/lib/glib2.rb +2 -1
- data/lib/glib2/regex.rb +29 -0
- data/lib/gnome2/rake/external-package.rb +6 -1
- data/lib/gnome2/rake/package-task.rb +1 -1
- data/lib/gnome2/rake/package.rb +9 -0
- data/lib/gnome2/rake/windows-binary-build-task.rb +35 -11
- data/lib/mkmf-gnome2.rb +3 -1
- data/test/test-match-info.rb +113 -0
- data/test/test-regex.rb +320 -0
- metadata +9 -4
data/ext/glib2/rbgobj_value.c
CHANGED
@@ -122,12 +122,14 @@ rbgobj_gvalue_to_rvalue(const GValue* value)
|
|
122
122
|
return func(value);
|
123
123
|
}
|
124
124
|
}
|
125
|
+
#if GLIB_CHECK_VERSION(2, 26, 0)
|
125
126
|
case G_TYPE_VARIANT:
|
126
127
|
{
|
127
128
|
GVariant *variant = g_value_peek_pointer(value);
|
128
129
|
rvalue = rbg_variant_to_ruby(variant);
|
129
130
|
return rvalue;
|
130
131
|
}
|
132
|
+
#endif
|
131
133
|
default:
|
132
134
|
if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) {
|
133
135
|
GValueToRValueFunc func;
|
@@ -308,7 +310,11 @@ rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
|
|
308
310
|
return;
|
309
311
|
}
|
310
312
|
}
|
311
|
-
|
313
|
+
#if GLIB_CHECK_VERSION(2, 26, 0)
|
314
|
+
case G_TYPE_VARIANT:
|
315
|
+
g_value_set_variant(result, rbg_variant_from_ruby(val));
|
316
|
+
break;
|
317
|
+
#endif
|
312
318
|
default:
|
313
319
|
if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) {
|
314
320
|
RValueToGValueFunc func =
|
data/ext/glib2/rbgprivate.h
CHANGED
@@ -152,6 +152,8 @@ G_GNUC_INTERNAL void Init_glib_keyfile(void);
|
|
152
152
|
G_GNUC_INTERNAL void Init_glib_bookmark_file(void);
|
153
153
|
G_GNUC_INTERNAL void Init_glib_variant_type(void);
|
154
154
|
G_GNUC_INTERNAL void Init_glib_variant(void);
|
155
|
+
G_GNUC_INTERNAL void Init_glib_regex(void);
|
156
|
+
G_GNUC_INTERNAL void Init_glib_matchinfo(void);
|
155
157
|
|
156
158
|
G_GNUC_INTERNAL void Init_gobject_convert(void);
|
157
159
|
G_GNUC_INTERNAL void Init_gobject_gtype(void);
|
data/ext/glib2/rbgutil.c
CHANGED
data/ext/glib2/rbgutil.h
CHANGED
@@ -109,6 +109,8 @@ extern GSource *rbg_interrupt_source_new(void);
|
|
109
109
|
|
110
110
|
extern gchar *rbg_name_to_nick(const gchar *name);
|
111
111
|
|
112
|
+
extern void *rbg_memzero(void *poitner, size_t size);
|
113
|
+
|
112
114
|
/*< protected >*/
|
113
115
|
RUBY_GLIB2_VAR ID rbgutil_id_module_eval;
|
114
116
|
extern void rbgutil_glibid_r2g_func(VALUE from, GValue* to);
|
data/lib/glib2.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2005-
|
1
|
+
# Copyright (C) 2005-2016 Ruby-GNOME2 Project Team
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -241,6 +241,7 @@ GLib::Log.set_log_domain(GLib::Thread::LOG_DOMAIN)
|
|
241
241
|
GLib::Log.set_log_domain(GLib::Module::LOG_DOMAIN)
|
242
242
|
|
243
243
|
require 'glib2/version'
|
244
|
+
require "glib2/regex"
|
244
245
|
=begin
|
245
246
|
Don't we need this?
|
246
247
|
ObjectSpace.define_finalizer(GLib) {
|
data/lib/glib2/regex.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright (C) 2016 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module GLib
|
18
|
+
class Regex
|
19
|
+
class << self
|
20
|
+
def match?(pattern, string, options={})
|
21
|
+
new(pattern, options).match(string, options).matches?
|
22
|
+
end
|
23
|
+
|
24
|
+
def split(pattern, string, options={})
|
25
|
+
new(pattern, options).split(string, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -123,7 +123,8 @@ module GNOME2
|
|
123
123
|
:need_autogen,
|
124
124
|
:need_autoreconf,
|
125
125
|
:build_concurrently,
|
126
|
-
:use_cc_environment_variable
|
126
|
+
:use_cc_environment_variable,
|
127
|
+
:gobject_introspection_compiler_split_args)
|
127
128
|
def initialize(properties)
|
128
129
|
super()
|
129
130
|
properties.each do |key, value|
|
@@ -178,6 +179,10 @@ module GNOME2
|
|
178
179
|
def use_cc_environment_variable?
|
179
180
|
use_cc_environment_variable.nil? ? true : use_cc_environment_variable
|
180
181
|
end
|
182
|
+
|
183
|
+
def gobject_introspection_compiler_split_args?
|
184
|
+
gobject_introspection_compiler_split_args
|
185
|
+
end
|
181
186
|
end
|
182
187
|
|
183
188
|
class NativeConfiguration < Struct.new(:build,
|
@@ -119,7 +119,7 @@ module GNOME2
|
|
119
119
|
s.author = @author
|
120
120
|
s.email = @email
|
121
121
|
s.homepage = @homepage
|
122
|
-
s.licenses = ["LGPLv2.1
|
122
|
+
s.licenses = ["LGPLv2.1+"]
|
123
123
|
s.version = version
|
124
124
|
extensions = FileList["ext/#{@name}/extconf.rb"]
|
125
125
|
extensions.existing!
|
data/lib/gnome2/rake/package.rb
CHANGED
@@ -126,6 +126,15 @@ module GNOME2
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
def build_arch
|
130
|
+
case build_architecture
|
131
|
+
when "x86"
|
132
|
+
"i686"
|
133
|
+
when "x64"
|
134
|
+
"x86_64"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
129
138
|
def build_architecture
|
130
139
|
ENV["RUBY_GNOME2_BUILD_ARCHITECTURE"] || "x86"
|
131
140
|
end
|
@@ -120,7 +120,7 @@ class GNOME2WindowsBinaryBuildTask
|
|
120
120
|
if package.windows.use_cc_environment_variable?
|
121
121
|
common_make_args << cc_env(package)
|
122
122
|
end
|
123
|
-
add_gobject_introspection_make_args(common_make_args)
|
123
|
+
add_gobject_introspection_make_args(package, common_make_args)
|
124
124
|
build_make_args = common_make_args.dup
|
125
125
|
install_make_args = common_make_args.dup
|
126
126
|
if package.windows.build_concurrently?
|
@@ -128,6 +128,9 @@ class GNOME2WindowsBinaryBuildTask
|
|
128
128
|
build_make_args << "-j#{make_n_jobs}" if make_n_jobs
|
129
129
|
end
|
130
130
|
ENV["GREP_OPTIONS"] = "--text"
|
131
|
+
# ENV["GI_SCANNER_DEBUG"] = "save-temps"
|
132
|
+
# build_make_args << "--debug"
|
133
|
+
# build_make_args << "V=1"
|
131
134
|
sh("nice", "make", *build_make_args) or exit(false)
|
132
135
|
sh("make", "install", *install_make_args) or exit(false)
|
133
136
|
|
@@ -152,9 +155,10 @@ class GNOME2WindowsBinaryBuildTask
|
|
152
155
|
|
153
156
|
def configure(package)
|
154
157
|
sh("./autogen.sh") if package.windows.need_autogen?
|
155
|
-
sh("autoreconf --install") if package.windows.need_autoreconf?
|
158
|
+
sh("autoreconf", "--install", "--force") if package.windows.need_autoreconf?
|
156
159
|
sh("./configure",
|
157
160
|
cc_env(package),
|
161
|
+
dlltool_env,
|
158
162
|
"CPPFLAGS=#{cppflags(package)}",
|
159
163
|
"LDFLAGS=#{ldflags(package)}",
|
160
164
|
"--prefix=#{dist_dir}",
|
@@ -177,6 +181,10 @@ class GNOME2WindowsBinaryBuildTask
|
|
177
181
|
"CC=#{cc(package)}"
|
178
182
|
end
|
179
183
|
|
184
|
+
def dlltool_env
|
185
|
+
"DLLTOOL=#{dlltool}"
|
186
|
+
end
|
187
|
+
|
180
188
|
def build_packages
|
181
189
|
packages = @package.external_packages.select do |package|
|
182
190
|
package.windows.build?
|
@@ -241,6 +249,10 @@ class GNOME2WindowsBinaryBuildTask
|
|
241
249
|
cxx_command_line.compact.join(" ")
|
242
250
|
end
|
243
251
|
|
252
|
+
def dlltool
|
253
|
+
"#{@package.windows.build_host}-dlltool"
|
254
|
+
end
|
255
|
+
|
244
256
|
def cppflags(package)
|
245
257
|
include_paths = package.windows.include_paths
|
246
258
|
if @package.windows.build_dependencies.include?("glib2")
|
@@ -282,7 +294,7 @@ class GNOME2WindowsBinaryBuildTask
|
|
282
294
|
paths
|
283
295
|
end
|
284
296
|
|
285
|
-
def add_gobject_introspection_make_args(common_make_args)
|
297
|
+
def add_gobject_introspection_make_args(package, common_make_args)
|
286
298
|
unless @package.windows.build_dependencies.include?("gobject-introspection")
|
287
299
|
return
|
288
300
|
end
|
@@ -299,21 +311,33 @@ class GNOME2WindowsBinaryBuildTask
|
|
299
311
|
]
|
300
312
|
dependencies += @package.windows.gobject_introspection_dependencies
|
301
313
|
|
302
|
-
compute_base_dir = lambda do |
|
303
|
-
"#{@package.project_root_dir}/#{
|
314
|
+
compute_base_dir = lambda do |dependent_package|
|
315
|
+
"#{@package.project_root_dir}/#{dependent_package}/vendor/local"
|
304
316
|
end
|
305
317
|
|
306
318
|
gi_base_dir = compute_base_dir.call("gobject-introspection")
|
307
319
|
introspection_compiler = "INTROSPECTION_COMPILER="
|
308
320
|
introspection_compiler << "#{gi_base_dir}/bin/g-ir-compiler.exe"
|
309
|
-
|
310
|
-
|
311
|
-
|
321
|
+
introspection_compiler_args = ""
|
322
|
+
dependencies.each do |dependent_package|
|
323
|
+
gir_dir = "#{compute_base_dir.call(dependent_package)}/share/gir-1.0"
|
324
|
+
introspection_compiler_args << " --includedir=#{gir_dir}"
|
325
|
+
end
|
326
|
+
if package.windows.gobject_introspection_compiler_split_args?
|
327
|
+
common_make_args << introspection_compiler
|
328
|
+
common_make_args <<
|
329
|
+
"INTROSPECTION_COMPILER_ARGS=#{introspection_compiler_args}"
|
330
|
+
common_make_args <<
|
331
|
+
"INTROSPECTION_COMPILER_OPTS=#{introspection_compiler_args}"
|
332
|
+
else
|
333
|
+
introspection_compiler << " #{introspection_compiler_args}"
|
334
|
+
common_make_args << introspection_compiler
|
312
335
|
end
|
313
|
-
common_make_args << introspection_compiler
|
314
336
|
|
315
|
-
|
316
|
-
|
337
|
+
common_make_args << dlltool_env
|
338
|
+
|
339
|
+
data_dirs = dependencies.collect do |dependent_package|
|
340
|
+
"#{compute_base_dir.call(dependent_package)}/share"
|
317
341
|
end
|
318
342
|
common_make_args << "XDG_DATA_DIRS=#{data_dirs.join(File::PATH_SEPARATOR)}"
|
319
343
|
end
|
data/lib/mkmf-gnome2.rb
CHANGED
@@ -503,6 +503,8 @@ def package_platform
|
|
503
503
|
:redhat
|
504
504
|
elsif File.exist?("/etc/SuSE-release")
|
505
505
|
:suse
|
506
|
+
elsif File.exist?("/etc/altlinux-release")
|
507
|
+
:altlinux
|
506
508
|
elsif find_executable("pacman")
|
507
509
|
:arch
|
508
510
|
elsif find_executable("brew")
|
@@ -536,7 +538,7 @@ def install_missing_native_package(native_package_info)
|
|
536
538
|
package_command_line = [package_name, *options].join(" ")
|
537
539
|
need_super_user_priviledge = true
|
538
540
|
case platform
|
539
|
-
when :debian
|
541
|
+
when :debian, :altlinux
|
540
542
|
install_command = "apt-get install -V -y #{package_command_line}"
|
541
543
|
when :fedora, :redhat
|
542
544
|
install_command = "yum install -y #{package_command_line}"
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (C) 2015-2016 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestMatchInfo < Test::Unit::TestCase
|
18
|
+
def test_string
|
19
|
+
regex = GLib::Regex.new("[A-Z]+")
|
20
|
+
match_info = regex.match("abc def")
|
21
|
+
assert_equal("abc def", match_info.string)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_regex
|
25
|
+
regex = GLib::Regex.new("[A-Z]+")
|
26
|
+
match_info = regex.match("abc def")
|
27
|
+
assert_equal("[A-Z]+", match_info.regex.pattern)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_partial_match
|
31
|
+
flags = GLib::RegexMatchFlags::PARTIAL_SOFT
|
32
|
+
regex = GLib::Regex.new("jan")
|
33
|
+
match_info = regex.match_all("ja", :match_options => flags)
|
34
|
+
assert do
|
35
|
+
!match_info.matches?
|
36
|
+
end
|
37
|
+
assert do
|
38
|
+
match_info.partial_match?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case "fetch" do
|
43
|
+
test "Integer" do
|
44
|
+
regex = GLib::Regex.new("[A-Z]+")
|
45
|
+
match_info = regex.match_all("abc DEF ghi JKL mnop")
|
46
|
+
assert_equal("DEF", match_info.fetch(0))
|
47
|
+
assert_equal("DE", match_info.fetch(1))
|
48
|
+
end
|
49
|
+
|
50
|
+
test "String" do
|
51
|
+
regex = GLib::Regex.new("(?<a_name>fo+)")
|
52
|
+
match_info = regex.match("tatafoo")
|
53
|
+
assert_equal("foo", match_info.fetch("a_name"))
|
54
|
+
end
|
55
|
+
|
56
|
+
test "Symbol" do
|
57
|
+
regex = GLib::Regex.new("(?<a_name>fo+)")
|
58
|
+
match_info = regex.match("tatafoo")
|
59
|
+
assert_equal("foo", match_info.fetch(:a_name))
|
60
|
+
end
|
61
|
+
|
62
|
+
test "[]" do
|
63
|
+
regex = GLib::Regex.new("(?<a_name>fo+)")
|
64
|
+
match_info = regex.match("tatafoo")
|
65
|
+
assert_equal("foo", match_info[:a_name])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
sub_test_case "fetch_pos" do
|
70
|
+
test "Integer" do
|
71
|
+
regex = GLib::Regex.new("[A-Z]+")
|
72
|
+
match_info = regex.match_all("abc DEF ghi JKL mnop")
|
73
|
+
assert_equal([4, 7], match_info.fetch_pos(0))
|
74
|
+
assert_equal([4, 6], match_info.fetch_pos(1))
|
75
|
+
end
|
76
|
+
|
77
|
+
test "String" do
|
78
|
+
regex = GLib::Regex.new("(?<a_name>fo+)")
|
79
|
+
match_info = regex.match("tatafoo")
|
80
|
+
assert_equal([4, 7], match_info.fetch_pos("a_name"))
|
81
|
+
end
|
82
|
+
|
83
|
+
test "Symbol" do
|
84
|
+
regex = GLib::Regex.new("(?<a_name>fo+)")
|
85
|
+
match_info = regex.match("tatafoo")
|
86
|
+
assert_equal([4, 7], match_info.fetch_pos(:a_name))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_fetch_all
|
91
|
+
regex = GLib::Regex.new("[A-Z]+")
|
92
|
+
str = "abc DEF ghi JKL mnop"
|
93
|
+
match_info = regex.match_all(str)
|
94
|
+
assert_equal(["DEF", "DE", "D"], match_info.fetch_all)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_next
|
98
|
+
regex = GLib::Regex.new("[A-Z]+")
|
99
|
+
str = "abc DEF ghi JKL mnop"
|
100
|
+
match_info = regex.match(str)
|
101
|
+
assert_equal("DEF", match_info[0])
|
102
|
+
assert {match_info.next}
|
103
|
+
assert_equal("JKL", match_info[0])
|
104
|
+
assert {!match_info.next}
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_expand_references
|
108
|
+
regex = GLib::Regex.new("a(?P<G>.)c")
|
109
|
+
match_info = regex.match("xabcy")
|
110
|
+
expanded_string = match_info.expand_references("X\\g<G>X")
|
111
|
+
assert_equal("XbX", expanded_string)
|
112
|
+
end
|
113
|
+
end
|
data/test/test-regex.rb
ADDED
@@ -0,0 +1,320 @@
|
|
1
|
+
# Copyright (C) 2015-2016 Ruby-GNOME2 Project Team
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class TestRegex < Test::Unit::TestCase
|
18
|
+
def test_enum_match_flags
|
19
|
+
assert_const_defined(GLib, :RegexMatchFlags)
|
20
|
+
assert_kind_of(GLib::RegexMatchFlags, GLib::RegexMatchFlags::PARTIAL_HARD)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_enum_compile_flags
|
24
|
+
assert_const_defined(GLib, :RegexCompileFlags)
|
25
|
+
assert_kind_of(GLib::RegexCompileFlags, GLib::RegexCompileFlags::CASELESS)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_pattern
|
29
|
+
regex = GLib::Regex.new("to??")
|
30
|
+
assert_equal("to??", regex.pattern)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_compile_flags
|
34
|
+
flags = GLib::RegexCompileFlags::CASELESS
|
35
|
+
regex = GLib::Regex.new("to??", :compile_options => flags)
|
36
|
+
assert_equal(flags, regex.compile_flags)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_match_flags
|
40
|
+
flags = GLib::RegexMatchFlags::PARTIAL_HARD
|
41
|
+
regex = GLib::Regex.new("to??", :match_options => flags)
|
42
|
+
assert_equal(flags, regex.match_flags)
|
43
|
+
end
|
44
|
+
|
45
|
+
sub_test_case "split" do
|
46
|
+
test "no options" do
|
47
|
+
regex = GLib::Regex.new("\s")
|
48
|
+
string_to_split = "a bc"
|
49
|
+
splited_strings = regex.split(string_to_split)
|
50
|
+
assert_equal(["a", "bc"], splited_strings)
|
51
|
+
end
|
52
|
+
|
53
|
+
test "start_position" do
|
54
|
+
regex = GLib::Regex.new("\s")
|
55
|
+
string_to_split = "a bc"
|
56
|
+
splited_strings = regex.split(string_to_split, :start_position => 2)
|
57
|
+
assert_equal(["bc"], splited_strings)
|
58
|
+
end
|
59
|
+
|
60
|
+
test "max_tokens" do
|
61
|
+
regex = GLib::Regex.new("\s")
|
62
|
+
string_to_split = "a bc de fg"
|
63
|
+
splited_strings = regex.split(string_to_split, :max_tokens => 2)
|
64
|
+
assert_equal(["a", "bc de fg"], splited_strings)
|
65
|
+
end
|
66
|
+
|
67
|
+
test "match_options" do
|
68
|
+
regex = GLib::Regex.new("a?b?")
|
69
|
+
string_to_split = "toto ab"
|
70
|
+
splited_strings = regex.split(string_to_split)
|
71
|
+
assert_equal(["t", "o", "t", "o", " "],
|
72
|
+
splited_strings)
|
73
|
+
splited_strings = regex.split(string_to_split,
|
74
|
+
:match_options => :notempty)
|
75
|
+
assert_equal(["toto ", ""], splited_strings)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
sub_test_case "match" do
|
80
|
+
setup do
|
81
|
+
@regex = GLib::Regex.new("[A-Z]+")
|
82
|
+
end
|
83
|
+
|
84
|
+
test "no match no options" do
|
85
|
+
match_info = @regex.match("abc def")
|
86
|
+
assert do
|
87
|
+
not match_info.matches?
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test "matched no options" do
|
92
|
+
match_info = @regex.match("abc DEF")
|
93
|
+
assert do
|
94
|
+
match_info.matches?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test "no match and start position option" do
|
99
|
+
match_info = @regex.match("abc def", :start_position => 4)
|
100
|
+
assert do
|
101
|
+
not match_info.matches?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test "matched and start position option" do
|
106
|
+
match_info = @regex.match("abc DEF", :start_position => 4)
|
107
|
+
assert do
|
108
|
+
match_info.matches?
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
sub_test_case "max_backref" do
|
114
|
+
test "none" do
|
115
|
+
regex = GLib::Regex.new("to?o")
|
116
|
+
assert_equal(0, regex.max_backref)
|
117
|
+
end
|
118
|
+
|
119
|
+
test "one" do
|
120
|
+
regex = GLib::Regex.new("(to(?)o)\\g1")
|
121
|
+
assert_equal(1, regex.max_backref)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
sub_test_case "capture_count" do
|
126
|
+
test "none" do
|
127
|
+
regex = GLib::Regex.new("to?o")
|
128
|
+
assert_equal(0, regex.capture_count)
|
129
|
+
end
|
130
|
+
|
131
|
+
test "one" do
|
132
|
+
regex = GLib::Regex.new("(to(\?)o)")
|
133
|
+
assert_equal(1, regex.capture_count)
|
134
|
+
end
|
135
|
+
|
136
|
+
test "three" do
|
137
|
+
regex = GLib::Regex.new("((red|white) (king|queen))")
|
138
|
+
assert_equal(3, regex.capture_count)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
sub_test_case "has_cr_or_lf" do
|
143
|
+
test "none" do
|
144
|
+
regex = GLib::Regex.new("to?o")
|
145
|
+
assert do
|
146
|
+
not regex.has_cr_or_lf?
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
test "both" do
|
151
|
+
regex = GLib::Regex.new("to\no")
|
152
|
+
assert do
|
153
|
+
regex.has_cr_or_lf?
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
test "cr" do
|
158
|
+
regex = GLib::Regex.new("to\rtiti")
|
159
|
+
assert do
|
160
|
+
regex.has_cr_or_lf?
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
sub_test_case "max_lookbehind" do
|
166
|
+
test "none" do
|
167
|
+
regex = GLib::Regex.new("to?o")
|
168
|
+
assert_equal(0, regex.max_lookbehind)
|
169
|
+
end
|
170
|
+
|
171
|
+
test "three" do
|
172
|
+
regex = GLib::Regex.new("(?<!foo)bar")
|
173
|
+
assert_equal(3, regex.max_lookbehind)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
sub_test_case "string_number" do
|
178
|
+
test "none" do
|
179
|
+
regex = GLib::Regex.new("too")
|
180
|
+
assert_equal(-1, regex.string_number("a_name"))
|
181
|
+
end
|
182
|
+
|
183
|
+
test "one" do
|
184
|
+
regex = GLib::Regex.new("(?<a_name>foo)bar")
|
185
|
+
assert_equal(1, regex.string_number("a_name"))
|
186
|
+
end
|
187
|
+
|
188
|
+
test "two" do
|
189
|
+
regex = GLib::Regex.new("(?<another_name>foo)(?<a_name>bar)")
|
190
|
+
assert_equal(2, regex.string_number("a_name"))
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_regex_escape_string
|
195
|
+
assert_equal("a\\.b\\*c", GLib::Regex.escape_string("a.b*c"))
|
196
|
+
end
|
197
|
+
|
198
|
+
sub_test_case "match?" do
|
199
|
+
test "true" do
|
200
|
+
assert do
|
201
|
+
GLib::Regex.match?("to", "tatota")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
test "false" do
|
206
|
+
assert do
|
207
|
+
not GLib::Regex.match?("ti", "tatota")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
sub_test_case "match_all" do
|
213
|
+
test "no match" do
|
214
|
+
regex = GLib::Regex.new("[A-Z]+")
|
215
|
+
assert do
|
216
|
+
not regex.match_all("abc def").matches?
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
test ":start_position" do
|
221
|
+
regex = GLib::Regex.new("[A-Z]")
|
222
|
+
assert do
|
223
|
+
regex.match_all("a B c", :start_position => 2).matches?
|
224
|
+
end
|
225
|
+
assert do
|
226
|
+
not regex.match_all("a B c", :start_position => 3).matches?
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
test "match all" do
|
231
|
+
regex = GLib::Regex.new("<.*>")
|
232
|
+
assert_equal(3, regex.match_all("<a> <b> <c>").match_count)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
sub_test_case "split simple" do
|
237
|
+
test "no options" do
|
238
|
+
splited_strings = GLib::Regex.split("\s", "a bc")
|
239
|
+
assert_equal(["a", "bc"], splited_strings)
|
240
|
+
end
|
241
|
+
|
242
|
+
test "match_options" do
|
243
|
+
splited_strings = GLib::Regex.split("a?b?", "toto ab")
|
244
|
+
assert_equal(["t", "o", "t", "o", " "], splited_strings)
|
245
|
+
|
246
|
+
splited_strings = GLib::Regex.split("a?b?",
|
247
|
+
"toto ab",
|
248
|
+
:match_options => :notempty)
|
249
|
+
assert_equal(["toto ", ""], splited_strings)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
sub_test_case "replace" do
|
254
|
+
test "simple" do
|
255
|
+
regex = GLib::Regex.new("\\s")
|
256
|
+
assert_equal("a_bc", regex.replace("a bc", "_"))
|
257
|
+
end
|
258
|
+
|
259
|
+
test "back reference" do
|
260
|
+
regex = GLib::Regex.new("\\s")
|
261
|
+
assert_equal("a_ _bc", regex.replace("a bc", "_\\0_"))
|
262
|
+
end
|
263
|
+
|
264
|
+
test "literal" do
|
265
|
+
regex = GLib::Regex.new("\\s")
|
266
|
+
assert_equal("a_\\0_bc",
|
267
|
+
regex.replace("a bc",
|
268
|
+
"_\\0_",
|
269
|
+
:literal => true))
|
270
|
+
end
|
271
|
+
|
272
|
+
sub_test_case "eval" do
|
273
|
+
test "all" do
|
274
|
+
regex = GLib::Regex.new("1|2|3|4")
|
275
|
+
modified_string = regex.replace(" 4 3 2 1") do |match_info|
|
276
|
+
"to"
|
277
|
+
end
|
278
|
+
assert_equal(" to to to to", modified_string)
|
279
|
+
end
|
280
|
+
|
281
|
+
test "break" do
|
282
|
+
regex = GLib::Regex.new("1|2|3|4")
|
283
|
+
modified_string = regex.replace(" 4 3 2 1") do |match_info|
|
284
|
+
break "to"
|
285
|
+
end
|
286
|
+
assert_equal(" to 3 2 1", modified_string)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
sub_test_case "check_replacement" do
|
292
|
+
test "no references" do
|
293
|
+
assert_true(GLib::Regex.check_replacement("foo\\n"))
|
294
|
+
end
|
295
|
+
|
296
|
+
test "with references" do
|
297
|
+
assert_true(GLib::Regex.check_replacement("\\0\\1"))
|
298
|
+
end
|
299
|
+
|
300
|
+
test "invalid" do
|
301
|
+
assert_raise(GLib::Error) do
|
302
|
+
GLib::Regex.check_replacement("\\")
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
sub_test_case "have_reference?" do
|
308
|
+
test "no references" do
|
309
|
+
assert do
|
310
|
+
not GLib::Regex.have_reference?("foo\\n")
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
test "with references" do
|
315
|
+
assert do
|
316
|
+
GLib::Regex.have_reference?("\\0\\1")
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|