regextest 0.1.5 → 0.1.6
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/lib/pre/unicode.rb +5 -0
- data/lib/regextest.rb +7 -3
- data/lib/regextest/back/element.rb +36 -13
- data/lib/regextest/back/main.rb +116 -65
- data/lib/regextest/back/result.rb +19 -8
- data/lib/regextest/common.rb +4 -1
- data/lib/regextest/front.rb +5 -0
- data/lib/regextest/front/back-refer.rb +2 -2
- data/lib/regextest/front/bracket-parser.rb +121 -103
- data/lib/regextest/front/bracket-parser.y +4 -1
- data/lib/regextest/front/bracket-scanner.rb +4 -3
- data/lib/regextest/front/char-class.rb +13 -5
- data/lib/regextest/front/letter.rb +39 -6
- data/lib/regextest/front/parenthesis.rb +2 -2
- data/lib/regextest/front/parser.rb +564 -545
- data/lib/regextest/front/parser.y +8 -3
- data/lib/regextest/front/range.rb +19 -1
- data/lib/regextest/front/scanner.rb +16 -13
- data/lib/regextest/front/special-letter.rb +63 -0
- data/lib/regextest/regex-option.rb +27 -0
- data/lib/regextest/unicode.rb +5 -0
- data/lib/regextest/version.rb +1 -1
- data/lib/tst-reg-test.rb +66 -21
- metadata +3 -2
@@ -62,6 +62,7 @@ rule
|
|
62
62
|
| LEX_NAMED_REFER {BackRefer.new(:LEX_NAMED_REFER, val[0])}
|
63
63
|
| LEX_NAMED_GENERATE {BackRefer.new(:LEX_NAMED_GENERATE, val[0])}
|
64
64
|
| LEX_CONTROL_LETTER {TLetter.new(:LEX_CONTROL_LETTER, val[0])}
|
65
|
+
| LEX_META_CONTROL_LETTER {TLetter.new(:LEX_META_CONTROL_LETTER, val[0])}
|
65
66
|
| LEX_META_LETTER {TLetter.new(:LEX_CONTROL_LETTER, val[0])}
|
66
67
|
| LEX_ESCAPED_LETTER {TLetter.new(:LEX_ESCAPED_LETTER, val[0])}
|
67
68
|
| LEX_UNICODE {TLetter.new(:LEX_UNICODE, val[0])}
|
@@ -77,7 +78,7 @@ rule
|
|
77
78
|
| LEX_ANC_STRING_END2 {Anchor.new(:LEX_ANC_STRING_END2, val[0])}
|
78
79
|
| LEX_ANC_LOOK_BEHIND2 {Anchor.new(:LEX_ANC_LOOK_BEHIND2, val[0])}
|
79
80
|
| LEX_ANC_MATCH_START {Anchor.new(:LEX_ANC_MATCH_START, val[0])}
|
80
|
-
| LEX_SPECIAL_LETTER {
|
81
|
+
| LEX_SPECIAL_LETTER {SpecialLetter.new(val[0])}
|
81
82
|
| LEX_MINUS {TLetter.new(:LEX_CHAR, val[0])} # no special meaning at basic mode
|
82
83
|
| LEX_AND_AND {TLetter.new(:LEX_AND_AND, val[0])}
|
83
84
|
| LEX_SPACE {TLetter.new(:LEX_SPACE, val[0])}
|
@@ -156,7 +157,7 @@ rule
|
|
156
157
|
| LEX_ANC_STRING_END2 {Anchor.new(:LEX_ANC_STRING_END2, val[0])}
|
157
158
|
| LEX_ANC_LOOK_BEHIND2 {Anchor.new(:LEX_ANC_LOOK_BEHIND2, val[0])}
|
158
159
|
| LEX_ANC_MATCH_START {Anchor.new(:LEX_ANC_MATCH_START, val[0])}
|
159
|
-
| LEX_SPECIAL_LETTER {
|
160
|
+
| LEX_SPECIAL_LETTER {SpecialLetter.new(val[0])}
|
160
161
|
| LEX_MINUS {TLetter.new(:LEX_CHAR, val[0])}
|
161
162
|
| LEX_AND_AND {TLetter.new(:LEX_AND_AND, val[0])}
|
162
163
|
| LEX_NEW_LINE {TEmpty.new} # ignore new line at extended mode
|
@@ -166,10 +167,12 @@ rule
|
|
166
167
|
| LEX_SHARP reg_comment_ex {TEmpty.new}
|
167
168
|
|
168
169
|
# comment of extended mode
|
169
|
-
reg_comment_ex:
|
170
|
+
reg_comment_ex:
|
171
|
+
| LEX_NEW_LINE # end of the comment
|
170
172
|
| LEX_CHAR reg_comment_ex
|
171
173
|
| LEX_OCTET reg_comment_ex
|
172
174
|
| LEX_BACK_REFER reg_comment_ex
|
175
|
+
| LEX_SPECIAL_LETTER reg_comment_ex
|
173
176
|
| LEX_CODE_LITERAL reg_comment_ex
|
174
177
|
| LEX_NAMED_REFER reg_comment_ex
|
175
178
|
| LEX_NAMED_GENERATE reg_comment_ex
|
@@ -217,6 +220,7 @@ require 'regextest/front/sequence' # parser class for a sequence of elemen
|
|
217
220
|
require 'regextest/front/bracket' # parser class for a character class (bracket)
|
218
221
|
require 'regextest/front/anchor' # parser class for a anchor
|
219
222
|
require 'regextest/front/back-refer' # parser class for a back reference
|
223
|
+
require 'regextest/front/special-letter' # parser class for a special letter
|
220
224
|
require 'regextest/front/bracket-parser' # bracket parser
|
221
225
|
|
222
226
|
---- inner
|
@@ -231,6 +235,7 @@ include Regextest::Front::Sequence
|
|
231
235
|
include Regextest::Front::Bracket
|
232
236
|
include Regextest::Front::Anchor
|
233
237
|
include Regextest::Front::BackRefer
|
238
|
+
include Regextest::Front::SpecialLetter
|
234
239
|
|
235
240
|
# execute to parse
|
236
241
|
def parse(lex_words, options)
|
@@ -14,6 +14,7 @@ module Regextest::Front::Range
|
|
14
14
|
# Constructor
|
15
15
|
def initialize(letter_begin, letter_end = nil)
|
16
16
|
TstLog("TRange: #{letter_begin}-#{letter_end}")
|
17
|
+
@options = nil
|
17
18
|
@begin = parse_letter(letter_begin)
|
18
19
|
if letter_end
|
19
20
|
@end = parse_letter(letter_end)
|
@@ -46,10 +47,27 @@ module Regextest::Front::Range
|
|
46
47
|
(@begin..@end).to_a
|
47
48
|
end
|
48
49
|
|
50
|
+
# set options
|
51
|
+
def set_options(options)
|
52
|
+
TstLog("Range set_options: #{options[:reg_options].inspect}")
|
53
|
+
@options = options
|
54
|
+
end
|
55
|
+
|
49
56
|
# transform to json format (using codepoints of Unicode)
|
50
57
|
def json
|
51
58
|
@@id += 1
|
52
|
-
|
59
|
+
if @options
|
60
|
+
charset = @options[:reg_options].charset
|
61
|
+
else
|
62
|
+
charset = "d"
|
63
|
+
end
|
64
|
+
"{" +
|
65
|
+
"\"type\": \"LEX_RANGE\", " +
|
66
|
+
"\"id\": \"G#{@@id}\", " +
|
67
|
+
"\"begin\": #{@begin}, " +
|
68
|
+
"\"end\": #{@end}, " +
|
69
|
+
"\"charset\": \"#{charset}\"" +
|
70
|
+
"}"
|
53
71
|
end
|
54
72
|
end
|
55
73
|
end
|
@@ -20,13 +20,15 @@ class Regextest::Front::Scanner
|
|
20
20
|
[:LEX_CODE_LITERAL,
|
21
21
|
LexCodeLiteral ],
|
22
22
|
[:LEX_NAMED_REFER,
|
23
|
-
%r
|
23
|
+
%r!(?u:\\k[<'](?:\-?\d+|\w+)(?:[\+\-]\d+)?[>'])! ],
|
24
24
|
[:LEX_NAMED_GENERATE,
|
25
|
-
%r
|
25
|
+
%r!(?u:\\g[<'][\+\-]?\w+[>'])! ],
|
26
26
|
[:LEX_CONTROL_LETTER,
|
27
|
-
%r!\\c[
|
27
|
+
%r!\\c\\\\|\\C-\\\\|\\c[0-~]|\\C-[0-~]! ],
|
28
|
+
[:LEX_META_CONTROL_LETTER,
|
29
|
+
%r!\\M-\\C-[0-~]! ],
|
28
30
|
[:LEX_META_LETTER,
|
29
|
-
%r!\\M-
|
31
|
+
%r!\\M-[0-~]! ],
|
30
32
|
[:LEX_ESCAPED_LETTER,
|
31
33
|
%r!\\[tvnrfae #\{\}\[\]\(\)]! ], # \b is an anchor out of bracket
|
32
34
|
[:LEX_UNICODE,
|
@@ -50,15 +52,16 @@ class Regextest::Front::Scanner
|
|
50
52
|
[:LEX_PAREN_START_EX2,
|
51
53
|
%r!\(\?[imxdau]*(?:\-(?=\w*x)[imx]+)?(?::|(?=\)))! ], # (?im-x: ... )
|
52
54
|
[:LEX_PAREN_START,
|
53
|
-
%r
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
%r!(?u:\(\?<\w+>|
|
56
|
+
\(\?'\w+'|
|
57
|
+
\(\?\(\d+\)|
|
58
|
+
\(\?\(<\w+>\)|
|
59
|
+
\(\?\('\w+'\)|
|
60
|
+
\(\?[imdau]*(?:\-[im]*)?(?::|(?=\)))| # expressions independent of "x"
|
61
|
+
\(\?\<[\=\!]|
|
62
|
+
\(\?.| # for better error message
|
63
|
+
\(
|
64
|
+
)
|
62
65
|
!x ],
|
63
66
|
[:LEX_PAREN_END,
|
64
67
|
%r!\)! ],
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Copyright (C) 2016 Mikio Ikoma
|
4
|
+
|
5
|
+
require 'regextest/common'
|
6
|
+
require 'regextest/front'
|
7
|
+
|
8
|
+
# Parse special letter element (\R / \X etc.)
|
9
|
+
module Regextest::Front::SpecialLetter
|
10
|
+
class SpecialLetter
|
11
|
+
include Regextest::Common
|
12
|
+
@@id = 0 # a class variable for generating unique name of element
|
13
|
+
|
14
|
+
# Constructor
|
15
|
+
def initialize(value)
|
16
|
+
TstLog("SpecialLetter: #{value}")
|
17
|
+
@value = value[0]
|
18
|
+
@offset = value[1]
|
19
|
+
@length = value[2]
|
20
|
+
@options = @@parse_options
|
21
|
+
@string = nil
|
22
|
+
@obj = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :offset, :length
|
26
|
+
|
27
|
+
# set string
|
28
|
+
def set_string(options)
|
29
|
+
reg_options = options[:reg_options]
|
30
|
+
case @value
|
31
|
+
when "\\R"
|
32
|
+
if reg_options.is_unicode?
|
33
|
+
'(?:\x0d\x0a|[\x0a-\x0c\u{85}\u{2028}\u{2029}]|\x0d(?!\x0a))'
|
34
|
+
else
|
35
|
+
'(?:\x0d\x0a|\x0d(?!\x0a)|[\x0a-\x0c])'
|
36
|
+
end
|
37
|
+
when "\\X"
|
38
|
+
# Unicode mode is not implemented yet
|
39
|
+
'(?m:.)'
|
40
|
+
else
|
41
|
+
raise "Internal error. Invalid special letter(#{value})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# set options
|
46
|
+
def set_options(options)
|
47
|
+
TstLog("SpecialLetter set_options: #{options[:reg_options].inspect}")
|
48
|
+
@string = set_string(options)
|
49
|
+
@obj = Regextest::Front.new(@string, options)
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# transform to json format
|
54
|
+
def json
|
55
|
+
@obj.get_json_regex
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Test suite (execute when this file is specified in command line)
|
61
|
+
if __FILE__ == $0
|
62
|
+
end
|
63
|
+
|
@@ -88,6 +88,33 @@ class Regextest::RegexOption
|
|
88
88
|
@reg_options |= options
|
89
89
|
end
|
90
90
|
|
91
|
+
# generate prefix regex
|
92
|
+
def prefix_reg
|
93
|
+
prefix = ""
|
94
|
+
prefix += "i" if is_ignore?
|
95
|
+
prefix += "m" if is_multiline?
|
96
|
+
prefix += "x" if is_extended?
|
97
|
+
|
98
|
+
if prefix.size > 0
|
99
|
+
"(?#{prefix})"
|
100
|
+
else
|
101
|
+
""
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# get charset ("a", "u", or "d")
|
106
|
+
def charset
|
107
|
+
case @char_set
|
108
|
+
when TstRegOptDefault
|
109
|
+
"d"
|
110
|
+
when TstRegOptAscii
|
111
|
+
"a"
|
112
|
+
when TstRegOptUnicode
|
113
|
+
"u"
|
114
|
+
else
|
115
|
+
raise "Internal error. Invalid char_set (#{@char_set})"
|
116
|
+
end
|
117
|
+
end
|
91
118
|
|
92
119
|
# methods for checking each flag
|
93
120
|
def is_ignore?
|
data/lib/regextest/unicode.rb
CHANGED
@@ -6,6 +6,11 @@ class Regextest::Unicode
|
|
6
6
|
# Generate hash of properties
|
7
7
|
def self.property(class_name)
|
8
8
|
case class_name.downcase
|
9
|
+
# Regextest defined char classes (from underscore)
|
10
|
+
when "_asciiprint"
|
11
|
+
([[32, 126]])
|
12
|
+
|
13
|
+
# Unicode.org defined char classes
|
9
14
|
when "alpha"
|
10
15
|
([[65, 90], [97, 122], [170, 170], [181, 181], [186, 186], [192, 214], [216, 246], [248, 705], [710, 721], [736, 740], [748, 748], [750, 750], [837, 837], [880, 884], [886, 887], [890, 893], [902, 902], [904, 906], [908, 908], [910, 929], [931, 1013], [1015, 1153], [1162, 1319], [1329, 1366], [1369, 1369], [1377, 1415], [1456, 1469], [1471, 1471], [1473, 1474], [1476, 1477], [1479, 1479], [1488, 1514], [1520, 1522], [1552, 1562], [1568, 1623], [1625, 1631], [1646, 1747], [1749, 1756], [1761, 1768], [1773, 1775], [1786, 1788], [1791, 1791], [1808, 1855], [1869, 1969], [1994, 2026], [2036, 2037], [2042, 2042], [2048, 2071], [2074, 2092], [2112, 2136], [2208, 2208], [2210, 2220], [2276, 2281], [2288, 2302], [2304, 2363], [2365, 2380], [2382, 2384], [2389, 2403], [2417, 2423], [2425, 2431], [2433, 2435], [2437, 2444], [2447, 2448], [2451, 2472], [2474, 2480], [2482, 2482], [2486, 2489], [2493, 2500], [2503, 2504], [2507, 2508], [2510, 2510], [2519, 2519], [2524, 2525], [2527, 2531], [2544, 2545], [2561, 2563], [2565, 2570], [2575, 2576], [2579, 2600], [2602, 2608], [2610, 2611], [2613, 2614], [2616, 2617], [2622, 2626], [2631, 2632], [2635, 2636], [2641, 2641], [2649, 2652], [2654, 2654], [2672, 2677], [2689, 2691], [2693, 2701], [2703, 2705], [2707, 2728], [2730, 2736], [2738, 2739], [2741, 2745], [2749, 2757], [2759, 2761], [2763, 2764], [2768, 2768], [2784, 2787], [2817, 2819], [2821, 2828], [2831, 2832], [2835, 2856], [2858, 2864], [2866, 2867], [2869, 2873], [2877, 2884], [2887, 2888], [2891, 2892], [2902, 2903], [2908, 2909], [2911, 2915], [2929, 2929], [2946, 2947], [2949, 2954], [2958, 2960], [2962, 2965], [2969, 2970], [2972, 2972], [2974, 2975], [2979, 2980], [2984, 2986], [2990, 3001], [3006, 3010], [3014, 3016], [3018, 3020], [3024, 3024], [3031, 3031], [3073, 3075], [3077, 3084], [3086, 3088], [3090, 3112], [3114, 3123], [3125, 3129], [3133, 3140], [3142, 3144], [3146, 3148], [3157, 3158], [3160, 3161], [3168, 3171], [3202, 3203], [3205, 3212], [3214, 3216], [3218, 3240], [3242, 3251], [3253, 3257], [3261, 3268], [3270, 3272], [3274, 3276], [3285, 3286], [3294, 3294], [3296, 3299], [3313, 3314], [3330, 3331], [3333, 3340], [3342, 3344], [3346, 3386], [3389, 3396], [3398, 3400], [3402, 3404], [3406, 3406], [3415, 3415], [3424, 3427], [3450, 3455], [3458, 3459], [3461, 3478], [3482, 3505], [3507, 3515], [3517, 3517], [3520, 3526], [3535, 3540], [3542, 3542], [3544, 3551], [3570, 3571], [3585, 3642], [3648, 3654], [3661, 3661], [3713, 3714], [3716, 3716], [3719, 3720], [3722, 3722], [3725, 3725], [3732, 3735], [3737, 3743], [3745, 3747], [3749, 3749], [3751, 3751], [3754, 3755], [3757, 3769], [3771, 3773], [3776, 3780], [3782, 3782], [3789, 3789], [3804, 3807], [3840, 3840], [3904, 3911], [3913, 3948], [3953, 3969], [3976, 3991], [3993, 4028], [4096, 4150], [4152, 4152], [4155, 4159], [4176, 4194], [4197, 4200], [4206, 4230], [4238, 4238], [4252, 4253], [4256, 4293], [4295, 4295], [4301, 4301], [4304, 4346], [4348, 4680], [4682, 4685], [4688, 4694], [4696, 4696], [4698, 4701], [4704, 4744], [4746, 4749], [4752, 4784], [4786, 4789], [4792, 4798], [4800, 4800], [4802, 4805], [4808, 4822], [4824, 4880], [4882, 4885], [4888, 4954], [4959, 4959], [4992, 5007], [5024, 5108], [5121, 5740], [5743, 5759], [5761, 5786], [5792, 5866], [5870, 5872], [5888, 5900], [5902, 5907], [5920, 5939], [5952, 5971], [5984, 5996], [5998, 6000], [6002, 6003], [6016, 6067], [6070, 6088], [6103, 6103], [6108, 6108], [6176, 6263], [6272, 6314], [6320, 6389], [6400, 6428], [6432, 6443], [6448, 6456], [6480, 6509], [6512, 6516], [6528, 6571], [6576, 6601], [6656, 6683], [6688, 6750], [6753, 6772], [6823, 6823], [6912, 6963], [6965, 6979], [6981, 6987], [7040, 7081], [7084, 7087], [7098, 7141], [7143, 7153], [7168, 7221], [7245, 7247], [7258, 7293], [7401, 7404], [7406, 7411], [7413, 7414], [7424, 7615], [7680, 7957], [7960, 7965], [7968, 8005], [8008, 8013], [8016, 8023], [8025, 8025], [8027, 8027], [8029, 8029], [8031, 8061], [8064, 8116], [8118, 8124], [8126, 8126], [8130, 8132], [8134, 8140], [8144, 8147], [8150, 8155], [8160, 8172], [8178, 8180], [8182, 8188], [8305, 8305], [8319, 8319], [8336, 8348], [8450, 8450], [8455, 8455], [8458, 8467], [8469, 8469], [8473, 8477], [8484, 8484], [8486, 8486], [8488, 8488], [8490, 8493], [8495, 8505], [8508, 8511], [8517, 8521], [8526, 8526], [8544, 8584], [9398, 9449], [11264, 11310], [11312, 11358], [11360, 11492], [11499, 11502], [11506, 11507], [11520, 11557], [11559, 11559], [11565, 11565], [11568, 11623], [11631, 11631], [11648, 11670], [11680, 11686], [11688, 11694], [11696, 11702], [11704, 11710], [11712, 11718], [11720, 11726], [11728, 11734], [11736, 11742], [11744, 11775], [11823, 11823], [12293, 12295], [12321, 12329], [12337, 12341], [12344, 12348], [12353, 12438], [12445, 12447], [12449, 12538], [12540, 12543], [12549, 12589], [12593, 12686], [12704, 12730], [12784, 12799], [13312, 19893], [19968, 40908], [40960, 42124], [42192, 42237], [42240, 42508], [42512, 42527], [42538, 42539], [42560, 42606], [42612, 42619], [42623, 42647], [42655, 42735], [42775, 42783], [42786, 42888], [42891, 42894], [42896, 42899], [42912, 42922], [43000, 43009], [43011, 43013], [43015, 43018], [43020, 43047], [43072, 43123], [43136, 43203], [43250, 43255], [43259, 43259], [43274, 43306], [43312, 43346], [43360, 43388], [43392, 43442], [43444, 43455], [43471, 43471], [43520, 43574], [43584, 43597], [43616, 43638], [43642, 43642], [43648, 43710], [43712, 43712], [43714, 43714], [43739, 43741], [43744, 43759], [43762, 43765], [43777, 43782], [43785, 43790], [43793, 43798], [43808, 43814], [43816, 43822], [43968, 44010], [44032, 55203], [55216, 55238], [55243, 55291], [63744, 64109], [64112, 64217], [64256, 64262], [64275, 64279], [64285, 64296], [64298, 64310], [64312, 64316], [64318, 64318], [64320, 64321], [64323, 64324], [64326, 64433], [64467, 64829], [64848, 64911], [64914, 64967], [65008, 65019], [65136, 65140], [65142, 65276], [65313, 65338], [65345, 65370], [65382, 65470], [65474, 65479], [65482, 65487], [65490, 65495], [65498, 65500], [65536, 65547], [65549, 65574], [65576, 65594], [65596, 65597], [65599, 65613], [65616, 65629], [65664, 65786], [65856, 65908], [66176, 66204], [66208, 66256], [66304, 66334], [66352, 66378], [66432, 66461], [66464, 66499], [66504, 66511], [66513, 66517], [66560, 66717], [67584, 67589], [67592, 67592], [67594, 67637], [67639, 67640], [67644, 67644], [67647, 67669], [67840, 67861], [67872, 67897], [67968, 68023], [68030, 68031], [68096, 68099], [68101, 68102], [68108, 68115], [68117, 68119], [68121, 68147], [68192, 68220], [68352, 68405], [68416, 68437], [68448, 68466], [68608, 68680], [69632, 69701], [69762, 69816], [69840, 69864], [69888, 69938], [70016, 70079], [70081, 70084], [71296, 71349], [73728, 74606], [74752, 74850], [77824, 78894], [92160, 92728], [93952, 94020], [94032, 94078], [94099, 94111], [110592, 110593], [119808, 119892], [119894, 119964], [119966, 119967], [119970, 119970], [119973, 119974], [119977, 119980], [119982, 119993], [119995, 119995], [119997, 120003], [120005, 120069], [120071, 120074], [120077, 120084], [120086, 120092], [120094, 120121], [120123, 120126], [120128, 120132], [120134, 120134], [120138, 120144], [120146, 120485], [120488, 120512], [120514, 120538], [120540, 120570], [120572, 120596], [120598, 120628], [120630, 120654], [120656, 120686], [120688, 120712], [120714, 120744], [120746, 120770], [120772, 120779], [126464, 126467], [126469, 126495], [126497, 126498], [126500, 126500], [126503, 126503], [126505, 126514], [126516, 126519], [126521, 126521], [126523, 126523], [126530, 126530], [126535, 126535], [126537, 126537], [126539, 126539], [126541, 126543], [126545, 126546], [126548, 126548], [126551, 126551], [126553, 126553], [126555, 126555], [126557, 126557], [126559, 126559], [126561, 126562], [126564, 126564], [126567, 126570], [126572, 126578], [126580, 126583], [126585, 126588], [126590, 126590], [126592, 126601], [126603, 126619], [126625, 126627], [126629, 126633], [126635, 126651], [131072, 173782], [173824, 177972], [177984, 178205], [194560, 195101]])
|
11
16
|
when "blank"
|
data/lib/regextest/version.rb
CHANGED
data/lib/tst-reg-test.rb
CHANGED
@@ -6,10 +6,12 @@ require 'regextest'
|
|
6
6
|
require 'kconv'
|
7
7
|
require 'timeout'
|
8
8
|
require 'pp'
|
9
|
+
require 'csv'
|
9
10
|
|
10
11
|
class Regextest::Test
|
11
12
|
def initialize(min_test, max_test)
|
12
|
-
|
13
|
+
@csv_file = "test_history.csv"
|
14
|
+
@results = {
|
13
15
|
success: [],
|
14
16
|
bug: [],
|
15
17
|
failed: [],
|
@@ -19,15 +21,48 @@ class Regextest::Test
|
|
19
21
|
timeout: [],
|
20
22
|
perl_syntax: [],
|
21
23
|
}
|
22
|
-
time_out =
|
23
|
-
do_test(results, min_test, max_test, time_out)
|
24
|
-
print_results(results)
|
24
|
+
time_out = 2
|
25
|
+
do_test(@results, min_test, max_test, time_out)
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
+
def append_to_csv(results = @results)
|
29
|
+
results2 = []
|
30
|
+
results.each do | key, values |
|
31
|
+
values.each do | value |
|
32
|
+
value[:reason] = key
|
33
|
+
results2.push value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
results2.sort!{|x, y| x[:index] <=> y[:index]}
|
37
|
+
if FileTest.exist?(@csv_file)
|
38
|
+
old_data = CSV.read(@csv_file, "rb:UTF-8")
|
39
|
+
CSV.open(@csv_file, "wb:UTF-8") do |csv|
|
40
|
+
csv << (old_data.shift) + [Time.now.to_s]
|
41
|
+
results2.each do | result |
|
42
|
+
old_row = old_data.shift
|
43
|
+
break if !old_row || old_row.size == 0
|
44
|
+
regex = result[:test] || result[:reg]
|
45
|
+
if old_row[0].to_i != result[:index]
|
46
|
+
raise "regex not matched. csv: #{old_row}, new: #{result}"
|
47
|
+
end
|
48
|
+
csv << old_row + [result[:reason]]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
CSV.open(@csv_file, "wb:UTF-8") do |csv|
|
53
|
+
csv << ["ID", "REGEXP", Time.now.to_s]
|
54
|
+
results2.each do | result |
|
55
|
+
regex = result[:test] || result[:reg]
|
56
|
+
csv << [result[:index], regex, result[:reason]]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def print_results(results = @results)
|
28
63
|
puts ""
|
29
64
|
(results[:failed] + results[:bug]).each do | failed_hash |
|
30
|
-
regex = failed_hash[:
|
65
|
+
regex = failed_hash[:reg] || failed_hash[:result][:reg]
|
31
66
|
puts "======="
|
32
67
|
puts " type: #{failed_hash[:type] || failed_hash[:result][:result]}"
|
33
68
|
puts " test: #{regex}"
|
@@ -51,6 +86,7 @@ class Regextest::Test
|
|
51
86
|
get_lines(results).each_with_index do | line, i |
|
52
87
|
next if(i < min_test || i > max_test)
|
53
88
|
puts line
|
89
|
+
reg = line.gsub(/^\s*(?:x1|x2|n)\(\"|\"\)\s*$/, "")
|
54
90
|
begin
|
55
91
|
rc = nil
|
56
92
|
timeout(timeout_seconds){
|
@@ -63,43 +99,44 @@ class Regextest::Test
|
|
63
99
|
end
|
64
100
|
rescue Timeout::Error => ex
|
65
101
|
warn "Timeout::Error #{ex}. \nline:#{line}"
|
66
|
-
results[:timeout].push({result: :timeout, message: ex, reg:
|
102
|
+
results[:timeout].push({result: :timeout, message: ex, reg: reg, index: i})
|
67
103
|
rescue RegexpError => ex
|
68
104
|
warn "RegexpError #{ex}. \nline:#{line}"
|
69
|
-
results[:not_scope].push({result: :regexp_error, message: ex, reg:
|
105
|
+
results[:not_scope].push({result: :regexp_error, message: ex, reg: reg, index: i})
|
70
106
|
rescue ArgumentError => ex
|
71
107
|
warn "ArgumentError #{ex}. \nline: line"
|
72
|
-
results[:failed].push({type: :argument_error, info: ex,
|
108
|
+
results[:failed].push({type: :argument_error, info: ex, reg: reg, index: i})
|
73
109
|
#rescue Regextest::Common::RegextestTimeout => ex
|
74
110
|
# warn "RegextestTimeout #{ex}. \nline:#{line}"
|
75
|
-
# results[:failed].push({ type: :timeout,
|
111
|
+
# results[:failed].push({ type: :timeout, reg: reg, info: ex, index: i})
|
76
112
|
rescue Regextest::RegextestError => ex
|
77
113
|
warn "RegextestError #{ex}. \nline:#{line}"
|
78
|
-
results[:impossible].push({ type: Regextest::RegextestError,
|
114
|
+
results[:impossible].push({ type: Regextest::RegextestError, reg: reg, info: ex, index: i})
|
79
115
|
rescue Regextest::RegextestFailedToGenerate => ex
|
80
116
|
warn "RegextestFailedToGenerate #{ex}. \nline:#{line}"
|
81
|
-
results[:failed].push({ type: Regextest::RegextestFailedToGenerate,
|
117
|
+
results[:failed].push({ type: Regextest::RegextestFailedToGenerate, reg: reg, info: ex, index: i})
|
82
118
|
rescue RuntimeError => ex
|
83
119
|
warn "RuntimeError #{ex}. \nline:#{line}"
|
84
|
-
results[:bug].push({ type: RuntimeError,
|
120
|
+
results[:bug].push({ type: RuntimeError, reg: reg, info: ex, index: i})
|
85
121
|
rescue SyntaxError => ex
|
86
122
|
warn "SyntaxError #{ex}. \nline:#{line}"
|
87
|
-
results[:failed].push({ type: SyntaxError,
|
123
|
+
results[:failed].push({ type: SyntaxError, reg: reg, info: ex, index: i})
|
88
124
|
rescue NameError => ex
|
89
125
|
warn "NameError #{ex}. \nline:#{line}"
|
90
|
-
results[:failed].push({ type: NameError,
|
126
|
+
results[:failed].push({ type: NameError, reg: reg, info: ex, index: i})
|
91
127
|
rescue TypeError => ex
|
92
128
|
warn "TypeError #{ex}. \nline:#{line}"
|
93
|
-
results[:failed].push({ type: TypeError,
|
129
|
+
results[:failed].push({ type: TypeError, reg: reg, info: ex, index: i})
|
94
130
|
rescue Encoding::CompatibilityError => ex
|
95
131
|
warn "Encoding::CompatibilityError #{ex}. \nline:#{line}"
|
96
|
-
results[:failed].push({ type: Encoding::CompatibilityError,
|
132
|
+
results[:failed].push({ type: Encoding::CompatibilityError, reg: reg, info: ex, index: i})
|
97
133
|
end
|
98
134
|
end
|
99
135
|
end
|
100
136
|
|
101
137
|
def get_lines(results)
|
102
138
|
lines = []
|
139
|
+
perl_index = 9000
|
103
140
|
# py_source = IO.read("../contrib/Onigmo/testpy.py")
|
104
141
|
File::open("../contrib/Onigmo/testpy.py") do |f|
|
105
142
|
f.each do |line|
|
@@ -111,7 +148,8 @@ class Regextest::Test
|
|
111
148
|
end
|
112
149
|
else
|
113
150
|
warn "Perl syntax. \nline:#{line}"
|
114
|
-
results[:perl_syntax].push({ type: :perl_syntax, test: line, info: nil})
|
151
|
+
results[:perl_syntax].push({ type: :perl_syntax, test: line, info: nil, index: perl_index})
|
152
|
+
perl_index += 1
|
115
153
|
end
|
116
154
|
end
|
117
155
|
end
|
@@ -153,7 +191,14 @@ end
|
|
153
191
|
|
154
192
|
# Test suite (execute when this file is specified in command line)
|
155
193
|
if __FILE__ == $0
|
156
|
-
|
157
|
-
|
158
|
-
|
194
|
+
if ARGV.size == 0 || ARGV[0].match(/^\d+$/)
|
195
|
+
min_test = ARGV[1]?(ARGV[0].to_i):0
|
196
|
+
max_test = ARGV[1]?(ARGV[1].to_i):(ARGV[0]?(ARGV[0].to_i):99999999)
|
197
|
+
test_obj = Regextest::Test.new(min_test, max_test)
|
198
|
+
test_obj.print_results
|
199
|
+
elsif ARGV[0] == "csv"
|
200
|
+
test_obj = Regextest::Test.new(0, 99999999)
|
201
|
+
test_obj.print_results
|
202
|
+
test_obj.append_to_csv
|
203
|
+
end
|
159
204
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regextest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IKOMA, Mikio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/regextest/front/scanner.rb
|
163
163
|
- lib/regextest/front/selectable.rb
|
164
164
|
- lib/regextest/front/sequence.rb
|
165
|
+
- lib/regextest/front/special-letter.rb
|
165
166
|
- lib/regextest/regex-option.rb
|
166
167
|
- lib/regextest/regexp.rb
|
167
168
|
- lib/regextest/unicode.rb
|