langscan 1.2-x86-mswin32-60
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 +91 -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 +188 -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 +4629 -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 +188 -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 +2971 -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 +188 -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 +5468 -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 +188 -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 +2108 -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 +188 -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 +2097 -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 +188 -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 +2058 -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 +188 -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 +188 -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 +2413 -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 +188 -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 +2109 -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 +189 -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 +188 -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 +2454 -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 +188 -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 +2477 -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/c/c.so +0 -0
- data/lib/langscan/csharp.rb +101 -0
- data/lib/langscan/csharp/csharp.so +0 -0
- data/lib/langscan/css.rb +109 -0
- data/lib/langscan/d.rb +201 -0
- data/lib/langscan/d/d.so +0 -0
- data/lib/langscan/eiffel.rb +167 -0
- data/lib/langscan/elisp.rb +132 -0
- data/lib/langscan/elisp/elisp.so +0 -0
- data/lib/langscan/io.rb +84 -0
- data/lib/langscan/java.rb +95 -0
- data/lib/langscan/java/java.so +0 -0
- data/lib/langscan/javascript.rb +97 -0
- data/lib/langscan/javascript/javascript.so +0 -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/pairmatcher/pairmatcher.so +0 -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/php/php.so +0 -0
- data/lib/langscan/python.rb +101 -0
- data/lib/langscan/python/python.so +0 -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.so +0 -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/scheme/scheme.so +0 -0
- data/lib/langscan/sh.rb +116 -0
- data/lib/langscan/sh/sh.so +0 -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 +320 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/lua'
|
3
|
+
|
4
|
+
class TestLua < Test::Unit::TestCase
|
5
|
+
def assert_fragments(expected, code)
|
6
|
+
result = []
|
7
|
+
LangScan::Lua.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::Lua.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([[:string, %Q('s\\'')]], %Q('s\\''))
|
43
|
+
assert_fragments([[:string, %Q('')]], %Q(''))
|
44
|
+
assert_fragments([[:string, %Q([[s\ns]])]], %Q([[s\ns]]))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_integers
|
48
|
+
assert_fragments([[:integer, "123"]], "123")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_floatings
|
52
|
+
assert_fragments([[:floating, "123.456"]], "123.456")
|
53
|
+
assert_fragments([[:floating, "0.456"]], "0.456")
|
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_fragment_type(:fundef, "foo", "function foo()")
|
60
|
+
assert_fragment_type(:fundef, "foo", "local function foo()")
|
61
|
+
assert_fragment_type(:fundef, "foo", "foo = function()")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_funcalls
|
65
|
+
assert_fragment_type(:funcall, "foo", "foo()")
|
66
|
+
assert_fragment_type(:funcall, "foo", "a = foo()")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
require 'langscan/ocaml'
|
4
|
+
|
5
|
+
module LangScan::OCaml
|
6
|
+
class TestToken < Test::Unit::TestCase
|
7
|
+
def test_int
|
8
|
+
t = Tokenizer.new("123")
|
9
|
+
f = t.get_token()
|
10
|
+
|
11
|
+
assert_equal("123", f.text)
|
12
|
+
assert_equal(:integer, f.type)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_comment
|
16
|
+
t = Tokenizer.new("(* ... *)")
|
17
|
+
f = t.get_token()
|
18
|
+
assert_equal("(* ... *)", f.text)
|
19
|
+
assert_equal(:comment, f.type)
|
20
|
+
assert_equal(nil, t.get_token())
|
21
|
+
|
22
|
+
t = Tokenizer.new("(* (* (* *) *) *)")
|
23
|
+
f = t.get_token()
|
24
|
+
assert_equal("(* (* (* *) *) *)", f.text)
|
25
|
+
assert_equal(:comment, f.type)
|
26
|
+
assert_equal(nil, t.get_token())
|
27
|
+
|
28
|
+
t = Tokenizer.new("(*\n*)")
|
29
|
+
f = t.get_token()
|
30
|
+
assert_equal("(*\n*)", f.text)
|
31
|
+
assert_equal(:comment, f.type)
|
32
|
+
assert_equal(nil, t.get_token())
|
33
|
+
|
34
|
+
t = Tokenizer.new("(* \" \" *)")
|
35
|
+
f = t.get_token()
|
36
|
+
assert_equal("(* \" \" *)", f.text)
|
37
|
+
assert_equal(:comment, f.type)
|
38
|
+
assert_equal(nil, t.get_token())
|
39
|
+
|
40
|
+
t = Tokenizer.new("(* \" *) (* \" *)")
|
41
|
+
f = t.get_token()
|
42
|
+
assert_equal("(* \" *) (* \" *)", f.text)
|
43
|
+
assert_equal(:comment, f.type)
|
44
|
+
assert_equal(nil, t.get_token())
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def assert_fragment_type(type, text, src)
|
49
|
+
found = false
|
50
|
+
LangScan::OCaml.scan(src) {|f|
|
51
|
+
if f.text == text
|
52
|
+
if found
|
53
|
+
raise "token #{text} occurred twice"
|
54
|
+
else
|
55
|
+
found = true
|
56
|
+
assert_equal(type, f.type, "fragment type of #{text}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
}
|
60
|
+
unless found
|
61
|
+
raise "token #{text} not found"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_fundefs
|
66
|
+
assert_fragment_type(:ident, "foo", "let foo = bar")
|
67
|
+
assert_fragment_type(:fundef, "foo", "let foo bar = bar")
|
68
|
+
assert_fragment_type(:fundef, "foo", "let rec foo bar = bar")
|
69
|
+
assert_fragment_type(:funcall, "baz", "let foo bar = baz bar")
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_methdefs
|
73
|
+
assert_fragment_type(:fundef, "foo", "method foo = 0")
|
74
|
+
assert_fragment_type(:funcall, "foo", "method f b = foo b")
|
75
|
+
assert_fragment_type(:ident, "foo", "method f foo c = a")
|
76
|
+
|
77
|
+
assert_fragment_type(:fundef, "foo", "method private foo = 0")
|
78
|
+
assert_fragment_type(:funcall, "foo", "method virtual f b = foo b")
|
79
|
+
assert_fragment_type(:ident, "foo", "method private virtual f foo c = a")
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_anon_fun
|
83
|
+
assert_fragment_type(:ident, "foo", "fun foo bar baz = baz")
|
84
|
+
assert_fragment_type(:ident, "bar", "fun foo bar baz = baz")
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_funcalls
|
88
|
+
assert_fragment_type(:funcall, "foo", "foo bar")
|
89
|
+
assert_fragment_type(:ident, "foo", "a:foo b:bar")
|
90
|
+
assert_fragment_type(:ident, "foo", "| foo bar")
|
91
|
+
assert_fragment_type(:ident, "foo", "with foo bar")
|
92
|
+
assert_fragment_type(:ident, "foo", "* foo bar") # not real?
|
93
|
+
assert_fragment_type(:ident, "foo", "'foo bar")
|
94
|
+
assert_fragment_type(:funcall, "foo", "foo 1")
|
95
|
+
assert_fragment_type(:funcall, "foo", "foo 1.1")
|
96
|
+
assert_fragment_type(:funcall, "foo", "foo \"str\"")
|
97
|
+
assert_fragment_type(:funcall, "foo", "foo ()")
|
98
|
+
assert_fragment_type(:ident, "foo", "foo fun") # not real?
|
99
|
+
assert_fragment_type(:ident, "foo", "foo -1")
|
100
|
+
assert_fragment_type(:funcall, "foo", "foo (-1)")
|
101
|
+
assert_fragment_type(:funcall, "foo", "foo [ 1 ]")
|
102
|
+
assert_fragment_type(:funcall, "foo", "foo [| 1 |]")
|
103
|
+
assert_fragment_type(:ident, "foo", "foo list")
|
104
|
+
assert_fragment_type(:ident, "foo", "?foo bar")
|
105
|
+
assert_fragment_type(:ident, "foo", "~foo bar")
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_after_funcalls
|
109
|
+
assert_fragment_type(:funcall, "foo", "f (foo bar)")
|
110
|
+
assert_fragment_type(:ident, "foo", "f [|1|] foo bar")
|
111
|
+
assert_fragment_type(:ident, "foo", "f a.b foo bar")
|
112
|
+
assert_fragment_type(:ident, "foo", "f a#b foo bar")
|
113
|
+
assert_fragment_type(:ident, "foo", "f a.b c.foo bar")
|
114
|
+
assert_fragment_type(:ident, "foo", "f a#b c#foo bar")
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_methcalls
|
118
|
+
assert_fragment_type(:funcall, "foo", "o#foo 1")
|
119
|
+
assert_fragment_type(:funcall, "foo", "o#foo;")
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_fundecls
|
123
|
+
assert_fragment_type(:ident, "foo", "val foo : int")
|
124
|
+
assert_fragment_type(:fundecl, "foo", "val foo : int -> int")
|
125
|
+
assert_fragment_type(:fundecl, "foo", "val mutable foo : int -> int")
|
126
|
+
assert_fragment_type(:fundecl, "foo", "external foo : int -> int")
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_methdecls
|
130
|
+
assert_fragment_type(:fundecl, "foo", "method foo : int -> int")
|
131
|
+
assert_fragment_type(:fundecl, "foo", "method foo : int")
|
132
|
+
assert_fragment_type(:ident, "foo", "method f : (int * int) foo b")
|
133
|
+
assert_fragment_type(:ident, "foo", "method f : a:foo b")
|
134
|
+
|
135
|
+
assert_fragment_type(:fundecl, "foo", "method private foo : int")
|
136
|
+
assert_fragment_type(:fundecl, "foo", "method virtual foo : int")
|
137
|
+
assert_fragment_type(:fundecl, "foo", "method private virtual foo : int")
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_skiptypes
|
141
|
+
assert_fragment_type(:ident, "foo", "of foo bar")
|
142
|
+
assert_fragment_type(:ident, "foo", ":> foo bar")
|
143
|
+
# assert_fragment_type(:ident, "foo", "| f.foo bar")
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_class
|
147
|
+
assert_fragment_type(:ident, "foo", "class foo bar")
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_skip_comments
|
151
|
+
assert_fragment_type(:fundecl, "foo", "method (**) foo (**) : (**) int")
|
152
|
+
assert_fragment_type(:funcall, "foo", "foo (**) [| (**) 1 (**) |]")
|
153
|
+
assert_fragment_type(:fundef, "foo",
|
154
|
+
"let (**) rec (**) foo (**) bar (**) = (**) bar")
|
155
|
+
end
|
156
|
+
|
157
|
+
end if system("ocaml -version")
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/php'
|
3
|
+
|
4
|
+
class TestScan < 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_classdef
|
44
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php class foo{} ?>") {|f|
|
45
|
+
f.type == :classdef && f.text == 'foo'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fundef
|
50
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php function foo1() {} ?>") {|f|
|
51
|
+
f.type == :fundef && f.text == 'foo1'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_funcall
|
56
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php hoge(); ?>") {|f|
|
57
|
+
f.type == :funcall && f.text == 'hoge'
|
58
|
+
}
|
59
|
+
assert_yield_all(LangScan::PHP, :scan, "<?php if(true); ?>") {|f|
|
60
|
+
f.type != :funcall
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_string
|
65
|
+
[
|
66
|
+
"'hoge'",
|
67
|
+
'"hoge"',
|
68
|
+
'"hoge\nfuga"'
|
69
|
+
].each do |src|
|
70
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php #{src} ?>") {|f|
|
71
|
+
f.type == :string
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_comment
|
77
|
+
[
|
78
|
+
'# comment',
|
79
|
+
"# comment\n",
|
80
|
+
"fuga(); # comment\nhoga();",
|
81
|
+
"fuga(); # comment",
|
82
|
+
].each do |src|
|
83
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php #{src} ?>") {|f|
|
84
|
+
f.type == :comment
|
85
|
+
}
|
86
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php #{src} ?>") {|f|
|
87
|
+
f.type == :ident and f.text == "?>"
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_space
|
93
|
+
[
|
94
|
+
'3 + 2',
|
95
|
+
"hoge( fuga)"
|
96
|
+
].each do |src|
|
97
|
+
assert_yield_any(LangScan::PHP, :scan, "<?php #{src} ?>") {|f|
|
98
|
+
f.type == :space
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_heredoc
|
104
|
+
[
|
105
|
+
"echo <<<EOS\r\nfoo\nEOS;\n",
|
106
|
+
"echo <<<EOS\r\nE\rEOS;\n",
|
107
|
+
"echo <<<EOS\rHOGE;\nEOS\n",
|
108
|
+
"echo <<< EODA\nHGE;\rEODA\n",
|
109
|
+
"echo <<<\tE\nF\nE\r",
|
110
|
+
"echo <<<EOS\r\nm\rEOS\n",
|
111
|
+
"echo <<<EO#{'S'*1000}\r\nEOS;\nEO#{'S'*1000}\n",
|
112
|
+
].each do |src|
|
113
|
+
pat = "<?php #{src} ?>"
|
114
|
+
assert_yield_any(LangScan::PHP, :scan, pat) {|f|
|
115
|
+
f.type == :string
|
116
|
+
}
|
117
|
+
assert_yield_any(LangScan::PHP, :scan, pat) {|f|
|
118
|
+
f.type == :ident and f.text == "?>"
|
119
|
+
}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_scriptregion
|
124
|
+
[
|
125
|
+
'<?php "hoge" ?>',
|
126
|
+
'<%= "hoge" %>',
|
127
|
+
'<% "hoge" %>',
|
128
|
+
'<script language="php"> "hoge" </script>',
|
129
|
+
'<? "hoge" ?>',
|
130
|
+
'<?= "hoge" ?>',
|
131
|
+
].each do |src|
|
132
|
+
assert_yield_any(LangScan::PHP, :scan, src) {|f|
|
133
|
+
f.type == :string and f.text == '"hoge"'
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'langscan/python'
|
3
|
+
|
4
|
+
class TestScan < 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_classdef
|
44
|
+
assert_yield_any(LangScan::Python, :scan, "class Bar:\n\tpass") {|f|
|
45
|
+
f.type == :classdef && f.text == 'Bar'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fundef
|
50
|
+
assert_yield_any(LangScan::Python, :scan, "def Foo:\n\tpass") {|f|
|
51
|
+
f.type == :fundef && f.text == 'Foo'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_funcall
|
56
|
+
assert_yield_any(LangScan::Python, :scan, "hoge()") {|f|
|
57
|
+
f.type == :funcall && f.text == 'hoge'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_not_funcall
|
62
|
+
assert_yield_any(LangScan::Python, :scan, "if (1)") {|f|
|
63
|
+
f.type == :keyword && f.text == 'if'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_string
|
68
|
+
['r"""'+"\n"+'hoge'+"\n"+'"""',
|
69
|
+
'r"""hoge"""',
|
70
|
+
"r'''\nhoge\n'''",
|
71
|
+
"r'''hoge'''",
|
72
|
+
'r"hoge"',
|
73
|
+
"r'hoge'",
|
74
|
+
"'hoge'",
|
75
|
+
'"hoge"',
|
76
|
+
'"hoge\nfuga"'].each do |src|
|
77
|
+
assert_yield_any(LangScan::Python, :scan, src) {|f|
|
78
|
+
f.type == :string
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_comment
|
84
|
+
[
|
85
|
+
'# comment',
|
86
|
+
"hoge.fuga() # comment"
|
87
|
+
].each do |src|
|
88
|
+
assert_yield_any(LangScan::Python, :scan, src) {|f|
|
89
|
+
f.type == :comment
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_space
|
95
|
+
[
|
96
|
+
'3 + 2',
|
97
|
+
"hoge( fuga)"
|
98
|
+
].each do |src|
|
99
|
+
assert_yield_any(LangScan::Python, :scan, src) {|f|
|
100
|
+
f.type == :space
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|