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,51 @@
|
|
1
|
+
$LOAD_PATH << "../../.." unless $LOAD_PATH.include?("../../..")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'langscan/rpmspec'
|
4
|
+
|
5
|
+
class TestRPMSpec < 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_preamble
|
29
|
+
assert_yield_any(LangScan::RPMSpec, :scan, "\nName: gonzui") {|f|
|
30
|
+
f.type == :keyword && f.text == 'Name'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_part
|
35
|
+
assert_yield_any(LangScan::RPMSpec, :scan, "\n%description devel") {|f|
|
36
|
+
f.type == :keyword && f.text == '%description'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_comment
|
41
|
+
assert_yield_any(LangScan::RPMSpec, :scan, "\n# comment") {|f|
|
42
|
+
f.type == :comment && f.text == '# comment'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_string
|
47
|
+
assert_yield_any(LangScan::RPMSpec, :scan, "\nCFLAGS=\"$RPM_OPT_FLAGS -Wall\"") {|f|
|
48
|
+
f.type == :string && f.text == '"$RPM_OPT_FLAGS -Wall"'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/ruby'
|
3
|
+
|
4
|
+
class TestRuby < Test::Unit::TestCase
|
5
|
+
def assert_yield_any(recv, meth, *args)
|
6
|
+
recv.__send__(meth, *args) {|*block_args|
|
7
|
+
if yield(*block_args)
|
8
|
+
assert(true)
|
9
|
+
return
|
10
|
+
end
|
11
|
+
}
|
12
|
+
assert(false, "no expected yields")
|
13
|
+
end
|
14
|
+
|
15
|
+
def assert_yield_all(recv, meth, *args)
|
16
|
+
recv.__send__(meth, *args) {|*block_args|
|
17
|
+
if !yield(*block_args)
|
18
|
+
assert(false, "unexpected yields")
|
19
|
+
return
|
20
|
+
end
|
21
|
+
}
|
22
|
+
assert(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_class
|
26
|
+
assert_yield_any(LangScan::Ruby, :scan, "class A\nend") {|f|
|
27
|
+
f.type == :classdef && f.text == 'A'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_module
|
32
|
+
assert_yield_any(LangScan::Ruby, :scan, "module A\nend") {|f|
|
33
|
+
f.type == :moduledef && f.text == 'A'
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_symbol
|
38
|
+
assert_yield_any(LangScan::Ruby, :scan, ":aaa") {|f|
|
39
|
+
f.type == :symbol && f.text == 'aaa'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_const
|
44
|
+
assert_yield_any(LangScan::Ruby, :scan, "ABC") {|f|
|
45
|
+
f.type == :const && f.text == 'ABC'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def assert_fragment_type(type, text, src)
|
50
|
+
found = false
|
51
|
+
LangScan::Ruby.scan(src) {|f|
|
52
|
+
if f.text == text
|
53
|
+
if found
|
54
|
+
raise "token #{text} occurred twice"
|
55
|
+
else
|
56
|
+
found = true
|
57
|
+
assert_equal(type, f.type, "fragment type of #{text}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
}
|
61
|
+
unless found
|
62
|
+
raise "token #{text} not found"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_singleton_method
|
67
|
+
assert_fragment_type(:fundef, 'm', "def o.m() end")
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/scheme'
|
3
|
+
|
4
|
+
class TestScheme < Test::Unit::TestCase
|
5
|
+
def assert_yield(recv, meth, *args)
|
6
|
+
yielded = false
|
7
|
+
recv.__send__(meth, *args) {|*block_args|
|
8
|
+
yielded = true
|
9
|
+
yield(*block_args)
|
10
|
+
}
|
11
|
+
assert(yielded, "block not yielded")
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_not_yield(recv, meth, *args)
|
15
|
+
yielded = false
|
16
|
+
recv.__send__(meth, *args) {|*block_args|
|
17
|
+
assert(false, "block yielded")
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def assert_yield_any(recv, meth, *args)
|
22
|
+
success = false
|
23
|
+
recv.__send__(meth, *args) {|*block_args|
|
24
|
+
if yield(*block_args)
|
25
|
+
assert(true)
|
26
|
+
success = true
|
27
|
+
break
|
28
|
+
end
|
29
|
+
}
|
30
|
+
assert(false, "no expected yields") unless success
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_yield_all(recv, meth, *args)
|
34
|
+
recv.__send__(meth, *args) {|*block_args|
|
35
|
+
if !yield(*block_args)
|
36
|
+
assert(false, "unexpected yields")
|
37
|
+
return
|
38
|
+
end
|
39
|
+
}
|
40
|
+
assert(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_fundef
|
44
|
+
[
|
45
|
+
{:str => "(define (foo))", :text => "foo"},
|
46
|
+
{:str => "(define (foo bar))", :text => "foo"},
|
47
|
+
{:str => "(define (foo bar) baz)", :text => "foo"},
|
48
|
+
{:str => "(define (foo= a) (= a a))", :text => "foo="}
|
49
|
+
].each {|src|
|
50
|
+
assert_yield_any(LangScan::Scheme, :scan, src[:str]) {|f|
|
51
|
+
f.type == :fundef && f.text == src[:text]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_funcall
|
57
|
+
[
|
58
|
+
{:str => "(foo)", :text => "foo"},
|
59
|
+
{:str => "(foo bar)", :text => "foo"},
|
60
|
+
{:str => "(let ((a 1) (b 2)) (+ a b))", :text => "+"},
|
61
|
+
{:str => "(do ((i 0 (+ i 1))) ((= i 10)) (foo))", :text => "foo"}
|
62
|
+
].each {|src|
|
63
|
+
assert_yield_any(LangScan::Scheme, :scan, src[:str]) {|f|
|
64
|
+
f.type == :funcall && f.text == src[:text]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_string
|
70
|
+
[
|
71
|
+
'"foo"',
|
72
|
+
%Q!"foo\nbar"!,
|
73
|
+
'"foo\"bar"',
|
74
|
+
'"foo\\"',
|
75
|
+
].each { |src|
|
76
|
+
assert_yield(LangScan::Scheme, :scan, src) {|f|
|
77
|
+
f.type == :string
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_ident
|
83
|
+
%w(foo foo= foo? + <=>? @foo fo!o ~foo foo^ foo$ &foo ** +- .foo
|
84
|
+
/hoge:
|
85
|
+
).each {|src|
|
86
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
87
|
+
f.type == :ident
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_quote
|
93
|
+
[
|
94
|
+
"'(a b c)",
|
95
|
+
"(quote (a b c)",
|
96
|
+
"(quasiquote (a b c))",
|
97
|
+
].each { |src|
|
98
|
+
assert_yield_all(LangScan::Scheme, :scan, src) {|f|
|
99
|
+
f.type != :funcall
|
100
|
+
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_number
|
105
|
+
%w(
|
106
|
+
1 -1 1050 #d1 #o0766 #b10 #xab #d#e16 #e#x1f #e10
|
107
|
+
).each { |src|
|
108
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
109
|
+
f.type == :integer
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
%w(
|
114
|
+
10.5 .543 .5e-5 10e10 10e-10 10#f4 10##.#d2 10/4 #xe/f
|
115
|
+
).each { |src|
|
116
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
117
|
+
f.type == :floating
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
%w(
|
122
|
+
3+i +i -i 0+i 0-10i #d0-10i -10i #x-i #d+i #x1+2i #xab+2i
|
123
|
+
#x1-2i #xa-2i #xa-i #xab/cd+1/23#i
|
124
|
+
).each { |src|
|
125
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
126
|
+
f.type == :imaginary
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_comment
|
132
|
+
[
|
133
|
+
'; comment',
|
134
|
+
"(foo bar) ; comment"
|
135
|
+
].each { |src|
|
136
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
137
|
+
f.type == :comment
|
138
|
+
}
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_space
|
143
|
+
[
|
144
|
+
'\ ',
|
145
|
+
"' 'foo bar"
|
146
|
+
].each { |src|
|
147
|
+
assert_yield_any(LangScan::Scheme, :scan, src) {|f|
|
148
|
+
f.type == :space
|
149
|
+
}
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
def assert_fragment_type(type, text, src)
|
154
|
+
found = false
|
155
|
+
LangScan::Scheme.scan(src) {|f|
|
156
|
+
if f.text == text
|
157
|
+
if found
|
158
|
+
raise "token #{text} occurred twice"
|
159
|
+
else
|
160
|
+
found = true
|
161
|
+
assert_equal(type, f.type, "fragment type of #{text}")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
}
|
165
|
+
unless found
|
166
|
+
raise "token #{text} not found"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.define_assert_fragment_type(name, type, text, src)
|
171
|
+
self.module_eval {
|
172
|
+
define_method("test_#{name}") {
|
173
|
+
assert_fragment_type(type, text, src)
|
174
|
+
}
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_nest_in_quote
|
179
|
+
assert_fragment_type(:ident, 'a', "'(a (b))")
|
180
|
+
assert_fragment_type(:ident, 'a', "(quote (a (b)))")
|
181
|
+
assert_fragment_type(:ident, 'b', "'(a (b))")
|
182
|
+
assert_fragment_type(:ident, 'b', "`(a (b))")
|
183
|
+
assert_fragment_type(:ident, 'b', "(quasiquote (a (b)))")
|
184
|
+
assert_fragment_type(:ident, 'b', "(quasiquote `(a (unquote (b))))")
|
185
|
+
assert_fragment_type(:funcall, 'b', "`(a ,(b))")
|
186
|
+
assert_fragment_type(:funcall, 'b', "``(a ,,(b))")
|
187
|
+
assert_fragment_type(:funcall, 'b', "`(a ,@(b))")
|
188
|
+
assert_fragment_type(:funcall, 'b', "(quasiquote `(a (unquote ,(b))))")
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_let_body
|
192
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1)) ((y)))")
|
193
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1) (z 2)) ((y)))")
|
194
|
+
assert_fragment_type(:funcall, 'y', "(let ((x 1) (z 2)) (y))")
|
195
|
+
assert_fragment_type(:ident, 'z', "(let ((x 1) (z 2)) ((y)))")
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestLangscan < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_c
|
9
|
+
fragments = []
|
10
|
+
LangScan::C.scan('#include <"stdio.h">') do |fragment|
|
11
|
+
fragments << fragment
|
12
|
+
end
|
13
|
+
assert_equal(6, fragments.size)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_csharp
|
17
|
+
fragments = []
|
18
|
+
LangScan::Csharp.scan('namespace Sample{useing System;}') do |fragment|
|
19
|
+
fragments << fragment
|
20
|
+
end
|
21
|
+
assert_equal(9, fragments.size)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_d
|
26
|
+
fragments = []
|
27
|
+
LangScan::D.scan('import std.stdio;') do |fragment|
|
28
|
+
fragments << fragment
|
29
|
+
end
|
30
|
+
assert_equal(6, fragments.size)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_java
|
34
|
+
fragments = []
|
35
|
+
LangScan::Java.scan('package com.example;') do |fragment|
|
36
|
+
fragments << fragment
|
37
|
+
end
|
38
|
+
assert_equal(6, fragments.size)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_ruby
|
42
|
+
fragments = []
|
43
|
+
LangScan::Ruby.scan('print "Hello", "World"') do |fragment|
|
44
|
+
fragments << fragment
|
45
|
+
end
|
46
|
+
assert_equal(10, fragments.size)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_python
|
50
|
+
fragments = []
|
51
|
+
LangScan::Python.scan('puts "Hello World"') do |fragment|
|
52
|
+
fragments << fragment
|
53
|
+
end
|
54
|
+
assert_equal(3, fragments.size)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_javascript
|
58
|
+
fragments = []
|
59
|
+
LangScan::JavaScript.scan('(function(){})();') do |fragment|
|
60
|
+
fragments << fragment
|
61
|
+
end
|
62
|
+
assert_equal(10, fragments.size)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_css
|
66
|
+
fragments = []
|
67
|
+
LangScan::CSS.scan('div#example p.sample { border: 1px solid red; }') do |fragment|
|
68
|
+
fragments << fragment
|
69
|
+
end
|
70
|
+
assert_equal(14, fragments.size)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_php
|
74
|
+
fragments = []
|
75
|
+
LangScan::PHP.scan('<?php echo "php"') do |fragment|
|
76
|
+
fragments << fragment
|
77
|
+
end
|
78
|
+
assert_equal(4, fragments.size)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_sh
|
82
|
+
fragments = []
|
83
|
+
LangScan::Shell.scan('#!/bin/sh\necho $1') do |fragment|
|
84
|
+
fragments << fragment
|
85
|
+
end
|
86
|
+
assert_equal(1, fragments.size)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_text
|
90
|
+
fragments = []
|
91
|
+
LangScan::Text.scan('This is plain text') do |fragment|
|
92
|
+
fragments << fragment
|
93
|
+
end
|
94
|
+
assert_equal(1, fragments.size)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_elisp
|
98
|
+
fragments = []
|
99
|
+
LangScan::EmacsLisp.scan('(line-number-mode 1)') do |fragment|
|
100
|
+
fragments << fragment
|
101
|
+
end
|
102
|
+
assert_equal(5, fragments.size)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_scheme
|
106
|
+
fragments = []
|
107
|
+
LangScan::Scheme.scan('(line-number-mode 1)') do |fragment|
|
108
|
+
fragments << fragment
|
109
|
+
end
|
110
|
+
assert_equal(5, fragments.size)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_brainfuck
|
114
|
+
fragments = []
|
115
|
+
LangScan::Brainfuck.scan('>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++
|
116
|
+
++>-]<.>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>
|
117
|
+
++++++++[<++++>-]<+.[-]++++++++++.') do |fragment|
|
118
|
+
fragments << fragment
|
119
|
+
end
|
120
|
+
assert_equal(182, fragments.size)
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|