chupa-text-decomposer-abiword 1.0.0
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 +7 -0
- data/.yardopts +5 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +502 -0
- data/README.md +38 -0
- data/Rakefile +48 -0
- data/chupa-text-decomposer-abiword.gemspec +50 -0
- data/doc/text/news.md +5 -0
- data/lib/chupa-text/decomposers/abiword.rb +132 -0
- data/test/fixture/abw/multi-pages.abw +43 -0
- data/test/fixture/abw/one-page.abw +41 -0
- data/test/fixture/doc/multi-pages.doc +0 -0
- data/test/fixture/doc/one-page.doc +0 -0
- data/test/fixture/docx/multi-pages.docx +0 -0
- data/test/fixture/docx/one-page.docx +0 -0
- data/test/fixture/odt/multi-pages.odt +0 -0
- data/test/fixture/odt/one-page.odt +0 -0
- data/test/fixture/rtf/multi-pages.rtf +19 -0
- data/test/fixture/rtf/one-page.rtf +17 -0
- data/test/fixture/zabw/multi-pages.zabw +0 -0
- data/test/fixture/zabw/one-page.zabw +0 -0
- data/test/helper.rb +57 -0
- data/test/run-test.rb +31 -0
- data/test/test-abw.rb +84 -0
- data/test/test-doc.rb +84 -0
- data/test/test-docx.rb +84 -0
- data/test/test-odt.rb +84 -0
- data/test/test-rtf.rb +84 -0
- data/test/test-zabw.rb +71 -0
- metadata +176 -0
data/test/run-test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
$VERBOSE = true
|
20
|
+
|
21
|
+
require "bundler/setup"
|
22
|
+
|
23
|
+
require "test-unit"
|
24
|
+
|
25
|
+
require "chupa-text"
|
26
|
+
|
27
|
+
ChupaText::Decomposers.load
|
28
|
+
|
29
|
+
require_relative "helper"
|
30
|
+
|
31
|
+
exit(Test::Unit::AutoRunner.run(true))
|
data/test/test-abw.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
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 TestAbw < Test::Unit::TestCase
|
18
|
+
include FixtureHelper
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@decomposer = ChupaText::Decomposers::AbiWord.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(*components)
|
25
|
+
super("abw", *components)
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case("target?") do
|
29
|
+
sub_test_case("extension") do
|
30
|
+
def create_data(uri)
|
31
|
+
data = ChupaText::Data.new
|
32
|
+
data.body = ""
|
33
|
+
data.uri = uri
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc
|
38
|
+
assert_true(@decomposer.target?(create_data("document.abw")))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case("mime-type") do
|
43
|
+
def create_data(mime_type)
|
44
|
+
data = ChupaText::Data.new
|
45
|
+
data.mime_type = mime_type
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_abiword
|
50
|
+
mime_type = "application/x-abiword"
|
51
|
+
assert_true(@decomposer.target?(create_data(mime_type)))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("decompose") do
|
57
|
+
include DecomposeHelper
|
58
|
+
|
59
|
+
sub_test_case("one page") do
|
60
|
+
def test_body
|
61
|
+
assert_equal(["Page1\n"], decompose.collect(&:body))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def decompose
|
66
|
+
super(fixture_path("one-page.abw"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sub_test_case("multi pages") do
|
71
|
+
def test_body
|
72
|
+
assert_equal([<<-BODY], decompose.collect(&:body))
|
73
|
+
Page1
|
74
|
+
Page2
|
75
|
+
BODY
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def decompose
|
80
|
+
super(fixture_path("multi-pages.abw"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/test-doc.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
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 TestDoc < Test::Unit::TestCase
|
18
|
+
include FixtureHelper
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@decomposer = ChupaText::Decomposers::AbiWord.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(*components)
|
25
|
+
super("doc", *components)
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case("target?") do
|
29
|
+
sub_test_case("extension") do
|
30
|
+
def create_data(uri)
|
31
|
+
data = ChupaText::Data.new
|
32
|
+
data.body = ""
|
33
|
+
data.uri = uri
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc
|
38
|
+
assert_true(@decomposer.target?(create_data("document.doc")))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case("mime-type") do
|
43
|
+
def create_data(mime_type)
|
44
|
+
data = ChupaText::Data.new
|
45
|
+
data.mime_type = mime_type
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_ms_word
|
50
|
+
mime_type = "application/msword"
|
51
|
+
assert_true(@decomposer.target?(create_data(mime_type)))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("decompose") do
|
57
|
+
include DecomposeHelper
|
58
|
+
|
59
|
+
sub_test_case("one page") do
|
60
|
+
def test_body
|
61
|
+
assert_equal(["Page1\n"], decompose.collect(&:body))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def decompose
|
66
|
+
super(fixture_path("one-page.doc"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sub_test_case("multi pages") do
|
71
|
+
def test_body
|
72
|
+
assert_equal([<<-BODY], decompose.collect(&:body))
|
73
|
+
Page1
|
74
|
+
Page2
|
75
|
+
BODY
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def decompose
|
80
|
+
super(fixture_path("multi-pages.doc"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/test-docx.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
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 TestDocx < Test::Unit::TestCase
|
18
|
+
include FixtureHelper
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@decomposer = ChupaText::Decomposers::AbiWord.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(*components)
|
25
|
+
super("docx", *components)
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case("target?") do
|
29
|
+
sub_test_case("extension") do
|
30
|
+
def create_data(uri)
|
31
|
+
data = ChupaText::Data.new
|
32
|
+
data.body = ""
|
33
|
+
data.uri = uri
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc
|
38
|
+
assert_true(@decomposer.target?(create_data("document.docx")))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case("mime-type") do
|
43
|
+
def create_data(mime_type)
|
44
|
+
data = ChupaText::Data.new
|
45
|
+
data.mime_type = mime_type
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_openxml_document
|
50
|
+
mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
51
|
+
assert_true(@decomposer.target?(create_data(mime_type)))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("decompose") do
|
57
|
+
include DecomposeHelper
|
58
|
+
|
59
|
+
sub_test_case("one page") do
|
60
|
+
def test_body
|
61
|
+
assert_equal(["Page1\n"], decompose.collect(&:body))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def decompose
|
66
|
+
super(fixture_path("one-page.docx"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sub_test_case("multi pages") do
|
71
|
+
def test_body
|
72
|
+
assert_equal([<<-BODY], decompose.collect(&:body))
|
73
|
+
Page1
|
74
|
+
Page2
|
75
|
+
BODY
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def decompose
|
80
|
+
super(fixture_path("multi-pages.docx"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/test-odt.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
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 TestOdt < Test::Unit::TestCase
|
18
|
+
include FixtureHelper
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@decomposer = ChupaText::Decomposers::AbiWord.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(*components)
|
25
|
+
super("odt", *components)
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case("target?") do
|
29
|
+
sub_test_case("extension") do
|
30
|
+
def create_data(uri)
|
31
|
+
data = ChupaText::Data.new
|
32
|
+
data.body = ""
|
33
|
+
data.uri = uri
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc
|
38
|
+
assert_true(@decomposer.target?(create_data("document.odt")))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case("mime-type") do
|
43
|
+
def create_data(mime_type)
|
44
|
+
data = ChupaText::Data.new
|
45
|
+
data.mime_type = mime_type
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_opendocument_text
|
50
|
+
mime_type = "application/vnd.oasis.opendocument.text"
|
51
|
+
assert_true(@decomposer.target?(create_data(mime_type)))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("decompose") do
|
57
|
+
include DecomposeHelper
|
58
|
+
|
59
|
+
sub_test_case("one page") do
|
60
|
+
def test_body
|
61
|
+
assert_equal(["Page1\n"], decompose.collect(&:body))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def decompose
|
66
|
+
super(fixture_path("one-page.odt"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sub_test_case("multi pages") do
|
71
|
+
def test_body
|
72
|
+
assert_equal([<<-BODY], decompose.collect(&:body))
|
73
|
+
Page1
|
74
|
+
Page2
|
75
|
+
BODY
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def decompose
|
80
|
+
super(fixture_path("multi-pages.odt"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/test-rtf.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
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 TestRtf < Test::Unit::TestCase
|
18
|
+
include FixtureHelper
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@decomposer = ChupaText::Decomposers::AbiWord.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(*components)
|
25
|
+
super("rtf", *components)
|
26
|
+
end
|
27
|
+
|
28
|
+
sub_test_case("target?") do
|
29
|
+
sub_test_case("extension") do
|
30
|
+
def create_data(uri)
|
31
|
+
data = ChupaText::Data.new
|
32
|
+
data.body = ""
|
33
|
+
data.uri = uri
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doc
|
38
|
+
assert_true(@decomposer.target?(create_data("document.rtf")))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sub_test_case("mime-type") do
|
43
|
+
def create_data(mime_type)
|
44
|
+
data = ChupaText::Data.new
|
45
|
+
data.mime_type = mime_type
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_rich_text_format
|
50
|
+
mime_type = "application/rtf"
|
51
|
+
assert_true(@decomposer.target?(create_data(mime_type)))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
sub_test_case("decompose") do
|
57
|
+
include DecomposeHelper
|
58
|
+
|
59
|
+
sub_test_case("one page") do
|
60
|
+
def test_body
|
61
|
+
assert_equal(["Page1\n"], decompose.collect(&:body))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def decompose
|
66
|
+
super(fixture_path("one-page.rtf"))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sub_test_case("multi pages") do
|
71
|
+
def test_body
|
72
|
+
assert_equal([<<-BODY], decompose.collect(&:body))
|
73
|
+
Page1
|
74
|
+
Page2
|
75
|
+
BODY
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def decompose
|
80
|
+
super(fixture_path("multi-pages.rtf"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|