tefil 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +10 -1
- data/VERSION +1 -1
- data/bin/columnform +1 -0
- data/bin/linesplit +48 -0
- data/example/linesplit/run.sh +6 -0
- data/example/linesplit/sample1.txt +1 -0
- data/example/linesplit/sample2.txt +2 -0
- data/example/linesplit/sample3.txt +2 -0
- data/example/linesplit/sample4.txt +5 -0
- data/lib/tefil.rb +1 -2
- data/lib/tefil/columnformer.rb +5 -0
- data/lib/tefil/fswikitomd.rb +11 -1
- data/lib/tefil/linesplitter.rb +50 -0
- data/lib/tefil/mdtofswiki.rb +5 -5
- data/lib/tefil/textfilterbase.rb +9 -0
- data/tefil.gemspec +12 -11
- data/test/test_columnformer.rb +20 -3
- data/test/test_fswikitomd.rb +130 -80
- data/test/test_linesplitter.rb +129 -0
- data/test/test_mdtofswiki.rb +55 -30
- data/test/test_textfilterbase.rb +11 -3
- metadata +11 -11
- data/bin/eachsentence +0 -24
- data/bin/statistics +0 -24
- data/example/eachsentence/sample.txt +0 -14
- data/lib/tefil/eachsentence.rb +0 -35
- data/lib/tefil/statistics.rb +0 -38
- data/test/test_eachsentence.rb +0 -123
- data/test/test_statistics.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b17ca385c9007e407470b7bc20a352f1e218a46f
|
4
|
+
data.tar.gz: 61dc4ec8abad83dc9e306a60347a383b99c90628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca0479bb7601d8f976bed6e8db4aaa9722c22721a8e8cdde0d53f177d5d26b48f8609dd95c9f845316359eb6d0aadc436777b33aa1770a009dc85317f4f8fd55
|
7
|
+
data.tar.gz: b8544dd354cf217ebcead34b7db977184dd0e24329cce552dd02c1df4aaa0a5ef1ab36b926860b2823f79b9804b30ee936e0d1dc6cefcd7a9b7a4071f0ecee29
|
data/CHANGES
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
= tefil changelog
|
2
2
|
|
3
|
-
==
|
3
|
+
== Version 0.1.5 [2018-05-11] released
|
4
|
+
|
5
|
+
* bin/fswiki2md: add new line after header
|
6
|
+
* bugfix for new line at the end of the stream
|
7
|
+
* Enable to use not String in the matrix for Tefil::ColumnFormer#form
|
8
|
+
* bugfix for bin/md2fswiki
|
9
|
+
* delete bin/statistics # move to gem 'malge'
|
10
|
+
* catch broken pipe and do nothing
|
11
|
+
* bin/columnform: add --transpose option
|
12
|
+
* rename: bin/eachsentence to bin/linesplit with adding some functions
|
4
13
|
|
5
14
|
== Version 0.1.4 [2017-05-31] released
|
6
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/bin/columnform
CHANGED
@@ -19,6 +19,7 @@ op.on("-o" , "--overwrite" , "Overwrite"){ OPTIONS[:overwrite] = true
|
|
19
19
|
op.on("-s char", "--separator=char", "Indicate separator"){|val| OPTIONS[:separator] = val}
|
20
20
|
op.on("-l" , "--left-just" , "Left justified (Default)" ){ OPTIONS[:just] = :left}
|
21
21
|
op.on("-r" , "--right-just" , "Right justified"){ OPTIONS[:just] = :right}
|
22
|
+
op.on("-t" , "--transpose" , "Transpose matrix"){ OPTIONS[:transpose] = true}
|
22
23
|
op.parse!(ARGV)
|
23
24
|
|
24
25
|
## default settings
|
data/bin/linesplit
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
# split a line to lines.
|
5
|
+
|
6
|
+
require "pp"
|
7
|
+
require "optparse"
|
8
|
+
require "rubygems"
|
9
|
+
require "tefil"
|
10
|
+
|
11
|
+
|
12
|
+
# option analysis
|
13
|
+
options = {
|
14
|
+
#:period => true,
|
15
|
+
:separator => ".",
|
16
|
+
:except => ""
|
17
|
+
}
|
18
|
+
op = OptionParser.new
|
19
|
+
#op.banner = [
|
20
|
+
# "Usage: #{File.basename("#{__FILE__}")} [options] [files]",
|
21
|
+
#].join("\n")
|
22
|
+
op.on("-o" , "--overwrite" , "Overwrite."){ options[:overwrite] = true}
|
23
|
+
op.on("-t str" , "--separator=str" , "Target strings. Default value is '.'"){ |v| options[:separator] = v}
|
24
|
+
op.on("-e str" , "--except=str" , "Except strings."){ |v| options[:except] = v}
|
25
|
+
op.on("-s" , "--space" , "Add space to separators."){ options[:space] = true}
|
26
|
+
op.on("-S" , "--strip" , "Strip extra space at head and tail of line."){ options[:strip] = true}
|
27
|
+
op.parse!(ARGV)
|
28
|
+
|
29
|
+
options[:overwrite] ||= false
|
30
|
+
|
31
|
+
#EXCEPT_WORDS = ["Fig.", "FIG."]
|
32
|
+
|
33
|
+
separators = []
|
34
|
+
separators += options[:separator].split(" ")
|
35
|
+
separators << ' ' if options[:space]
|
36
|
+
separators.uniq!
|
37
|
+
|
38
|
+
indent_mode = :no
|
39
|
+
indent_mode = :strip if options[:strip]
|
40
|
+
|
41
|
+
#pp separators; exit
|
42
|
+
|
43
|
+
is = Tefil::LineSplitter.new(separators: separators,
|
44
|
+
except_words: options[:except].split(" "),
|
45
|
+
indent_mode: indent_mode,
|
46
|
+
options: options)
|
47
|
+
#pp is; exit
|
48
|
+
is.filter(ARGV)
|
@@ -0,0 +1 @@
|
|
1
|
+
A bad workman always blames his tools. Once a beggar, always a beggar.
|
data/lib/tefil.rb
CHANGED
@@ -11,11 +11,10 @@ require 'tefil/columnformer'
|
|
11
11
|
require 'tefil/columnanalyzer'
|
12
12
|
require 'tefil/indentconverter'
|
13
13
|
require 'tefil/indentstatistics'
|
14
|
-
require 'tefil/statistics'
|
15
14
|
require 'tefil/linesubstituter'
|
16
15
|
require 'tefil/percentpacker'
|
17
16
|
require 'tefil/zshescaper'
|
18
|
-
require 'tefil/
|
17
|
+
require 'tefil/linesplitter.rb'
|
19
18
|
require 'tefil/fswikitomd.rb'
|
20
19
|
require 'tefil/mdtofswiki.rb'
|
21
20
|
|
data/lib/tefil/columnformer.rb
CHANGED
@@ -29,12 +29,16 @@ class Tefil::ColumnFormer < Tefil::TextFilterBase
|
|
29
29
|
def initialize(options = {})
|
30
30
|
@just = options[:just] || :left
|
31
31
|
@separator = options[:separator] || ' '
|
32
|
+
@transpose = options[:transpose]
|
32
33
|
super(options)
|
33
34
|
end
|
34
35
|
|
35
36
|
#def form(matrix, io = $stdout, separator = " ", left = false)
|
36
37
|
def form(matrix, io = $stdout, indent = 0)
|
37
38
|
#Obtain max length for each column.
|
39
|
+
|
40
|
+
matrix = matrix.transpose if @transpose
|
41
|
+
|
38
42
|
max_lengths = []
|
39
43
|
matrix.each do |row|
|
40
44
|
row.each_with_index do |item, index|
|
@@ -49,6 +53,7 @@ class Tefil::ColumnFormer < Tefil::TextFilterBase
|
|
49
53
|
matrix.each do |row|
|
50
54
|
new_items = []
|
51
55
|
row.each_with_index do |item, index|
|
56
|
+
item = item.to_s
|
52
57
|
method = (@just.to_s + "_just").to_sym
|
53
58
|
new_items[index] = item.send(method, max_lengths[index])
|
54
59
|
end
|
data/lib/tefil/fswikitomd.rb
CHANGED
@@ -57,7 +57,17 @@ class Tefil::FswikiToMd < Tefil::TextFilterBase
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# 出力
|
60
|
-
out_io.
|
60
|
+
out_io.print line
|
61
|
+
|
62
|
+
#p "test"
|
63
|
+
## 空行処理
|
64
|
+
case
|
65
|
+
when type == :head1 then out_io.puts
|
66
|
+
when type == :head2 then out_io.puts
|
67
|
+
when type == :head3 then out_io.puts
|
68
|
+
else # type == :pain then 'do nothing'
|
69
|
+
end
|
70
|
+
|
61
71
|
end
|
62
72
|
end
|
63
73
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class Tefil::LineSplitter < Tefil::TextFilterBase
|
3
|
+
|
4
|
+
def initialize(separators: , indent_mode: :no, except_words: [], options: {})
|
5
|
+
options[:smart_filename] = true
|
6
|
+
@minimum = options[:minimum]
|
7
|
+
@separators = separators
|
8
|
+
@except_words = except_words
|
9
|
+
@indent_mode = indent_mode
|
10
|
+
super(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def process_stream(in_io, out_io)
|
14
|
+
results = []
|
15
|
+
|
16
|
+
# prepare substitute info to get back to original for except rule.
|
17
|
+
sub_except_words = Marshal.load(Marshal.dump(@except_words))
|
18
|
+
@separators.each do |str|
|
19
|
+
sub_except_words.map do |word|
|
20
|
+
word.gsub!(str, str + "\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
in_io.read.split("\n").each do |line|
|
25
|
+
#if @indent_mode == :indent
|
26
|
+
# /^( *)/ =~ line
|
27
|
+
# head_spaces = $1
|
28
|
+
#end
|
29
|
+
@separators.each do |str|
|
30
|
+
line.gsub!(str, str + "\n")
|
31
|
+
end
|
32
|
+
@except_words.each_with_index do |word, index|
|
33
|
+
line.gsub!(sub_except_words[index], word)
|
34
|
+
end
|
35
|
+
# 行の頭と末尾の空白 strip
|
36
|
+
if @indent_mode == :strip
|
37
|
+
line.gsub!(/\n */, "\n")
|
38
|
+
line.strip!
|
39
|
+
line.gsub!(/ */, " ")
|
40
|
+
end
|
41
|
+
#if @indent_mode == :indent
|
42
|
+
# results << head_spaces + line
|
43
|
+
#end
|
44
|
+
results << line
|
45
|
+
end
|
46
|
+
out_io.puts results.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
data/lib/tefil/mdtofswiki.rb
CHANGED
@@ -18,10 +18,10 @@ class Tefil::MdToFswiki < Tefil::TextFilterBase
|
|
18
18
|
when line.sub!(/^ \*/ , '') then type = :item3
|
19
19
|
when line.sub!(/^ \*/ , '') then type = :item2
|
20
20
|
when line.sub!(/^\*/ , '') then type = :item1
|
21
|
-
when line.sub!(/^ \d
|
22
|
-
when line.sub!(/^ \d
|
23
|
-
when line.sub!(/^ \d
|
24
|
-
when line.sub!(/^\d
|
21
|
+
when line.sub!(/^ \d+\./, '') then type = :enum4
|
22
|
+
when line.sub!(/^ \d+\./ , '') then type = :enum3
|
23
|
+
when line.sub!(/^ \d+\./ , '') then type = :enum2
|
24
|
+
when line.sub!(/^\d+\./ , '') then type = :enum1
|
25
25
|
when line.sub!(/^ / , '') then type = :pre
|
26
26
|
when line.sub!(/^---/ , '') then type = :hline
|
27
27
|
else type = :plain
|
@@ -54,7 +54,7 @@ class Tefil::MdToFswiki < Tefil::TextFilterBase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# 出力
|
57
|
-
out_io.
|
57
|
+
out_io.print line
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/lib/tefil/textfilterbase.rb
CHANGED
@@ -71,6 +71,7 @@ class Tefil::TextFilterBase
|
|
71
71
|
rescue ArgumentError, Errno::EISDIR
|
72
72
|
$stderr.puts $!
|
73
73
|
next
|
74
|
+
rescue Errno::EPIPE
|
74
75
|
end
|
75
76
|
|
76
77
|
if @overwrite
|
@@ -105,5 +106,13 @@ class Tefil::TextFilterBase
|
|
105
106
|
raise NotRedefinedMethodError
|
106
107
|
end
|
107
108
|
|
109
|
+
def process_string(in_str)
|
110
|
+
in_io = StringIO.open in_str
|
111
|
+
out_io = StringIO.new
|
112
|
+
process_stream(in_io, out_io)
|
113
|
+
out_io.rewind
|
114
|
+
out_io.read
|
115
|
+
end
|
116
|
+
|
108
117
|
end
|
109
118
|
|
data/tefil.gemspec
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: tefil 0.1.
|
5
|
+
# stub: tefil 0.1.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "tefil"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["ippei94da"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2018-05-11"
|
15
15
|
s.description = "This gem provides a framework of text filter.\n Tefil eneable to make text filter commands which have overwrite option easily.\n "
|
16
16
|
s.email = "ippei94da@gmail.com"
|
17
|
-
s.executables = ["calc", "columnanalyze", "columnform", "
|
17
|
+
s.executables = ["calc", "columnanalyze", "columnform", "fswiki2md", "indentconv", "indentstat", "linesplit", "linesub", "md2fswiki", "percentpack", "zshescape"]
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
"LICENSE.txt",
|
20
20
|
"README.rdoc"
|
@@ -30,14 +30,13 @@ Gem::Specification.new do |s|
|
|
30
30
|
"bin/calc",
|
31
31
|
"bin/columnanalyze",
|
32
32
|
"bin/columnform",
|
33
|
-
"bin/eachsentence",
|
34
33
|
"bin/fswiki2md",
|
35
34
|
"bin/indentconv",
|
36
35
|
"bin/indentstat",
|
36
|
+
"bin/linesplit",
|
37
37
|
"bin/linesub",
|
38
38
|
"bin/md2fswiki",
|
39
39
|
"bin/percentpack",
|
40
|
-
"bin/statistics",
|
41
40
|
"bin/zshescape",
|
42
41
|
"doc/memo.txt",
|
43
42
|
"example/calc/run.zsh",
|
@@ -46,26 +45,29 @@ Gem::Specification.new do |s|
|
|
46
45
|
"example/columnanalyze/run.zsh",
|
47
46
|
"example/columnformer/indent.txt",
|
48
47
|
"example/columnformer/sample.txt",
|
49
|
-
"example/eachsentence/sample.txt",
|
50
48
|
"example/indentconv/sample0.txt",
|
51
49
|
"example/indentconv/sample1.txt",
|
52
50
|
"example/indentstat/indent4.txt",
|
53
51
|
"example/indentstat/sample0.txt",
|
54
52
|
"example/indentstat/sample1.txt",
|
53
|
+
"example/linesplit/run.sh",
|
54
|
+
"example/linesplit/sample1.txt",
|
55
|
+
"example/linesplit/sample2.txt",
|
56
|
+
"example/linesplit/sample3.txt",
|
57
|
+
"example/linesplit/sample4.txt",
|
55
58
|
"example/percentpack/sample.txt",
|
56
59
|
"example/zshescape/sample.txt",
|
57
60
|
"lib/tefil.rb",
|
58
61
|
"lib/tefil/calculator.rb",
|
59
62
|
"lib/tefil/columnanalyzer.rb",
|
60
63
|
"lib/tefil/columnformer.rb",
|
61
|
-
"lib/tefil/eachsentence.rb",
|
62
64
|
"lib/tefil/fswikitomd.rb",
|
63
65
|
"lib/tefil/indentconverter.rb",
|
64
66
|
"lib/tefil/indentstatistics.rb",
|
67
|
+
"lib/tefil/linesplitter.rb",
|
65
68
|
"lib/tefil/linesubstituter.rb",
|
66
69
|
"lib/tefil/mdtofswiki.rb",
|
67
70
|
"lib/tefil/percentpacker.rb",
|
68
|
-
"lib/tefil/statistics.rb",
|
69
71
|
"lib/tefil/textfilterbase.rb",
|
70
72
|
"lib/tefil/zshescaper.rb",
|
71
73
|
"tefil.gemspec",
|
@@ -76,14 +78,13 @@ Gem::Specification.new do |s|
|
|
76
78
|
"test/test_calculator.rb",
|
77
79
|
"test/test_columnanalyzer.rb",
|
78
80
|
"test/test_columnformer.rb",
|
79
|
-
"test/test_eachsentence.rb",
|
80
81
|
"test/test_fswikitomd.rb",
|
81
82
|
"test/test_indentconverter.rb",
|
82
83
|
"test/test_indentstatistics.rb",
|
84
|
+
"test/test_linesplitter.rb",
|
83
85
|
"test/test_linesubstituter.rb",
|
84
86
|
"test/test_mdtofswiki.rb",
|
85
87
|
"test/test_percentpacker.rb",
|
86
|
-
"test/test_statistics.rb",
|
87
88
|
"test/test_textfilterbase.rb",
|
88
89
|
"test/test_zshescaper.rb"
|
89
90
|
]
|
data/test/test_columnformer.rb
CHANGED
@@ -15,6 +15,7 @@ class TC_ColumnFormer < Test::Unit::TestCase
|
|
15
15
|
@cf00 = Tefil::ColumnFormer.new
|
16
16
|
@cf01 = Tefil::ColumnFormer.new({:just => :right})
|
17
17
|
@cf02 = Tefil::ColumnFormer.new({:separator => ','})
|
18
|
+
@cf03 = Tefil::ColumnFormer.new({:transpose => true})
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_print_size
|
@@ -38,7 +39,6 @@ class TC_ColumnFormer < Test::Unit::TestCase
|
|
38
39
|
io.rewind
|
39
40
|
assert_equal(" a ab\n abc a\n", io.read)
|
40
41
|
|
41
|
-
|
42
42
|
io = StringIO.new
|
43
43
|
@cf01.form(matrix, io)
|
44
44
|
io.rewind
|
@@ -60,8 +60,25 @@ class TC_ColumnFormer < Test::Unit::TestCase
|
|
60
60
|
io.rewind
|
61
61
|
assert_equal("abc def\nあいう えおか\n", io.read)
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
##### not string
|
64
|
+
io = StringIO.new
|
65
|
+
matrix = [
|
66
|
+
[0, 1],
|
67
|
+
[2, 3],
|
68
|
+
]
|
69
|
+
@cf00.form(matrix, io)
|
70
|
+
io.rewind
|
71
|
+
assert_equal("0 1\n2 3\n", io.read)
|
72
|
+
|
73
|
+
#### transpose
|
74
|
+
io = StringIO.new
|
75
|
+
matrix = [
|
76
|
+
[0, 1],
|
77
|
+
[2, 3],
|
78
|
+
]
|
79
|
+
@cf03.form(matrix, io)
|
80
|
+
io.rewind
|
81
|
+
assert_equal("0 2\n1 3\n", io.read)
|
65
82
|
end
|
66
83
|
end
|
67
84
|
|
data/test/test_fswikitomd.rb
CHANGED
@@ -5,7 +5,8 @@ require "helper"
|
|
5
5
|
require "stringio"
|
6
6
|
|
7
7
|
class Tefil::FswikiToMd
|
8
|
-
public :process_stream
|
8
|
+
public :process_stream,
|
9
|
+
:process_string
|
9
10
|
end
|
10
11
|
|
11
12
|
class TC_FswikiToMd < Test::Unit::TestCase
|
@@ -13,91 +14,140 @@ class TC_FswikiToMd < Test::Unit::TestCase
|
|
13
14
|
@f00 = Tefil::FswikiToMd.new()
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
["! head3" , "### head3" ],
|
21
|
-
["abc ''italic'' def" , "abc *italic* def" ],
|
22
|
-
["abc '''bold''' def" , "abc **bold** def" ],
|
23
|
-
#["abc ==strike== def" , ],
|
24
|
-
#["abc __underline__ def" , ],
|
25
|
-
#['"" quotation' , ],
|
26
|
-
["* item" , "* item" ],
|
27
|
-
["** item" , " * item" ],
|
28
|
-
["*** item" , " * item" ],
|
29
|
-
["**** item" , " * item" ],
|
30
|
-
["+ enum" , "1. enum" ],
|
31
|
-
["++ enum" , " 1. enum" ],
|
32
|
-
["+++ enum" , " 1. enum" ],
|
33
|
-
["++++ enum" , " 1. enum" ],
|
34
|
-
#["*http://www.yahoo.co.jp/" , ],
|
35
|
-
["[Google|http://www.google.co.jp/]" , "[Google](http://www.google.co.jp/)" ],
|
36
|
-
[" formatted text" , " formatted text" ],
|
37
|
-
["----" , "---" ],
|
38
|
-
["// comment" , "<!-- comment-->" ],
|
39
|
-
].each do |i|
|
40
|
-
$stdin = StringIO.new
|
41
|
-
$stdin.puts i[0]
|
42
|
-
$stdin.rewind
|
43
|
-
#str = capture_stdout{}
|
44
|
-
result = capture_stdout{ @f00.filter([])}
|
45
|
-
correct = sprintf("#{i[1]}\n")
|
46
|
-
assert_equal(correct, result)
|
47
|
-
end
|
17
|
+
def test_process_string
|
18
|
+
assert_equal("# head1\n\n", @f00.process_string("!!! head1\n"))
|
19
|
+
assert_equal("# head2\n\n", @f00.process_string("!!! head2\n"))
|
20
|
+
assert_equal("# head3\n\n", @f00.process_string("!!! head3\n"))
|
48
21
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
# "## head2",
|
78
|
-
# "### head3",
|
79
|
-
# "abc *italic* def",
|
80
|
-
# "abc **bold** def",
|
81
|
-
# "* item",
|
82
|
-
# " * item",
|
83
|
-
# " * item",
|
84
|
-
# " * item",
|
85
|
-
# "0. enum",
|
86
|
-
# " 0. enum",
|
87
|
-
# " 0. enum",
|
88
|
-
# " 0. enum",
|
89
|
-
# "[Google](http://www.google.co.jp/)",
|
90
|
-
# " formatted text",
|
91
|
-
# "---",
|
92
|
-
# ""
|
93
|
-
#].join("\n")
|
94
|
-
#assert_equal(correct, result)
|
22
|
+
assert_equal("abc *italic* def",
|
23
|
+
@f00.process_string("abc ''italic'' def"))
|
24
|
+
assert_equal("abc **bold** def",
|
25
|
+
@f00.process_string("abc '''bold''' def"))
|
26
|
+
assert_equal( "* item",
|
27
|
+
@f00.process_string("* item"))
|
28
|
+
assert_equal(" * item",
|
29
|
+
@f00.process_string("** item"))
|
30
|
+
assert_equal(" * item",
|
31
|
+
@f00.process_string("*** item"))
|
32
|
+
assert_equal(" * item",
|
33
|
+
@f00.process_string("**** item"))
|
34
|
+
assert_equal("1. enum",
|
35
|
+
@f00.process_string("+ enum"))
|
36
|
+
assert_equal(" 1. enum",
|
37
|
+
@f00.process_string("++ enum"))
|
38
|
+
assert_equal(" 1. enum",
|
39
|
+
@f00.process_string("+++ enum"))
|
40
|
+
assert_equal(" 1. enum",
|
41
|
+
@f00.process_string("++++ enum"))
|
42
|
+
assert_equal("[Google](http://www.google.co.jp/)",
|
43
|
+
@f00.process_string("[Google|http://www.google.co.jp/]" ))
|
44
|
+
assert_equal(" formatted text",
|
45
|
+
@f00.process_string(" formatted text"))
|
46
|
+
assert_equal("---",
|
47
|
+
@f00.process_string("----"))
|
48
|
+
assert_equal("<!-- comment-->",
|
49
|
+
@f00.process_string("// comment"))
|
95
50
|
end
|
96
|
-
end
|
97
51
|
|
52
|
+
def test_process_stream
|
53
|
+
input = <<HERE
|
54
|
+
!!! head1
|
55
|
+
!! head2
|
56
|
+
! head3
|
57
|
+
abc ''italic'' def
|
58
|
+
abc '''bold''' def
|
59
|
+
* item
|
60
|
+
** item
|
61
|
+
*** item
|
62
|
+
**** item
|
63
|
+
+ enum
|
64
|
+
++ enum
|
65
|
+
+++ enum
|
66
|
+
++++ enum
|
67
|
+
[Google|http://www.google.co.jp/]" ,
|
68
|
+
formatted text"
|
69
|
+
----"
|
70
|
+
// comment"
|
71
|
+
HERE
|
72
|
+
|
73
|
+
#abc ==strike== def
|
74
|
+
#abc __underline__ def
|
75
|
+
#"" quotation'
|
76
|
+
#*http://www.yahoo.co.jp/"
|
98
77
|
|
78
|
+
# correct = <<HERE
|
79
|
+
## head1
|
80
|
+
#
|
81
|
+
## head1
|
82
|
+
#
|
83
|
+
### head2
|
84
|
+
#
|
85
|
+
#### head3
|
86
|
+
#
|
87
|
+
#abc *italic* def
|
88
|
+
#abc **bold** def
|
89
|
+
#
|
90
|
+
#* item
|
91
|
+
# * item
|
92
|
+
# * item
|
93
|
+
# * item
|
94
|
+
#1. enum
|
95
|
+
# 1. enum
|
96
|
+
# 1. enum
|
97
|
+
# 1. enum
|
98
|
+
#
|
99
|
+
#[Google](http://www.google.co.jp/)
|
100
|
+
# formatted text
|
101
|
+
#---
|
102
|
+
#<!-- comment-->
|
103
|
+
#HERE
|
104
|
+
#
|
105
|
+
#
|
106
|
+
# in_io = StringIO.new
|
107
|
+
# in_io.puts input
|
108
|
+
# in_io.rewind
|
109
|
+
# out_io = StringIO.new
|
110
|
+
# @f00.process_stream(in_io, out_io)
|
111
|
+
# out_io.rewind
|
112
|
+
# result = out_io.read
|
113
|
+
#
|
114
|
+
# assert_equal(correct, result)
|
115
|
+
#end
|
99
116
|
|
117
|
+
#[
|
118
|
+
# ["!!! head1" , "# head1" ],
|
119
|
+
# ["!! head2" , "## head2" ],
|
120
|
+
# ["! head3" , "### head3" ],
|
121
|
+
# ["abc ''italic'' def" , "abc *italic* def" ],
|
122
|
+
# ["abc '''bold''' def" , "abc **bold** def" ],
|
123
|
+
# #["abc ==strike== def" , ],
|
124
|
+
# #["abc __underline__ def" , ],
|
125
|
+
# #['"" quotation' , ],
|
126
|
+
# ["* item" , "* item" ],
|
127
|
+
# ["** item" , " * item" ],
|
128
|
+
# ["*** item" , " * item" ],
|
129
|
+
# ["**** item" , " * item" ],
|
130
|
+
# ["+ enum" , "1. enum" ],
|
131
|
+
# ["++ enum" , " 1. enum" ],
|
132
|
+
# ["+++ enum" , " 1. enum" ],
|
133
|
+
# ["++++ enum" , " 1. enum" ],
|
134
|
+
# #["*http://www.yahoo.co.jp/" , ],
|
135
|
+
# ["[Google|http://www.google.co.jp/]" , "[Google](http://www.google.co.jp/)" ],
|
136
|
+
# [" formatted text" , " formatted text" ],
|
137
|
+
# ["----" , "---" ],
|
138
|
+
# ["// comment" , "<!-- comment-->" ],
|
139
|
+
#].each do |i|
|
140
|
+
# $stdin = StringIO.new
|
141
|
+
# $stdin.puts i[0]
|
142
|
+
# $stdin.rewind
|
143
|
+
# #str = capture_stdout{}
|
144
|
+
# result = capture_stdout{ @f00.filter([])}
|
145
|
+
# correct = sprintf("#{i[1]}\n")
|
146
|
+
# assert_equal(correct, result)
|
147
|
+
#end
|
100
148
|
|
101
149
|
|
102
150
|
|
103
151
|
|
152
|
+
end
|
153
|
+
end
|