langscan 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.txt +19 -0
- data/History.txt +126 -0
- data/Manifest.txt +167 -0
- data/README.rdoc +89 -0
- data/Rakefile +40 -0
- data/ext/langscan/_make_c.rb +20 -0
- data/ext/langscan/_make_h.rb +30 -0
- data/ext/langscan/_template.c +134 -0
- data/ext/langscan/_template.h +53 -0
- data/ext/langscan/c/c/Makefile +157 -0
- data/ext/langscan/c/c/c.c +134 -0
- data/ext/langscan/c/c/c.h +66 -0
- data/ext/langscan/c/c/ctok.c +4622 -0
- data/ext/langscan/c/c/ctok.l +212 -0
- data/ext/langscan/c/c/extconf.rb +3 -0
- data/ext/langscan/c/c/modulename.txt +1 -0
- data/ext/langscan/c/c/tokenlist.txt +13 -0
- data/ext/langscan/csharp/csharp/Makefile +157 -0
- data/ext/langscan/csharp/csharp/csharp.c +134 -0
- data/ext/langscan/csharp/csharp/csharp.h +65 -0
- data/ext/langscan/csharp/csharp/csharptok.c +2965 -0
- data/ext/langscan/csharp/csharp/csharptok.l +200 -0
- data/ext/langscan/csharp/csharp/extconf.rb +3 -0
- data/ext/langscan/csharp/csharp/modulename.txt +1 -0
- data/ext/langscan/csharp/csharp/tokenlist.txt +12 -0
- data/ext/langscan/d/d/Makefile +157 -0
- data/ext/langscan/d/d/d.c +134 -0
- data/ext/langscan/d/d/d.h +64 -0
- data/ext/langscan/d/d/dtok.c +5461 -0
- data/ext/langscan/d/d/dtok.l +282 -0
- data/ext/langscan/d/d/extconf.rb +3 -0
- data/ext/langscan/d/d/modulename.txt +1 -0
- data/ext/langscan/d/d/tokenlist.txt +11 -0
- data/ext/langscan/elisp/elisp/Makefile +157 -0
- data/ext/langscan/elisp/elisp/elisp.c +134 -0
- data/ext/langscan/elisp/elisp/elisp.h +62 -0
- data/ext/langscan/elisp/elisp/elisptok.c +2101 -0
- data/ext/langscan/elisp/elisp/elisptok.l +151 -0
- data/ext/langscan/elisp/elisp/extconf.rb +3 -0
- data/ext/langscan/elisp/elisp/modulename.txt +1 -0
- data/ext/langscan/elisp/elisp/tokenlist.txt +9 -0
- data/ext/langscan/java/java/Makefile +157 -0
- data/ext/langscan/java/java/extconf.rb +3 -0
- data/ext/langscan/java/java/java.c +134 -0
- data/ext/langscan/java/java/java.h +64 -0
- data/ext/langscan/java/java/javatok.c +2090 -0
- data/ext/langscan/java/java/javatok.l +155 -0
- data/ext/langscan/java/java/modulename.txt +1 -0
- data/ext/langscan/java/java/tokenlist.txt +11 -0
- data/ext/langscan/javascript/javascript/Makefile +157 -0
- data/ext/langscan/javascript/javascript/extconf.rb +3 -0
- data/ext/langscan/javascript/javascript/javascript.c +134 -0
- data/ext/langscan/javascript/javascript/javascript.h +63 -0
- data/ext/langscan/javascript/javascript/javascripttok.c +2051 -0
- data/ext/langscan/javascript/javascript/javascripttok.l +147 -0
- data/ext/langscan/javascript/javascript/modulename.txt +1 -0
- data/ext/langscan/javascript/javascript/tokenlist.txt +10 -0
- data/ext/langscan/pairmatcher/pairmatcher/Makefile +157 -0
- data/ext/langscan/pairmatcher/pairmatcher/extconf.rb +3 -0
- data/ext/langscan/pairmatcher/pairmatcher/pairmatcher.c +890 -0
- data/ext/langscan/php/php/Makefile +157 -0
- data/ext/langscan/php/php/extconf.rb +3 -0
- data/ext/langscan/php/php/modulename.txt +1 -0
- data/ext/langscan/php/php/php.c +134 -0
- data/ext/langscan/php/php/php.h +64 -0
- data/ext/langscan/php/php/phptok.c +2406 -0
- data/ext/langscan/php/php/phptok.l +212 -0
- data/ext/langscan/php/php/tokenlist.txt +11 -0
- data/ext/langscan/post-distclean.rb +21 -0
- data/ext/langscan/pre-config.rb +57 -0
- data/ext/langscan/python/python/Makefile +157 -0
- data/ext/langscan/python/python/extconf.rb +3 -0
- data/ext/langscan/python/python/modulename.txt +1 -0
- data/ext/langscan/python/python/python.c +134 -0
- data/ext/langscan/python/python/python.h +61 -0
- data/ext/langscan/python/python/pythontok.c +2102 -0
- data/ext/langscan/python/python/pythontok.l +155 -0
- data/ext/langscan/python/python/tokenlist.txt +8 -0
- data/ext/langscan/ruby/compat/ripper/Makefile +158 -0
- data/ext/langscan/ruby/compat/ripper/depend +1 -0
- data/ext/langscan/ruby/compat/ripper/extconf.rb +4 -0
- data/ext/langscan/ruby/compat/ripper/include/eventids1.c +251 -0
- data/ext/langscan/ruby/compat/ripper/include/eventids2.c +277 -0
- data/ext/langscan/ruby/compat/ripper/include/lex.c +138 -0
- data/ext/langscan/ruby/compat/ripper/ripper.c +14420 -0
- data/ext/langscan/scheme/scheme/Makefile +157 -0
- data/ext/langscan/scheme/scheme/extconf.rb +3 -0
- data/ext/langscan/scheme/scheme/modulename.txt +1 -0
- data/ext/langscan/scheme/scheme/scheme.c +134 -0
- data/ext/langscan/scheme/scheme/scheme.h +60 -0
- data/ext/langscan/scheme/scheme/schemetok.c +2447 -0
- data/ext/langscan/scheme/scheme/schemetok.l +177 -0
- data/ext/langscan/scheme/scheme/tokenlist.txt +7 -0
- data/ext/langscan/sh/sh/Makefile +157 -0
- data/ext/langscan/sh/sh/extconf.rb +3 -0
- data/ext/langscan/sh/sh/modulename.txt +1 -0
- data/ext/langscan/sh/sh/sh.c +134 -0
- data/ext/langscan/sh/sh/sh.h +61 -0
- data/ext/langscan/sh/sh/shtok.c +2470 -0
- data/ext/langscan/sh/sh/shtok.l +325 -0
- data/ext/langscan/sh/sh/tokenlist.txt +8 -0
- data/lib/langscan.rb +124 -0
- data/lib/langscan/_common.rb +50 -0
- data/lib/langscan/_easyscanner.rb +78 -0
- data/lib/langscan/_pairmatcher.rb +46 -0
- data/lib/langscan/_type.rb +125 -0
- data/lib/langscan/autoconf.rb +51 -0
- data/lib/langscan/automake.rb +51 -0
- data/lib/langscan/brainfuck.rb +48 -0
- data/lib/langscan/c.rb +144 -0
- data/lib/langscan/csharp.rb +101 -0
- data/lib/langscan/css.rb +109 -0
- data/lib/langscan/d.rb +201 -0
- data/lib/langscan/eiffel.rb +167 -0
- data/lib/langscan/elisp.rb +132 -0
- data/lib/langscan/io.rb +84 -0
- data/lib/langscan/java.rb +95 -0
- data/lib/langscan/javascript.rb +97 -0
- data/lib/langscan/lua.rb +116 -0
- data/lib/langscan/ocaml.rb +298 -0
- data/lib/langscan/ocaml/camlexer.ml +28 -0
- data/lib/langscan/ocaml/lexer.mll +230 -0
- data/lib/langscan/ocaml/types.ml +36 -0
- data/lib/langscan/perl.rb +87 -0
- data/lib/langscan/perl/tokenizer.pl +231 -0
- data/lib/langscan/php.rb +80 -0
- data/lib/langscan/python.rb +101 -0
- data/lib/langscan/rpmspec.rb +71 -0
- data/lib/langscan/ruby.rb +164 -0
- data/lib/langscan/ruby/compat/README +5 -0
- data/lib/langscan/ruby/compat/ripper.rb +4 -0
- data/lib/langscan/ruby/compat/ripper/core.rb +918 -0
- data/lib/langscan/ruby/compat/ripper/filter.rb +70 -0
- data/lib/langscan/ruby/compat/ripper/lexer.rb +179 -0
- data/lib/langscan/ruby/compat/ripper/sexp.rb +100 -0
- data/lib/langscan/scheme.rb +160 -0
- data/lib/langscan/sh.rb +116 -0
- data/lib/langscan/text.rb +37 -0
- data/metaconfig +2 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/makemanifest.rb +21 -0
- data/setup.rb +1604 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/langscan.rake +42 -0
- data/test/langscan/brainfuck/test/test_scan.rb +55 -0
- data/test/langscan/c/test/test_scan.rb +216 -0
- data/test/langscan/c/test/test_token.rb +41 -0
- data/test/langscan/csharp/test/test_scan.rb +157 -0
- data/test/langscan/css/test/test_css.rb +79 -0
- data/test/langscan/d/test/test_scan.rb +233 -0
- data/test/langscan/d/test/test_token.rb +205 -0
- data/test/langscan/eiffel/test/test_eiffel.rb +95 -0
- data/test/langscan/elisp/test/test_elisp.rb +177 -0
- data/test/langscan/io/test/test_io.rb +79 -0
- data/test/langscan/java/test/test_java.rb +74 -0
- data/test/langscan/javascript/test/test_javascript.rb +39 -0
- data/test/langscan/lua/test/test_lua.rb +69 -0
- data/test/langscan/ocaml/test/test_ocaml.rb +161 -0
- data/test/langscan/php/test/test_scan.rb +138 -0
- data/test/langscan/python/test/test_scan.rb +105 -0
- data/test/langscan/rpmspec/test/test_rpmspec.rb +51 -0
- data/test/langscan/ruby/test/test_scan.rb +71 -0
- data/test/langscan/scheme/test/test_scan.rb +198 -0
- data/test/test_helper.rb +7 -0
- data/test/test_langscan.rb +123 -0
- metadata +296 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/eiffel'
|
3
|
+
|
4
|
+
class TestEiffel < Test::Unit::TestCase
|
5
|
+
def assert_fragments(expected, code)
|
6
|
+
result = []
|
7
|
+
LangScan::Eiffel.scan(code) {|f| result.push(f) }
|
8
|
+
fragments = []
|
9
|
+
result.each {|fragment|
|
10
|
+
type, text = fragment.to_a
|
11
|
+
unless type == :punct
|
12
|
+
fragments << [type, text]
|
13
|
+
end
|
14
|
+
}
|
15
|
+
assert_equal(expected, fragments)
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_fragment_type(type, text, src)
|
19
|
+
found = false
|
20
|
+
LangScan::Eiffel.scan(src) {|f|
|
21
|
+
if f.text == text
|
22
|
+
if found
|
23
|
+
raise "token #{text} occurred twice"
|
24
|
+
else
|
25
|
+
found = true
|
26
|
+
assert_equal(type, f.type, "fragment type of #{text}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
}
|
30
|
+
unless found
|
31
|
+
raise "token #{text} not found"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_comments
|
36
|
+
assert_fragments([[:comment, "-- c"]], "-- c")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_strings
|
40
|
+
assert_fragments([[:string, %Q("s%"")]], %Q("s%""))
|
41
|
+
assert_fragments([[:string, %Q("")]], %Q(""))
|
42
|
+
assert_fragments([[:character, %Q('%'')]], %Q('%''))
|
43
|
+
assert_fragments([[:character, %Q('c')]], %Q('c'))
|
44
|
+
assert_fragments([[:string, %Q("s%\ns")]], %Q("s%\ns"))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_integers
|
48
|
+
assert_fragments([[:integer, "123"]], "123")
|
49
|
+
assert_fragments([[:integer, "1_234"]], "1_234")
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_floatings
|
53
|
+
assert_fragments([[:floating, "1_234.456"]], "1_234.456")
|
54
|
+
assert_fragments([[:floating, ".456"]], ".456")
|
55
|
+
assert_fragments([[:floating, "123."]], "123.")
|
56
|
+
assert_fragments([[:floating, "123.456e-2"]], "123.456e-2")
|
57
|
+
assert_fragments([[:floating, "123.456E2"]], "123.456E2")
|
58
|
+
assert_fragments([[:floating, "123.456E+2"]], "123.456E+2")
|
59
|
+
assert_fragments([[:floating, ".E+2"]], ".E+2")
|
60
|
+
assert_fragments([], ".")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_keywords
|
64
|
+
assert_fragment_type(:keyword, 'feature', 'feature')
|
65
|
+
assert_fragment_type(:keyword, 'fEAtUrE', 'fEAtUrE')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_fundefs
|
69
|
+
assert_fragment_type(:fundef, 'foo', 'foo() is do')
|
70
|
+
assert_fragment_type(:fundef, 'foo', 'foo(p : INTEGER) is')
|
71
|
+
assert_fragment_type(:fundef, 'foo', 'foo(p : INTEGER) : INTEGER is')
|
72
|
+
assert_fragment_type(:fundef, 'foo', 'foo is do')
|
73
|
+
assert_fragment_type(:fundef, 'foo', 'foo: INTEGER is local')
|
74
|
+
assert_fragment_type(:fundef, 'foo', "foo: INTEGER is --comment\nexternal")
|
75
|
+
|
76
|
+
assert_fragment_type(:ident, 'foo', 'foo is REAL')
|
77
|
+
assert_fragment_type(:ident, 'foo', 'f (p : INTEGER) : foo is once')
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_funcalls
|
81
|
+
assert_fragment_type(:funcall, 'foo', 'foo();')
|
82
|
+
assert_fragment_type(:funcall, 'foo', 'a.foo(p);')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_renames
|
86
|
+
assert_fragment_type(:fundef, 'foo', 'rename f as foo')
|
87
|
+
assert_fragment_type(:ident, 'foo', 'rename foo as f')
|
88
|
+
assert_fragment_type(:fundef, 'foo', 'rename b as bar, f as foo')
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_classdefs
|
92
|
+
assert_fragment_type(:classdef, 'foo', 'class foo')
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
$LOAD_PATH << "../../.." unless $LOAD_PATH.include?("../../..")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'langscan/elisp'
|
4
|
+
|
5
|
+
class TestEmacsLisp < Test::Unit::TestCase
|
6
|
+
def assert_yield_any(recv, meth, *args)
|
7
|
+
success = false
|
8
|
+
recv.__send__(meth, *args) {|*block_args|
|
9
|
+
if yield(*block_args)
|
10
|
+
assert(true)
|
11
|
+
success = true
|
12
|
+
break
|
13
|
+
end
|
14
|
+
}
|
15
|
+
assert(false, "no expected yields") unless success
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_yield_all(recv, meth, *args)
|
19
|
+
recv.__send__(meth, *args) {|*block_args|
|
20
|
+
if !yield(*block_args)
|
21
|
+
assert(false, "unexpected yields")
|
22
|
+
return
|
23
|
+
end
|
24
|
+
}
|
25
|
+
assert(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_defun
|
29
|
+
[
|
30
|
+
{:str => "(defun foo () ())", :text => "foo"},
|
31
|
+
{:str => "(defun foo (bar) ())", :text => "foo"},
|
32
|
+
{:str => "(defun foo (bar) baz)", :text => "foo"},
|
33
|
+
{:str => "(defun foo= (a) (= a a))", :text => "foo="}
|
34
|
+
].each {|src|
|
35
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src[:str]) {|f|
|
36
|
+
f.type == :fundef && f.text == src[:text]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_funcall
|
42
|
+
[
|
43
|
+
{:str => "(foo)", :text => "foo"},
|
44
|
+
{:str => "(foo bar)", :text => "foo"},
|
45
|
+
{:str => "(let ((a 1) (b 2)) (+ a b))", :text => "+"}
|
46
|
+
].each {|src|
|
47
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src[:str]) {|f|
|
48
|
+
f.type == :funcall && f.text == src[:text]
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_defvar
|
54
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, "(defvar a 't)") {|f|
|
55
|
+
f.type == :keyword && f.text == 'defvar'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_setq
|
60
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, "(setq a 1)") {|f|
|
61
|
+
f.type == :keyword && f.text == 'setq'
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_ident
|
66
|
+
%w(foo foo= foo? char-to-string 1+ \+1 +-*/_~!@$%^&=:<>{}
|
67
|
+
).each {|src|
|
68
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
69
|
+
f.type == :ident
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_quote
|
75
|
+
[
|
76
|
+
"'(a b c)",
|
77
|
+
"`(a b c)",
|
78
|
+
"(quote (a b c))",
|
79
|
+
"(backquote (a b c))",
|
80
|
+
].each { |src|
|
81
|
+
assert_yield_all(LangScan::EmacsLisp, :scan, src) {|f|
|
82
|
+
f.type != :funcall
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_character
|
88
|
+
[
|
89
|
+
'?a',
|
90
|
+
'? ',
|
91
|
+
'?\C-\\',
|
92
|
+
'?\C-\M-m',
|
93
|
+
'?\101',
|
94
|
+
'?\)',
|
95
|
+
'?\^Ij',
|
96
|
+
'?\H-\M-\A-x'
|
97
|
+
].each { |src|
|
98
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
99
|
+
f.type == :character
|
100
|
+
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_string
|
105
|
+
[
|
106
|
+
'"foo"',
|
107
|
+
"\"foo\nbar\"",
|
108
|
+
"\"foo\\\nbar\"",
|
109
|
+
'"foo\"bar"',
|
110
|
+
'"foo\\\\"',
|
111
|
+
].each { |src|
|
112
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
113
|
+
f.type == :string
|
114
|
+
}
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_number
|
119
|
+
%w( 1 -1 1050 10. +1 ).each { |src|
|
120
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
121
|
+
f.type == :integer
|
122
|
+
}
|
123
|
+
}
|
124
|
+
%w( 1.0 -.1 4e10 10.3e4 +3.32e-10 ).each { |src|
|
125
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
126
|
+
f.type == :floating
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_comment
|
132
|
+
[
|
133
|
+
'; comment',
|
134
|
+
"(foo bar) ; comment"
|
135
|
+
].each { |src|
|
136
|
+
assert_yield_any(LangScan::EmacsLisp, :scan, src) {|f|
|
137
|
+
f.type == :comment
|
138
|
+
}
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def assert_fragment_type(type, text, src)
|
144
|
+
found = false
|
145
|
+
LangScan::EmacsLisp.scan(src) {|f|
|
146
|
+
if f.text == text
|
147
|
+
if found
|
148
|
+
raise "token #{text} occurred twice"
|
149
|
+
else
|
150
|
+
found = true
|
151
|
+
assert_equal(type, f.type, "fragment type of #{text}")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
}
|
155
|
+
unless found
|
156
|
+
raise "token #{text} not found"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_nest_in_quote
|
161
|
+
assert_fragment_type(:ident, 'a', "'(a (b))")
|
162
|
+
assert_fragment_type(:ident, 'a', "(quote (a (b)))")
|
163
|
+
assert_fragment_type(:ident, 'b', "'(a (b))")
|
164
|
+
assert_fragment_type(:ident, 'b', "`(a (b))")
|
165
|
+
assert_fragment_type(:ident, 'b', "(backquote (a (b)))")
|
166
|
+
assert_fragment_type(:funcall, 'b', "`(a ,(b))")
|
167
|
+
assert_fragment_type(:funcall, 'b', "`(a ,@(b))")
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_let_body
|
171
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1)) ((y)))")
|
172
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1) (z 2)) ((y)))")
|
173
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1) (z 2)) (y))")
|
174
|
+
assert_fragment_type(:ident, 'z', "(let ((x 1) (z 2)) ((y)))")
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/io'
|
3
|
+
|
4
|
+
class TestIo < Test::Unit::TestCase
|
5
|
+
def assert_fragments(expected, code)
|
6
|
+
result = []
|
7
|
+
LangScan::Io.scan(code) {|f| result.push(f) }
|
8
|
+
fragments = []
|
9
|
+
result.each {|fragment|
|
10
|
+
type, text = fragment.to_a
|
11
|
+
unless type == :punct
|
12
|
+
fragments << [type, text]
|
13
|
+
end
|
14
|
+
}
|
15
|
+
assert_equal(expected, fragments)
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_punct(expected, code)
|
19
|
+
num = 0
|
20
|
+
LangScan::Io.scan(code) {|f|
|
21
|
+
assert_equal(:punct, f.type)
|
22
|
+
assert_equal(expected, f.text)
|
23
|
+
num += 1
|
24
|
+
}
|
25
|
+
assert_equal(1, num)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_comments
|
29
|
+
assert_fragments([[:comment, "/*c*/"]], "/*c*/")
|
30
|
+
assert_fragments([[:comment, "/*/c\n*/"]], "/*/c\n*/")
|
31
|
+
assert_fragments([[:comment, "#c"]], "#c")
|
32
|
+
assert_fragments([[:comment, "//c"]], "//c")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_strings
|
36
|
+
assert_fragments([[:string, %Q("s")]], %Q("s"))
|
37
|
+
assert_fragments([[:string, %Q("""s\ns""")]], %Q("""s\ns"""))
|
38
|
+
assert_fragments([[:string, %Q("")]], %Q(""))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_integers
|
42
|
+
assert_fragments([[:integer, "123"]], "123")
|
43
|
+
assert_fragments([[:integer, "0x0"]], "0x0")
|
44
|
+
assert_fragments([[:integer, "0x0F"]], "0x0F")
|
45
|
+
assert_fragments([[:integer, "0XeE"]], "0XeE")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_floatings
|
49
|
+
assert_fragments([[:floating, "123.456"]], "123.456")
|
50
|
+
assert_fragments([[:floating, "0.456"]], "0.456")
|
51
|
+
assert_fragments([[:floating, ".456"]], ".456")
|
52
|
+
assert_fragments([[:floating, "123e-2"]], "123e-2")
|
53
|
+
assert_fragments([[:floating, "123e2"]], "123e2")
|
54
|
+
assert_fragments([[:floating, "123.456e-2"]], "123.456e-2")
|
55
|
+
assert_fragments([[:floating, "123.456e2"]], "123.456e2")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_fundefs
|
59
|
+
assert_fragments([[:fundef, "s"], [:funcall, "f"]], "s := f")
|
60
|
+
assert_fragments([[:fundef, "s"], [:funcall, "f"]], "s = f")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_funcalls
|
64
|
+
assert_fragments([[:funcall, "f"]], "f")
|
65
|
+
assert_fragments([[:funcall, "a"]], "@a")
|
66
|
+
assert_fragments([[:funcall, "a"]], "@@a")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_punct
|
70
|
+
assert_punct('@@', '@@')
|
71
|
+
assert_punct(':=', ':=')
|
72
|
+
assert_punct(';', ';')
|
73
|
+
assert_punct('(', '(')
|
74
|
+
assert_punct('{', '{')
|
75
|
+
assert_punct(']', ']')
|
76
|
+
assert_punct(',', ',')
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/java'
|
3
|
+
|
4
|
+
class TestJava < Test::Unit::TestCase
|
5
|
+
def test_duplicated
|
6
|
+
fs = {}
|
7
|
+
LangScan::Java.scan("a()") {|f|
|
8
|
+
assert(!fs[f.beg_byteno], "duplicated fragment: #{f.inspect}")
|
9
|
+
fs[f.beg_byteno] = f
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_fundef
|
14
|
+
fragments = scan("int foo() {}")
|
15
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
16
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
17
|
+
assert_equal("foo", fundef[0].text)
|
18
|
+
assert_equal(4, fundef[0].beg_byteno)
|
19
|
+
assert_equal(1, fundef[0].beg_lineno)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_fundef
|
23
|
+
fragments = scan("int\nfoo()\n{}")
|
24
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
25
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
26
|
+
assert_equal("foo", fundef[0].text)
|
27
|
+
assert_equal(4, fundef[0].beg_byteno)
|
28
|
+
assert_equal(2, fundef[0].beg_lineno)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_fundef_arg
|
32
|
+
fragments = scan("String getName(Object obj) {}")
|
33
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
34
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
35
|
+
assert_equal("getName", fundef[0].text)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_fundef_comment
|
39
|
+
fragments = scan("String getName(Object obj, /* (ok) */) {}")
|
40
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
41
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
42
|
+
assert_equal("getName", fundef[0].text)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_fundef_comment2
|
46
|
+
fragments = scan("public static final String getName(Object obj, // (ok)\n) {}")
|
47
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
48
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
49
|
+
assert_equal("getName", fundef[0].text)
|
50
|
+
assert_equal(27, fundef[0].beg_byteno)
|
51
|
+
assert_equal(1, fundef[0].beg_lineno)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_fundef_throws
|
55
|
+
fragments = scan("int foo() throws IOException {}")
|
56
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
57
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
58
|
+
assert_equal("foo", fundef[0].text)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_fundef_throws2
|
62
|
+
fragments = scan("int foo() throws IOException, GonzuiException {}")
|
63
|
+
fundef = fragments.find_all {|f| f.type == :fundef}
|
64
|
+
assert_equal(1, fundef.size, fragments.join("\n"))
|
65
|
+
assert_equal("foo", fundef[0].text)
|
66
|
+
end
|
67
|
+
|
68
|
+
def scan(src)
|
69
|
+
r = []
|
70
|
+
LangScan::Java.scan(src) {|f| r << f }
|
71
|
+
return r
|
72
|
+
end
|
73
|
+
private :scan
|
74
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
$LOAD_PATH << "../../.." unless $LOAD_PATH.include?("../../..")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'langscan/javascript'
|
4
|
+
|
5
|
+
class TestJavaScript < Test::Unit::TestCase
|
6
|
+
def assert_yield_any(recv, meth, *args)
|
7
|
+
success = false
|
8
|
+
recv.__send__(meth, *args) {|*block_args|
|
9
|
+
if yield(*block_args)
|
10
|
+
assert(true)
|
11
|
+
success = true
|
12
|
+
break
|
13
|
+
end
|
14
|
+
}
|
15
|
+
assert(false, "no expected yields") unless success
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_yield_all(recv, meth, *args)
|
19
|
+
recv.__send__(meth, *args) {|*block_args|
|
20
|
+
if !yield(*block_args)
|
21
|
+
assert(false, "unexpected yields")
|
22
|
+
return
|
23
|
+
end
|
24
|
+
}
|
25
|
+
assert(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_funcall
|
29
|
+
assert_yield_any(LangScan::JavaScript, :scan, "a()") {|f|
|
30
|
+
f.type == :funcall && f.text == 'a'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_fundef
|
35
|
+
assert_yield_any(LangScan::JavaScript, :scan, "a(){}") {|f|
|
36
|
+
f.type == :fundef && f.text == 'a'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|