plain_text 0.4 → 0.5

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.
@@ -26,6 +26,7 @@ class TestUnitPlainText < MiniTest::Test
26
26
 
27
27
  class ChString < String
28
28
  # Test sub-class.
29
+ include PlainText
29
30
  end
30
31
 
31
32
  def setup
@@ -194,6 +195,12 @@ class TestUnitPlainText < MiniTest::Test
194
195
  s2 = "\n 06==\n07\n08\n\n10\n11\n12\n14\n\n16\n17\n18\n19\n\n21\n22\n\n\n"
195
196
  assert_equal s1, PT.head(s, /==/) # Up to Line 4
196
197
  assert_equal s2, PT.head_inverse(s, /==/) # From Line 5
198
+ s3 = "\n2\n\n\n\n"
199
+ exp ="\n2\n\n\n"
200
+ act = PT.head(s3, 4)
201
+ assert_equal exp, act, prerr(exp,act) # Up to Line 4 (test of String#split(s,-1))
202
+ assert_raises(ArgumentError){PT.head(s3, 0)}
203
+ assert_equal s3, PT.head(s3, 99)
197
204
  end
198
205
 
199
206
  def test_head_re03
@@ -210,6 +217,57 @@ class TestUnitPlainText < MiniTest::Test
210
217
  assert_equal s7, PT.head(s, /T/), s7.inspect+" <=> \n"+PT.head(s, /T/).inspect # Up to 11
211
218
  end
212
219
 
220
+ def test_head_re04
221
+ s = "all-matched"
222
+ # Null cases
223
+ assert_equal s, PT.head(s, /X/, inclusive: true)
224
+ assert_equal s, PT.head(s, /X/, inclusive: false)
225
+ assert_equal "", PT.head_inverse(s, /X/, inclusive: true)
226
+ assert_equal "", PT.head_inverse(s, /X/, inclusive: false)
227
+ end
228
+
229
+ # padding
230
+ def test_head_re05
231
+ s = "\n2\n3\n四\n5\n6\n7\n8\n9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19\n\n"
232
+ e = "\n2\n3\n四\n5\n6\n7\n8\n"
233
+ a = PT.head(s, /5/, inclusive: true, padding: 3)
234
+ assert_equal e, a, prerr(e,a)
235
+ e = "\n2\n"
236
+ a = PT.head(s, /5/, inclusive: true, padding: -3)
237
+ assert_equal e, a, prerr(e,a)
238
+
239
+ s = "\n2\n3\n四\n5\n6\n7\n8\n9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19\n\n"
240
+ e = "9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19\n\n"
241
+ a = PT.head_inverse(s, /5/, inclusive: true, padding: 3)
242
+ assert_equal e, a, prerr(e,a)
243
+ e = "3\n四\n5\n6\n7\n8\n9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19\n\n"
244
+ a = PT.head_inverse(s, /5/, inclusive: true, padding: -3)
245
+ assert_equal e, a, prerr(e,a)
246
+
247
+ e = "\n2\n3\n四\n5\n6\n7\n"
248
+ a = PT.head(s, /5/, inclusive: false, padding: 3)
249
+ assert_equal e, a, prerr(e,a)
250
+ e = "\n"
251
+ a = PT.head(s, /5/, inclusive: false, padding: -3)
252
+ assert_equal e, a, prerr(e,a)
253
+
254
+ a = PT.head(s, /5/, inclusive: true, padding: 20)
255
+ assert_equal s, a
256
+ a = PT.head(s, /5/, inclusive: true, padding: -9)
257
+ assert_equal "", a
258
+
259
+ # Empty (boundary)
260
+ a = PT.head(s, /2/, inclusive: false, padding: -1)
261
+ assert_equal "", a, prerr("",a)
262
+
263
+ # Without the last linebreak
264
+ s = "\n2\n3\n四\n5\n6\n7\n8\n9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19"
265
+ a = PT.head(s, /5/, inclusive: false, padding: 20)
266
+ assert_equal s, a, prerr(s,a)
267
+ a = PT.head(s, /19/, inclusive: true)
268
+ assert_equal s, a, prerr(s,a)
269
+ end
270
+
213
271
  def test_tail01
214
272
  assert_equal "", PT.tail("")
215
273
  assert_equal 'abc', PT.tail("abc")
@@ -274,10 +332,61 @@ class TestUnitPlainText < MiniTest::Test
274
332
  assert_equal s, PT.tail(s, /a/), prerr(s, PT.tail(s, /a/), long: nil)
275
333
  assert_equal s, PT.tail(s, /a/), prerr(s, PT.tail(s, /a/))
276
334
  assert_equal s, PT.tail(s, /b/), prerr(s, PT.tail(s, /b/))
277
- assert_equal "def", PT.tail(s, /a/, inclusive: false)
335
+ act = PT.tail(s, /a/, inclusive: false)
336
+ assert_equal "def", act, prerr('def', act)
278
337
  assert_equal "def", PT.tail(s, /b/, inclusive: false), prerr('"def"', PT.tail(s, /b/, inclusive: false))
279
338
  end
280
339
 
340
+ def test_tail_re04
341
+ s = "abc\ndef"
342
+ # Null cases
343
+ assert_equal "", PT.tail(s, /X/, inclusive: true)
344
+ assert_equal "", PT.tail(s, /X/, inclusive: false)
345
+ assert_equal s, PT.tail_inverse(s, /X/, inclusive: true)
346
+ assert_equal s, PT.tail_inverse(s, /X/, inclusive: false)
347
+
348
+ s = "A. has\nB. adds\n\n\n___Sample\n\n NextLine\n"
349
+ assert_equal s, PT.tail_inverse(s, /no_match/)
350
+ assert_equal "", PT.tail( s, /no_match/)
351
+
352
+ # Without the last linebreak
353
+ s = "\n2\n3\n四\n5\n6\n7\n8\n9\n10\n11\n\n13\n14\n15\n16\n\n壱8\n19"
354
+ e = "19"
355
+ a = PT.tail(s, 1, inclusive: true)
356
+ assert_equal e, a, prerr(e,a)
357
+ a = PT.tail(s, 1, inclusive: false) # "inclusive" ignored
358
+ assert_equal e, a, prerr(e,a)
359
+ #a = PT.tail(s, /5/, inclusive: false, padding: 20)
360
+ #assert_equal s, a, prerr(s,a)
361
+ a = PT.tail(s, /19/, inclusive: true)
362
+ assert_equal e, a, prerr(e,a)
363
+ a = PT.tail(s, /19/, inclusive: false)
364
+ assert_equal "", a, prerr("",a)
365
+ a = PT.tail(s, /19/, inclusive: true, padding: 22)
366
+ assert_equal s, a, prerr(s,a)
367
+ e = "15\n16\n\n壱8\n19"
368
+ a = PT.tail(s, /16/, inclusive: false, padding: 2)
369
+ assert_equal e, a, prerr(e,a)
370
+ e = "壱8\n19"
371
+ a = PT.tail(s, /16/, inclusive: true, padding: -2)
372
+ assert_equal e, a, prerr(e,a)
373
+
374
+ end
375
+
376
+ def test_pre_match_in_line01
377
+ # s = ["A. has\nB. adds\n\nC\n___", "Sample", "\nE\n NextLine\n"]
378
+ s = ChString.new ""
379
+ s0 = ChString.new "1\n2\n__abc"
380
+ s1 = ChString.new "1\n2\n"
381
+ s2 = ChString.new "__Abc"
382
+ assert_equal "__abc", s.send(:pre_match_in_line, s0)[0]
383
+ assert_equal "", s.send(:pre_match_in_line, s1)[0]
384
+ assert_equal "__Abc", s.send(:pre_match_in_line, s2)[0]
385
+ assert_equal "1\n2\n", s.send(:pre_match_in_line, s0).pre_match
386
+ assert_equal "1\n2\n", s.send(:pre_match_in_line, s1).pre_match
387
+ assert_equal "", s.send(:pre_match_in_line, s2).pre_match
388
+ end
389
+
281
390
  # @param *rest [Object] Parameters to print. Expected first, Actual second.
282
391
  # @param long: [Boolena] If true, linefeed is inserted (Better for String comparison).
283
392
  # @return [String] Error message when failed.
@@ -331,6 +331,86 @@ class TestUnitPlainTextPart < MiniTest::Test
331
331
  assert_raises(ArgumentError){ pt1.slice!(1..2) } # Odd starting index.
332
332
  end
333
333
 
334
+ # merge paragraphs
335
+ def test_merge_para
336
+ s1 = "a\n\nb\n\nc\n\nd\n\ne\n\n"
337
+ # 0 1 2 3 4 5 6 7 8 9
338
+ pt1 = Pt.parse s1
339
+ assert_equal 10, pt1.size
340
+ assert_equal 5, pt1.parts.size
341
+ assert_equal "b\n\n", pt1[2..3].join
342
+
343
+ pt2 = pt1.dup
344
+ pt2.merge_para!(2,3,4)
345
+ assert_equal s1, pt2.join
346
+ assert_equal 8, pt2.size
347
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
348
+
349
+ pt2 = pt1.dup
350
+ pt2.merge_para!(2,3,4, 5)
351
+ assert_equal s1, pt2.join
352
+ assert_equal 8, pt2.size
353
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
354
+
355
+ pt2 = pt1.dup
356
+ pt2.merge_para!(2..4)
357
+ assert_equal s1, pt2.join
358
+ assert_equal 8, pt2.size
359
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
360
+
361
+ pt2 = pt1.dup
362
+ pt2.merge_para!(2..5)
363
+ assert_equal s1, pt2.join
364
+ assert_equal 8, pt2.size
365
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
366
+
367
+ pt2 = pt1.dup
368
+ pt2.merge_para!(2...6)
369
+ assert_equal s1, pt2.join
370
+ assert_equal 8, pt2.size
371
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
372
+
373
+ pt2 = pt1.dup
374
+ pt2.merge_para!(2...-4)
375
+ assert_equal s1, pt2.join
376
+ assert_equal 8, pt2.size
377
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
378
+
379
+ pt2 = pt1.dup
380
+ pt2.merge_para!(1..2, use_para_index: true)
381
+ assert_equal s1, pt2.join
382
+ assert_equal 8, pt2.size
383
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
384
+
385
+ pt2 = pt1.dup
386
+ pt2.merge_para!(8..12)
387
+ assert_equal s1, pt2.join
388
+ assert_equal 10, pt2.size
389
+ assert_equal pt1, pt2
390
+ end
391
+
392
+ def test_merge_para_if
393
+ s1 = "a\n\nb\n\nc\n\nd\n\ne\n\n"
394
+ # 0 1 2 3 4 5 6 7 8 9
395
+ pt1 = Pt.parse s1
396
+
397
+ pt2 = pt1.dup
398
+ assert pt2.merge_para_if{|ary,bi,bf|
399
+ ary[0] == ?b && ary[2] == ?c
400
+ }
401
+ assert_equal s1, pt2.join
402
+ assert_equal 8, pt2.size
403
+ assert_equal "b\n\nc\n\n", pt2[2..3].join
404
+
405
+ # Multiple
406
+ pt2 = pt1.dup
407
+ assert pt2.merge_para_if{|ary,bi,bf|
408
+ (ary[0] == ?a && ary[2] == ?b) || (ary[0] == ?d && ary[2] == ?e)
409
+ }
410
+ assert_equal s1, pt2.join
411
+ assert_equal 6, pt2.size
412
+ assert_equal ["a\n\nb", "\n\n", "c", "\n\n", "d\n\ne", "\n\n"], pt2.to_a
413
+ end
334
414
 
335
415
  # Tests of Part.parse
336
416
  def test_parse01
@@ -74,5 +74,34 @@ class TestUnitPlainTextSplit < MiniTest::Test
74
74
  assert_equal ["", "XY", "ab", "XX", "c", "XY"], s.split_with_delimiter(/X+(Y?)/)
75
75
  end
76
76
 
77
+ def test_count_regexp01
78
+ s1 = "XabXXc"
79
+ s2 = "XabXXcX"
80
+ s3 = "XXabX+XcX"
81
+ assert_equal 2, PTS.count_regexp(s1, /X+Y?/)
82
+ assert_equal 2, s1.count_regexp(/X+Y?/)
83
+ assert_equal 3, s1.count_regexp(/X+Y?/, like_linenum: true)
84
+ assert_equal [2, false], s1.count_regexp(/X+Y?/, with_if_end: true)
85
+ assert_equal [2, false], s1.count_regexp(/X+Y?/, with_if_end: true, like_linenum: false)
86
+ assert_equal 3, s2.count_regexp(/X+Y?/)
87
+ assert_equal 3, s2.count_regexp(/X+Y?/, like_linenum: true)
88
+ assert_equal [3, true], s2.count_regexp(/X+Y?/, with_if_end: true)
89
+ assert_equal 0, s2.count_regexp('X+')
90
+ assert_equal 1, s3.count_regexp('X+')
91
+ assert_equal 2, s3.count_regexp('X+', like_linenum: true)
92
+ assert_equal [0, true], ''.count_regexp(/X+Y?/, with_if_end: true)
93
+ end
94
+
95
+ def test_count_lines01
96
+ s1 = "\nab\n\nc"
97
+ s2 = "\nab\n\nc\n"
98
+ s3 = "\r\n\nab\r\n+\r\n\r\n"
99
+ assert_equal 4, PTS.count_lines(s1)
100
+ assert_equal 4, s1.count_lines
101
+ assert_equal 4, s2.count_lines
102
+ assert_equal 0, ''.count_lines
103
+ assert_equal 4, s3.count_lines(linebreak: "\r\n")
104
+ end
105
+
77
106
  end # class TestUnitPlainTextSplit < MiniTest::Test
78
107
 
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # Author: M. Sakano (Wise Babel Ltd)
4
+
5
+ require 'plain_text/util'
6
+
7
+ $stdout.sync=true
8
+ $stderr.sync=true
9
+ # print '$LOAD_PATH=';p $LOAD_PATH
10
+
11
+ #################################################
12
+ # Unit Test
13
+ #################################################
14
+
15
+ #if $0 == __FILE__
16
+ gem "minitest"
17
+ # require 'minitest/unit'
18
+ require 'minitest/autorun'
19
+ # MiniTest::Unit.autorun
20
+
21
+ class TestUnitPlainTextUtil < MiniTest::Test
22
+ T = true
23
+ F = false
24
+ SCFNAME = File.basename(__FILE__)
25
+ include PlainText::Util
26
+
27
+ def setup
28
+ end
29
+
30
+ def teardown
31
+ end
32
+
33
+ def test_arind2ranges
34
+ assert_equal [(1..3), (6..7), (9..9)], arind2ranges([1,2,3,6,7,9])
35
+ end
36
+ end
data/test/testhead_rb.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Tests of an executable.
4
4
  #
5
- # @author: M. Sakano (Wise Babel Ltd)
5
+ # @author M. Sakano (Wise Babel Ltd)
6
6
 
7
7
  require 'open3'
8
8
 
@@ -30,10 +30,10 @@ class TestUnitHeadRb < MiniTest::Test
30
30
  def teardown
31
31
  end
32
32
 
33
- def test_countchar01
33
+ def test_head01
34
34
  o, e, s = Open3.capture3 EXE
35
35
  assert_equal 0, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
36
- assert_equal "\n", o
36
+ assert_equal "", o
37
37
  assert_empty e
38
38
 
39
39
  stin = "1\n2\n3\n4\n5\n6\n7\n8\n9\nA\nB\n"
@@ -42,7 +42,7 @@ class TestUnitHeadRb < MiniTest::Test
42
42
  assert_equal stin[0..19], o
43
43
  assert_empty e
44
44
 
45
- o, e, s = Open3.capture3 EXE+' -i', stdin_data: stin
45
+ o, e, s = Open3.capture3 EXE+' -r', stdin_data: stin
46
46
  assert_equal 0, s.exitstatus
47
47
  assert_equal stin[20..-1], o, "Wrong! STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
48
48
  assert_empty e
@@ -65,6 +65,61 @@ class TestUnitHeadRb < MiniTest::Test
65
65
  assert_equal 0, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
66
66
  assert_equal stin[0..7], o, "Wrong! STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
67
67
  assert_empty e
68
+
69
+ o, e, s = Open3.capture3 EXE+' -e "no_match" -r', stdin_data: stin
70
+ assert_equal 0, s.exitstatus
71
+ assert_equal '', o, prerr('', o)
72
+ assert_empty e
73
+ end
74
+
75
+ def test_head02
76
+ stin = "A\nB\nC\nD\ne\nf\ng\nH\nI\nJ\nK\n"
77
+
78
+ o, e, s = Open3.capture3 EXE+' -e "c"', stdin_data: stin
79
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
80
+ assert_empty e, prerr('',e)
81
+ assert_equal stin, o, prerr(s,o)
82
+
83
+ o, e, s = Open3.capture3 EXE+' -e "c" -i', stdin_data: stin
84
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
85
+ assert_empty e, prerr('',e)
86
+ exp = "A\nB\nC\n"
87
+ assert_equal exp, o, prerr(exp,o)
88
+
89
+ o, e, s = Open3.capture3 EXE+' -e "c.*D" -i', stdin_data: stin
90
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
91
+ assert_empty e, prerr('',e)
92
+ assert_equal stin, o, prerr(exp,o)
93
+
94
+ o, e, s = Open3.capture3 EXE+' -e "c.*D" -i -m', stdin_data: stin
95
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
96
+ assert_empty e, prerr('',e)
97
+ exp = "A\nB\nC\nD\n"
98
+ assert_equal exp, o, prerr(exp,o)
99
+
100
+ o, e, s = Open3.capture3 EXE+' -e "c" -p -1', stdin_data: stin
101
+ exp = "A\nB\n"
102
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
103
+ assert_empty e, prerr('',e)
104
+ assert_equal stin, o, prerr(s,o)
105
+
106
+ end
107
+
108
+ def comerr(o, e, s)
109
+ 'コマンドエラー(status=%s): STDOUT=%s STDERR=%s'%[s.exitstatus, o.inspect, (e.empty? ? '""' : ":\n"+e)]
110
+ end
111
+
112
+ # Default error-printing routine, so they are compared easily.
113
+ # This is especially useful when the expected/actual object contains
114
+ # linefeed or space characters, as they are not very visible
115
+ # hence comparable in the minitest default output.
116
+ #
117
+ # @param expected [Object] Expected object.
118
+ # @param actual [Object] Actual object your code has returned.
119
+ # @param long: [Boolena] If true, linefeed is inserted (Better for String comparison).
120
+ # @return [String] Error message when failed.
121
+ def prerr(expected, actual, long: true)
122
+ '[期待] '+[expected, actual].map(&:inspect).join(" ⇔ "+(long ? "\n" : "")+'[実際] ')
68
123
  end
69
124
  end # class TestUnitHeadRb < MiniTest::Test
70
125
 
data/test/testtail_rb.rb CHANGED
@@ -30,41 +30,91 @@ class TestUnitTailRb < MiniTest::Test
30
30
  def teardown
31
31
  end
32
32
 
33
- def test_countchar01
33
+ def test_tail01
34
34
  o, e, s = Open3.capture3 EXE
35
35
  assert_equal 0, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
36
- assert_equal "\n", o
37
36
  assert_empty e
37
+ assert_equal "", o
38
38
 
39
39
  stin = "1\n2\n3\n4\n5\n6\n7\n8\n9\nA\nB\n"
40
40
  o, e, s = Open3.capture3 EXE, stdin_data: stin
41
+ assert_empty e, prerr(stin[2..-1], e)
41
42
  assert_equal 0, s.exitstatus
42
- assert_equal stin[2..-1], o
43
- assert_empty e
43
+ assert_equal stin[2..-1], o, prerr(stin[2..-1], o)
44
44
 
45
- o, e, s = Open3.capture3 EXE+' -i', stdin_data: stin
45
+ o, e, s = Open3.capture3 EXE+' -r', stdin_data: stin
46
+ assert_empty e
46
47
  assert_equal 0, s.exitstatus
47
48
  assert_equal stin[0..1], o, "Wrong! STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
48
- assert_empty e
49
49
 
50
50
  o, e, s = Open3.capture3 EXE+' -n 10', stdin_data: stin
51
+ assert_empty e
51
52
  assert_equal 0, s.exitstatus
52
53
  assert_equal stin[2..-1], o
53
- assert_empty e
54
54
 
55
55
  o, e, s = Open3.capture3 EXE+' -b', stdin_data: stin
56
56
  assert_equal 1, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
57
57
  assert_match(/missing/i, e)
58
58
 
59
59
  o, e, s = Open3.capture3 EXE+' -e "[5-9]"', stdin_data: stin
60
+ assert_empty e
60
61
  assert_equal 0, s.exitstatus
61
62
  assert_equal stin[-6..-1], o, "Wrong! STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
62
- assert_empty e
63
63
 
64
64
  o, e, s = Open3.capture3 EXE+' -e "[5-9]" -x', stdin_data: stin
65
+ assert_empty e
65
66
  assert_equal 0, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
66
67
  assert_equal stin[-4..-1], o, "Wrong! STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
68
+
69
+ o, e, s = Open3.capture3 EXE+' -e "no_match"', stdin_data: stin
67
70
  assert_empty e
71
+ assert_equal 0, s.exitstatus
72
+ assert_equal '', o, prerr('', o)
73
+
74
+ end
75
+
76
+ def test_tail02
77
+ stin = "A\nB\nC\nD\ne\nf\ng\nH\nI\nJ\nK\n"
78
+
79
+ o, e, s = Open3.capture3 EXE+' -e "i"', stdin_data: stin
80
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
81
+ assert_empty e, prerr('',e)
82
+ assert_equal "", o, prerr("",o)
83
+
84
+ o, e, s = Open3.capture3 EXE+' -e "i" -i', stdin_data: stin
85
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
86
+ assert_empty e, prerr('',e)
87
+ exp = "I\nJ\nK\n"
88
+ assert_equal exp, o, prerr(exp,o)
89
+
90
+ o, e, s = Open3.capture3 EXE+' -e "i.*J" -i -m', stdin_data: stin
91
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
92
+ assert_empty e, prerr('',e)
93
+ exp = "I\nJ\nK\n"
94
+ assert_equal exp, o, prerr(exp,o)
95
+
96
+ o, e, s = Open3.capture3 EXE+' -e "i.*J" -i', stdin_data: stin
97
+ assert_equal 0, s.exitstatus, comerr(o, e, s)
98
+ assert_empty e, prerr('',e)
99
+ assert_equal "", o, prerr("",o)
100
+
101
+ end
102
+
103
+ def comerr(o, e, s)
104
+ 'コマンドエラー(status=%s): STDOUT=%s STDERR=%s'%[s.exitstatus, o.inspect, (e.empty? ? '""' : ":\n"+e)]
105
+ end
106
+
107
+ # Default error-printing routine, so they are compared easily.
108
+ # This is especially useful when the expected/actual object contains
109
+ # linefeed or space characters, as they are not very visible
110
+ # hence comparable in the minitest default output.
111
+ #
112
+ # @param expected [Object] Expected object.
113
+ # @param actual [Object] Actual object your code has returned.
114
+ # @param long: [Boolena] If true, linefeed is inserted (Better for String comparison).
115
+ # @return [String] Error message when failed.
116
+ def prerr(expected, actual, long: true)
117
+ '[期待] '+[expected, actual].map(&:inspect).join(" ⇔ "+(long ? "\n" : "")+'[実際] ')
68
118
  end
69
119
  end # class TestUnitTailRb < MiniTest::Test
70
120
 
@@ -0,0 +1,71 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # Tests of an executable.
4
+ #
5
+ # @author: M. Sakano (Wise Babel Ltd)
6
+
7
+ require 'open3'
8
+
9
+ $stdout.sync=true
10
+ $stderr.sync=true
11
+ # print '$LOAD_PATH=';p $LOAD_PATH
12
+
13
+ #################################################
14
+ # Unit Test
15
+ #################################################
16
+
17
+ gem "minitest"
18
+ # require 'minitest/unit'
19
+ require 'minitest/autorun'
20
+
21
+ class TestUnitYard2mdRb < MiniTest::Test
22
+ T = true
23
+ F = false
24
+ SCFNAME = File.basename(__FILE__)
25
+ EXE = "%s/../bin/%s" % [File.dirname(__FILE__), File.basename(__FILE__).sub(/^test_?(.+)\.rb/, '\1').sub(/_rb$/, '.rb')]
26
+
27
+ def setup
28
+ end
29
+
30
+ def teardown
31
+ end
32
+
33
+ def test_basics01
34
+
35
+ o, e, s = Open3.capture3 EXE
36
+ assert_equal 0, s.exitstatus, "error is raised: STDOUT="+o.inspect+" STDERR="+(e.empty? ? '""' : ":\n"+e)
37
+ assert_equal "\n", o
38
+ assert_empty e
39
+
40
+ stin = " +abc def+ \n\n efg\n"
41
+ o, e, s = Open3.capture3 EXE, stdin_data: stin
42
+ assert_equal 0, s.exitstatus
43
+ exp = " `abc def` \n\n efg\n"
44
+ assert_equal exp, o, "期待:#{exp.inspect} ⇔ \n実際:#{o.inspect}"
45
+ assert_empty e
46
+
47
+ stin = " +abc\ndef+ \n\n efg\n"
48
+ o, e, s = Open3.capture3 EXE, stdin_data: stin
49
+ assert_equal 0, s.exitstatus
50
+ exp = " `abc def` \n\n efg\n"
51
+ assert_equal exp, o, "期待:#{exp.inspect} ⇔ \n実際:#{o.inspect}"
52
+ assert_empty e
53
+
54
+ stin = " [abc\ndef](http://xy\n .h\n tml) \n\n efg\n"
55
+ o, e, s = Open3.capture3 EXE, stdin_data: stin
56
+ assert_equal 0, s.exitstatus
57
+ exp = " [abc def](http://xy.html) \n\n efg\n"
58
+ assert_equal exp, o, "期待:#{exp.inspect} ⇔ \n実際:#{o.inspect}"
59
+ assert_empty e
60
+
61
+ stin = " +abc def+ " + "\n\n\n efg\n"
62
+ srub = "```ruby\n"
63
+ exp = srub+"+abc def+ \n```\n\n\n efg\n"
64
+ o, e, s = Open3.capture3 EXE, stdin_data: stin
65
+ assert_equal 0, s.exitstatus
66
+ assert_equal exp, o, "期待:#{exp.inspect} ⇔ \n実際:#{o.inspect}"
67
+ assert_empty e
68
+
69
+ end
70
+ end
71
+
metadata CHANGED
@@ -1,25 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plain_text
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masa Sakano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This module provides utility functions and methods to handle plain text,
14
14
  classes Part/Paragraph/Boundary to represent the logical structure of a document
15
15
  and ParseRule to describe the rules to parse plain text to produce a Part-type Ruby
16
- instance.
16
+ instance. A few handy Ruby executable scripts to make use of them are included.
17
17
  email:
18
18
  executables:
19
19
  - countchar
20
20
  - textclean
21
21
  - head.rb
22
22
  - tail.rb
23
+ - yard2md_afterclean
23
24
  extensions: []
24
25
  extra_rdoc_files:
25
26
  - README.en.rdoc
@@ -34,6 +35,7 @@ files:
34
35
  - bin/head.rb
35
36
  - bin/tail.rb
36
37
  - bin/textclean
38
+ - bin/yard2md_afterclean
37
39
  - lib/plain_text.rb
38
40
  - lib/plain_text/parse_rule.rb
39
41
  - lib/plain_text/part.rb
@@ -46,15 +48,19 @@ files:
46
48
  - test/test_plain_text_parse_rule.rb
47
49
  - test/test_plain_text_part.rb
48
50
  - test/test_plain_text_split.rb
51
+ - test/test_plain_text_util.rb
49
52
  - test/testcountchar.rb
50
53
  - test/testhead_rb.rb
51
54
  - test/testtail_rb.rb
52
55
  - test/testtextclean.rb
56
+ - test/testyard2md_afterclean.rb
53
57
  homepage: https://www.wisebabel.com
54
58
  licenses:
55
59
  - MIT
56
60
  metadata:
57
61
  yard.run: yri
62
+ changelog_uri: https://github.com/masasakano/plain_text/blob/master/ChangeLog
63
+ source_code_uri: https://github.com/masasakano/plain_text
58
64
  post_install_message:
59
65
  rdoc_options:
60
66
  - "--charset=UTF-8"
@@ -80,7 +86,9 @@ test_files:
80
86
  - test/testtail_rb.rb
81
87
  - test/test_plain_text_part.rb
82
88
  - test/test_plain_text.rb
89
+ - test/testyard2md_afterclean.rb
83
90
  - test/testcountchar.rb
84
91
  - test/testtextclean.rb
85
92
  - test/test_plain_text_split.rb
93
+ - test/test_plain_text_util.rb
86
94
  - test/testhead_rb.rb