redcar-javamateview 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/LICENSE +34 -0
  2. data/README +58 -0
  3. data/Rakefile +94 -0
  4. data/lib/javamateview.rb +41 -0
  5. data/lib/javamateview/example.rb +334 -0
  6. data/lib/javamateview/jar/java-mateview.jar +0 -0
  7. data/lib/javamateview/jcodings.jar +0 -0
  8. data/lib/javamateview/jdom.jar +0 -0
  9. data/lib/javamateview/joni.jar +0 -0
  10. data/spec/onig/match_spec.rb +50 -0
  11. data/spec/parsing/dynamic_parsing_spec.rb +172 -0
  12. data/spec/parsing/static_parsing_spec.rb +476 -0
  13. data/spec/spec_helper.rb +33 -0
  14. data/src/com/redcareditor/mate/Bundle.java +81 -0
  15. data/src/com/redcareditor/mate/DoublePattern.java +89 -0
  16. data/src/com/redcareditor/mate/Grammar.java +129 -0
  17. data/src/com/redcareditor/mate/IAnnotationAreaListener.java +7 -0
  18. data/src/com/redcareditor/mate/IGrammarListener.java +5 -0
  19. data/src/com/redcareditor/mate/IncludePattern.java +10 -0
  20. data/src/com/redcareditor/mate/LineNumberRulerColumn.java +922 -0
  21. data/src/com/redcareditor/mate/Marker.java +22 -0
  22. data/src/com/redcareditor/mate/MateText.java +697 -0
  23. data/src/com/redcareditor/mate/ParseThunk.java +71 -0
  24. data/src/com/redcareditor/mate/Parser.java +627 -0
  25. data/src/com/redcareditor/mate/ParserScheduler.java +237 -0
  26. data/src/com/redcareditor/mate/Pattern.java +152 -0
  27. data/src/com/redcareditor/mate/RangeSet.java +91 -0
  28. data/src/com/redcareditor/mate/Scanner.java +178 -0
  29. data/src/com/redcareditor/mate/Scope.java +534 -0
  30. data/src/com/redcareditor/mate/ScopeMatcher.java +162 -0
  31. data/src/com/redcareditor/mate/SharedTextColors.java +110 -0
  32. data/src/com/redcareditor/mate/SinglePattern.java +20 -0
  33. data/src/com/redcareditor/mate/WhitespaceCharacterPainter.java +395 -0
  34. data/src/com/redcareditor/mate/colouring/Colourer.java +16 -0
  35. data/src/com/redcareditor/mate/colouring/swt/MarginPaintListener.java +62 -0
  36. data/src/com/redcareditor/mate/colouring/swt/SwtColourer.java +501 -0
  37. data/src/com/redcareditor/mate/document/MateDocument.java +15 -0
  38. data/src/com/redcareditor/mate/document/MateTextFactory.java +9 -0
  39. data/src/com/redcareditor/mate/document/MateTextLocation.java +8 -0
  40. data/src/com/redcareditor/mate/document/MateTextLocationComparator.java +17 -0
  41. data/src/com/redcareditor/mate/document/MateTextRange.java +18 -0
  42. data/src/com/redcareditor/mate/document/swt/SwtMateDocument.java +143 -0
  43. data/src/com/redcareditor/mate/document/swt/SwtMateTextLocation.java +88 -0
  44. data/src/com/redcareditor/mate/document/swt/SwtMateTextRange.java +92 -0
  45. data/src/com/redcareditor/mate/document/swt/SwtScopePositionUpdater.java +90 -0
  46. data/src/com/redcareditor/mate/undo/MateTextUndoManager.java +11 -0
  47. data/src/com/redcareditor/mate/undo/swt/SwtMateTextUndoManager.java +166 -0
  48. data/src/com/redcareditor/onig/Match.java +212 -0
  49. data/src/com/redcareditor/onig/NullMatch.java +57 -0
  50. data/src/com/redcareditor/onig/NullRx.java +29 -0
  51. data/src/com/redcareditor/onig/Range.java +45 -0
  52. data/src/com/redcareditor/onig/Rx.java +167 -0
  53. data/src/com/redcareditor/plist/Dict.java +119 -0
  54. data/src/com/redcareditor/plist/PlistNode.java +52 -0
  55. data/src/com/redcareditor/plist/PlistPropertyLoader.java +44 -0
  56. data/src/com/redcareditor/theme/ScopeSelector.java +39 -0
  57. data/src/com/redcareditor/theme/Theme.java +122 -0
  58. data/src/com/redcareditor/theme/ThemeManager.java +41 -0
  59. data/src/com/redcareditor/theme/ThemeSetting.java +78 -0
  60. data/src/com/redcareditor/util/FileUtility.java +64 -0
  61. data/src/com/redcareditor/util/SingleLineFormatter.java +11 -0
  62. data/src/com/redcareditor/util/swt/ColourUtil.java +56 -0
  63. data/src/ruby/java-mateview.rb +68 -0
  64. data/test/com/redcareditor/mate/BundleTest.java +33 -0
  65. data/test/com/redcareditor/mate/EmptyRangeSetTest.java +27 -0
  66. data/test/com/redcareditor/mate/FilledRangeSetTest.java +82 -0
  67. data/test/com/redcareditor/mate/GrammarTest.java +158 -0
  68. data/test/com/redcareditor/mate/MateTextTest.java +35 -0
  69. data/test/com/redcareditor/mate/ScopeMatcherMatchingTest.java +55 -0
  70. data/test/com/redcareditor/mate/ScopeMatcherRankingTest.java +40 -0
  71. data/test/com/redcareditor/onig/RxTest.java +54 -0
  72. data/test/com/redcareditor/plist/DictTest.java +33 -0
  73. data/test/com/redcareditor/theme/RailsCastThemeTest.java +37 -0
  74. data/test/com/redcareditor/theme/ScopeSelectorTest.java +38 -0
  75. data/test/com/redcareditor/theme/ThemeManagerTest.java +29 -0
  76. data/test/com/redcareditor/util/swt/ColourUtilTest.java +17 -0
  77. metadata +134 -0
Binary file
Binary file
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + "/../../spec/spec_helper"
2
+
3
+ describe Onig::Match do
4
+ it "is returned from a regex search" do
5
+ rx = Onig::Rx.createRx("fo?o")
6
+ rx.search("foo").should be_an_instance_of(Onig::Match)
7
+ end
8
+
9
+ def search(pattern, string)
10
+ Onig::Rx.createRx(pattern).search(string)
11
+ end
12
+
13
+ it "tells you how many captures it has" do
14
+ search("foo", "foo").num_captures.should == 1
15
+ search("f(oo)", "foo").num_captures.should == 2
16
+ search("(f)(oo)", "foo").num_captures.should == 3
17
+ search("(f)(o)(o)", "foo").num_captures.should == 4
18
+ end
19
+
20
+ it "returns the start offsets of the captures" do
21
+ search("(f)(oo)", "foo").get_capture(0).start.should == 0
22
+ search("(f)(oo)", "foo").get_capture(1).start.should == 0
23
+ search("(f)(oo)", "foo").get_capture(2).start.should == 1
24
+ end
25
+
26
+ it "returns the end offsets of the captures" do
27
+ search("(f)(oo)", "foo").get_capture(0).end.should == 3
28
+ search("(f)(oo)", "foo").get_capture(1).end.should == 1
29
+ search("(f)(oo)", "foo").get_capture(2).end.should == 3
30
+ end
31
+
32
+ it "returns character offsets" do
33
+ search("(f)(.o)", "f†o").get_capture(0).end.should == 3
34
+ search("(f)(.o)", "f†o").get_capture(1).end.should == 1
35
+ search("(f)(.o)", "f†o").get_capture(2).end.should == 3
36
+ end
37
+
38
+ it "but you can get the byte offsets if you want them" do
39
+ search("(f)(.o)", "f†o").get_byte_capture(0).end.should == 5
40
+ search("(f)(.o)", "f†o").get_byte_capture(1).end.should == 1
41
+ search("(f)(.o)", "f†o").get_byte_capture(2).end.should == 5
42
+ end
43
+
44
+ it "matches a complex regex and returns character offsets" do
45
+ pattern = "\\b(0[xX]\\h(?>_?\\h)*|\\d(?>_?\\d)*(\\.(?![^[:space:][:digit:]])(?>_?\\d)*)?([eE][-+]?\\d(?>_?\\d)*)?|0[bB][01]+)\\b"
46
+ match = search(pattern, "1 + 2 + 'Redcar'")
47
+ match.get_capture(0).start.should == 0
48
+ match.get_capture(0).end.should == 1
49
+ end
50
+ end
@@ -0,0 +1,172 @@
1
+
2
+ require 'spec/spec_helper'
3
+
4
+ describe JavaMateView, "when reparsing after changes" do
5
+ before(:each) do
6
+ $display ||= Swt::Widgets::Display.new
7
+ @shell = Swt::Widgets::Shell.new($display)
8
+ @mt = JavaMateView::MateText.new(@shell, false)
9
+ @st = @mt.get_text_widget
10
+ end
11
+
12
+ after(:each) do
13
+ @mt.get_text_widget.dispose
14
+ @shell.dispose
15
+ end
16
+
17
+ def strip(text)
18
+ lines = text.split("\n")
19
+ lines.first =~ /^(\s*)/
20
+ whitespace = $1 || ""
21
+ result = lines.map{|line| line[(whitespace.length)..-1]}.join("\n")
22
+ result
23
+ end
24
+
25
+ def it_should_match_clean_reparse
26
+ @mt.parser.root.pretty(0).should == @mt.clean_reparse
27
+ end
28
+
29
+ def it_should_match_clean_reparse_debug
30
+ @mt.parser.root.pretty(0).should == @mt.clean_reparse
31
+ end
32
+
33
+ describe "when parsing Ruby" do
34
+ before(:each) do
35
+ @mt.set_grammar_by_name("Ruby")
36
+ end
37
+
38
+ it "reparses lines with only whitespace changes" do
39
+ @st.text = strip(<<-END)
40
+ class Red < Car
41
+ def foo
42
+ end
43
+ end
44
+ END
45
+ 1.times { @mt.type(1, 9, " ") }
46
+ it_should_match_clean_reparse
47
+ end
48
+
49
+ it "reparses lines with only whitespace changes, even when they have scope openers" do
50
+ @st.text = strip(<<-END)
51
+ puts "hello"
52
+ foo=<<HI
53
+ Here.foo
54
+ Here.foo
55
+ HI
56
+ puts "hello"
57
+ END
58
+ 5.times { @mt.type(1, 9, " ") }
59
+ it_should_match_clean_reparse
60
+ end
61
+
62
+ it "reparses flat SinglePatterns that have no changes to scopes" do
63
+ @st.text = "1 + 2 + Redcar"
64
+ @mt.type(0, 1, " ")
65
+ it_should_match_clean_reparse
66
+ end
67
+
68
+ it "reparses flat SinglePatterns that have changes to scopes" do
69
+ @st.text = "1 + 2 + Redcar"
70
+ @mt.type(0, 4, "2")
71
+ @mt.type(0, 12, "o")
72
+ it_should_match_clean_reparse
73
+ end
74
+
75
+ it "reparses when blank lines inserted" do
76
+ @st.text = strip(<<-END)
77
+ class Red < Car
78
+ def foo
79
+ end
80
+ end
81
+ END
82
+ @mt.type(1, 0, "\n")
83
+ @mt.type(1, 0, "\n")
84
+ it_should_match_clean_reparse
85
+ end
86
+ # 0, 13, 22, 33, 44, 47
87
+ # HI end is 46
88
+ it "reparses lines with only whitespace changes, even when they have closing scopes" do
89
+ @st.text = strip(<<-END)
90
+ puts "hello"
91
+ foo=<<HI
92
+ Here.foo
93
+ Here.foo
94
+ HI
95
+ puts "hello"
96
+ END
97
+ 1.times { @mt.type(4, 2, " ") }
98
+ it_should_match_clean_reparse
99
+ end
100
+
101
+ it "opens expected scopes again" do
102
+ @st.text = "def foo(a, b, c"
103
+ @mt.type(0, 15, ")")
104
+ it_should_match_clean_reparse
105
+ end
106
+
107
+ it "clears after at multiple levels correctly" do
108
+ @st.text = strip(<<-END)
109
+ f=<<-HTML
110
+ <style>
111
+ .foo {
112
+ }
113
+ </style>
114
+ <br />
115
+ HTML
116
+ p :asdf
117
+ END
118
+ 1.times { |i| @mt.backspace(4, 10-i)}
119
+ it_should_match_clean_reparse
120
+ end
121
+
122
+ it "removes an open scope correctly" do
123
+ @st.text = strip(<<-END)
124
+ def fo'o
125
+ end
126
+ END
127
+ @mt.backspace(0, 7)
128
+ it_should_match_clean_reparse
129
+ end
130
+
131
+ it "should interpolate an opening scope" do
132
+ @st.text = "\"asdf{1+2}asdf\""
133
+ @mt.type(0, 5, "#")
134
+ it_should_match_clean_reparse
135
+ end
136
+
137
+ it "should reparse closing scopes" do
138
+ @st.text = "fo=<<HI\nHI"
139
+ @mt.type(1, 2, "\n")
140
+ it_should_match_clean_reparse
141
+ end
142
+
143
+ it "should reparse strings correctly" do
144
+ @st.text = "bus(\"les/\#{name}\").data = self\n\n"
145
+ @mt.type(0, 30, " ")
146
+ it_should_match_clean_reparse
147
+ end
148
+
149
+ it "should handle multibyte characters with aplomb" do
150
+ @st.text = "\"as\"as"
151
+ @mt.type(0, 2, "†")
152
+ it_should_match_clean_reparse
153
+ end
154
+
155
+ it "scopes should have left gravity" do
156
+ @st.text = "def foo"
157
+ @mt.type(0, 7, "(")
158
+ @mt.type(0, 8, "a")
159
+ @mt.type(0, 9, ")")
160
+ it_should_match_clean_reparse
161
+ end
162
+
163
+ it "should reparse closing captures without adding duplicates" do
164
+ @st.text = "def foo"
165
+ @mt.type(0, 7, "(")
166
+ @mt.type(0, 8, ")")
167
+ @mt.type(0, 8, "a")
168
+ it_should_match_clean_reparse
169
+ end
170
+ end
171
+ end
172
+
@@ -0,0 +1,476 @@
1
+
2
+ require 'spec/spec_helper'
3
+
4
+ describe JavaMateView do
5
+ before(:each) do
6
+ $display ||= Swt::Widgets::Display.new
7
+ @shell = Swt::Widgets::Shell.new(@display)
8
+ @mt = JavaMateView::MateText.new(@shell, false)
9
+ @st = @mt.get_text_widget
10
+ end
11
+
12
+ after(:each) do
13
+ @mt.get_text_widget.dispose
14
+ @shell.dispose
15
+ $display.dispose
16
+ end
17
+
18
+ describe "when parsing Ruby from scratch" do
19
+ before(:each) do
20
+ @mt.set_grammar_by_name("Ruby")
21
+ end
22
+
23
+ it "does something" do
24
+ @st.get_line_count.should == 1
25
+ end
26
+
27
+ it "should have a blank Ruby scope tree" do
28
+ @mt.parser.root.pretty(0).should == (t=<<END)
29
+ + source.ruby (0,0)-(0,0) open
30
+ END
31
+ end
32
+
33
+ it "parses flat SinglePatterns" do
34
+ @st.text = "1 + 2 + Redcar"
35
+ @mt.parser.root.pretty(0).should == (t=<<END)
36
+ + source.ruby (0,0)-(0,14) open
37
+ + constant.numeric.ruby (0,0)-(0,1) closed
38
+ + keyword.operator.arithmetic.ruby (0,2)-(0,3) closed
39
+ + constant.numeric.ruby (0,4)-(0,5) closed
40
+ + keyword.operator.arithmetic.ruby (0,6)-(0,7) closed
41
+ + variable.other.constant.ruby (0,8)-(0,14) closed
42
+ END
43
+ end
44
+
45
+ it "parses flat SinglePatterns on multiple lines" do
46
+ @st.text = "1 + \n3 + Redcar"
47
+ @mt.parser.root.pretty(0).should == (t=<<END)
48
+ + source.ruby (0,0)-(1,10) open
49
+ + constant.numeric.ruby (0,0)-(0,1) closed
50
+ + keyword.operator.arithmetic.ruby (0,2)-(0,3) closed
51
+ + constant.numeric.ruby (1,0)-(1,1) closed
52
+ + keyword.operator.arithmetic.ruby (1,2)-(1,3) closed
53
+ + variable.other.constant.ruby (1,4)-(1,10) closed
54
+ END
55
+ end
56
+
57
+ it "arranges SinglePattern captures into trees" do
58
+ @st.text = "class Red < Car"
59
+ @mt.parser.root.pretty(0).should == (t=<<END)
60
+ + source.ruby (0,0)-(0,15) open
61
+ + meta.class.ruby (0,0)-(0,15) closed
62
+ c keyword.control.class.ruby (0,0)-(0,5) closed
63
+ c entity.name.type.class.ruby (0,6)-(0,15) closed
64
+ c entity.other.inherited-class.ruby (0,9)-(0,15) closed
65
+ c punctuation.separator.inheritance.ruby (0,10)-(0,11) closed
66
+ END
67
+ end
68
+
69
+ it "opens DoublePatterns" do
70
+ @st.text = "\"asdf"
71
+ @mt.parser.root.pretty(0).should == (t=<<END)
72
+ + source.ruby (0,0)-(0,5) open
73
+ + string.quoted.double.ruby (0,0)-(0,5) open
74
+ c punctuation.definition.string.begin.ruby (0,0)-(0,1) closed
75
+ END
76
+ end
77
+
78
+ it "closes DoublePatterns" do
79
+ @st.text = "\"asdf\""
80
+ @mt.parser.root.pretty(0).should == (t=<<END)
81
+ + source.ruby (0,0)-(0,6) open
82
+ + string.quoted.double.ruby (0,0)-(0,6) closed
83
+ c punctuation.definition.string.begin.ruby (0,0)-(0,1) closed
84
+ c punctuation.definition.string.end.ruby (0,5)-(0,6) closed
85
+ END
86
+ end
87
+
88
+ it "knows content_names of DoublePatterns" do
89
+ @st.text = "def foo(a, b)"
90
+ @mt.parser.root.pretty(0).should == (t=<<END)
91
+ + source.ruby (0,0)-(0,13) open
92
+ + meta.function.method.with-arguments.ruby variable.parameter.function.ruby (0,0)-(0,13) closed
93
+ c keyword.control.def.ruby (0,0)-(0,3) closed
94
+ c entity.name.function.ruby (0,4)-(0,7) closed
95
+ c punctuation.definition.parameters.ruby (0,7)-(0,8) closed
96
+ + punctuation.separator.object.ruby (0,9)-(0,10) closed
97
+ c punctuation.definition.parameters.ruby (0,12)-(0,13) closed
98
+ END
99
+ end
100
+
101
+ it "creates scopes as children of DoublePatterns" do
102
+ @st.text = "\"laura\\nroslin\""
103
+ @mt.parser.root.pretty(0).should == (t=<<END)
104
+ + source.ruby (0,0)-(0,15) open
105
+ + string.quoted.double.ruby (0,0)-(0,15) closed
106
+ c punctuation.definition.string.begin.ruby (0,0)-(0,1) closed
107
+ + constant.character.escape.ruby (0,6)-(0,8) closed
108
+ c punctuation.definition.string.end.ruby (0,14)-(0,15) closed
109
+ END
110
+ end
111
+
112
+ it "creates closing regexes correctly" do
113
+ @st.text = "foo=\<\<END\nstring\nEND"
114
+ @mt.parser.root.pretty(0).should == (t=<<END)
115
+ + source.ruby (0,0)-(2,3) open
116
+ + string.unquoted.heredoc.ruby (0,3)-(2,3) closed
117
+ c punctuation.definition.string.begin.ruby (0,3)-(0,9) closed
118
+ c punctuation.definition.string.end.ruby (2,0)-(2,3) closed
119
+ END
120
+ end
121
+
122
+ it "creates multiple levels of scopes" do
123
+ @st.text = "\"william \#{:joseph} adama\""
124
+ @mt.parser.root.pretty(0).should == (t=<<END)
125
+ + source.ruby (0,0)-(0,26) open
126
+ + string.quoted.double.ruby (0,0)-(0,26) closed
127
+ c punctuation.definition.string.begin.ruby (0,0)-(0,1) closed
128
+ + source.ruby.embedded.source (0,9)-(0,19) closed
129
+ c punctuation.section.embedded.ruby (0,9)-(0,11) closed
130
+ + constant.other.symbol.ruby (0,11)-(0,18) closed
131
+ c punctuation.definition.constant.ruby (0,11)-(0,12) closed
132
+ c punctuation.section.embedded.ruby (0,18)-(0,19) closed
133
+ c punctuation.definition.string.end.ruby (0,25)-(0,26) closed
134
+ END
135
+ end
136
+
137
+ it "parses some Ruby correctly" do
138
+ @st.text = <<END
139
+ class Red < Car
140
+ attr :foo
141
+ Dir["*"].each do |fn|
142
+ p fn
143
+ end
144
+ end
145
+ END
146
+ @mt.parser.root.pretty(0).should == (t=<<END)
147
+ + source.ruby (0,0)-(6,0) open
148
+ + meta.class.ruby (0,0)-(0,15) closed
149
+ c keyword.control.class.ruby (0,0)-(0,5) closed
150
+ c entity.name.type.class.ruby (0,6)-(0,15) closed
151
+ c entity.other.inherited-class.ruby (0,9)-(0,15) closed
152
+ c punctuation.separator.inheritance.ruby (0,10)-(0,11) closed
153
+ + keyword.other.special-method.ruby (1,2)-(1,6) closed
154
+ + constant.other.symbol.ruby (1,7)-(1,11) closed
155
+ c punctuation.definition.constant.ruby (1,7)-(1,8) closed
156
+ + support.class.ruby (2,2)-(2,5) closed
157
+ + punctuation.section.array.ruby (2,5)-(2,6) closed
158
+ + string.quoted.double.ruby (2,6)-(2,9) closed
159
+ c punctuation.definition.string.begin.ruby (2,6)-(2,7) closed
160
+ c punctuation.definition.string.end.ruby (2,8)-(2,9) closed
161
+ + punctuation.section.array.ruby (2,9)-(2,10) closed
162
+ + punctuation.separator.method.ruby (2,10)-(2,11) closed
163
+ + keyword.control.start-block.ruby (2,16)-(2,19) closed
164
+ + [noname] (2,19)-(2,23) closed
165
+ c punctuation.separator.variable.ruby (2,19)-(2,20) closed
166
+ + variable.other.block.ruby (2,20)-(2,22) closed
167
+ c punctuation.separator.variable.ruby (2,22)-(2,23) closed
168
+ + keyword.control.ruby (4,2)-(4,5) closed
169
+ + keyword.control.ruby (5,0)-(5,3) closed
170
+ END
171
+ end
172
+
173
+ it "embeds HTML in Ruby" do
174
+ @st.text = <<END
175
+ foo=<<-HTML
176
+ <p>FOO</p>
177
+ HTML
178
+ END
179
+ @mt.parser.root.pretty(0).should == (t=<<END)
180
+ + source.ruby (0,0)-(3,0) open
181
+ + keyword.operator.assignment.ruby (0,3)-(0,4) closed
182
+ + string.unquoted.embedded.html.ruby text.html.embedded.ruby (0,4)-(2,4) closed
183
+ c punctuation.definition.string.begin.ruby (0,4)-(0,11) closed
184
+ + meta.tag.block.any.html (1,0)-(1,3) closed
185
+ c punctuation.definition.tag.begin.html (1,0)-(1,1) closed
186
+ c entity.name.tag.block.any.html (1,1)-(1,2) closed
187
+ c punctuation.definition.tag.end.html (1,2)-(1,3) closed
188
+ + meta.tag.block.any.html (1,6)-(1,10) closed
189
+ c punctuation.definition.tag.begin.html (1,6)-(1,8) closed
190
+ c entity.name.tag.block.any.html (1,8)-(1,9) closed
191
+ c punctuation.definition.tag.end.html (1,9)-(1,10) closed
192
+ c punctuation.definition.string.end.ruby (2,0)-(2,4) closed
193
+ END
194
+ end
195
+
196
+
197
+ it "embeds CSS in HTML in Ruby" do
198
+ @st.text = <<END
199
+ foo=<<-HTML
200
+ <style>
201
+ .foo {
202
+
203
+ }
204
+ </style>
205
+ HTML
206
+ END
207
+ @mt.parser.root.pretty(0).should == (t=<<END)
208
+ + source.ruby (0,0)-(7,0) open
209
+ + keyword.operator.assignment.ruby (0,3)-(0,4) closed
210
+ + string.unquoted.embedded.html.ruby text.html.embedded.ruby (0,4)-(6,4) closed
211
+ c punctuation.definition.string.begin.ruby (0,4)-(0,11) closed
212
+ + source.css.embedded.html (1,0)-(5,8) closed
213
+ c punctuation.definition.tag.html (1,0)-(1,1) closed
214
+ c entity.name.tag.style.html (1,1)-(1,6) closed
215
+ + [noname] (1,6)-(5,0) closed
216
+ c punctuation.definition.tag.html (1,6)-(1,7) closed
217
+ + meta.selector.css (2,0)-(2,7) closed
218
+ + entity.other.attribute-name.class.css (2,2)-(2,6) closed
219
+ c punctuation.definition.entity.css (2,2)-(2,3) closed
220
+ + meta.property-list.css (2,7)-(4,3) closed
221
+ c punctuation.section.property-list.css (2,7)-(2,8) closed
222
+ c punctuation.section.property-list.css (4,2)-(4,3) closed
223
+ c punctuation.definition.tag.html (5,0)-(5,2) closed
224
+ c entity.name.tag.style.html (5,2)-(5,7) closed
225
+ c punctuation.definition.tag.html (5,7)-(5,8) closed
226
+ c punctuation.definition.string.end.ruby (6,0)-(6,4) closed
227
+ END
228
+ end
229
+
230
+ it "should do YAML" do
231
+ @mt.set_grammar_by_name("YAML")
232
+ @st.text = <<YAML
233
+ --- !ruby/object:Free
234
+ YAML
235
+ end
236
+
237
+ it "should parse this Python without falling off the end of the line" do
238
+ source = <<-PYTHON
239
+ __gsignals__ = {
240
+ "completed": (
241
+ gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
242
+ }
243
+ PYTHON
244
+ @mt.set_grammar_by_name("Python")
245
+ @st.text = source
246
+ end
247
+
248
+
249
+ it "should parse this Ruby without dying" do
250
+ source = <<-RUBY
251
+ "–",
252
+ RUBY
253
+ @mt.set_grammar_by_name("Ruby")
254
+ @st.text = source
255
+ end
256
+
257
+ it "should parse these C comments correctly" do
258
+ source = <<-TEXT
259
+ /* H
260
+ */
261
+ Gtk gtk_ (Gtk* self) {
262
+ TEXT
263
+ @mt.set_grammar_by_name("C")
264
+ @st.text = source
265
+ @mt.parser.root.pretty(0).should_not include("invalid.illegal")
266
+ end
267
+
268
+ it "should parse this PHP without dying" do
269
+ source = <<-PHP
270
+ <?php
271
+ /**
272
+ *
273
+ */
274
+ class ClassName extends AnotherClass
275
+ {
276
+ PHP
277
+ @mt.set_grammar_by_name("PHP").should be_true
278
+ @st.text = source
279
+ end
280
+
281
+ it "should not have any problem with Japanese UTF-8 characters" do
282
+ @mt.set_grammar_by_name("Plain Text")
283
+ @st.text = "日本"
284
+ end
285
+ end
286
+
287
+ describe "performance" do
288
+ before do
289
+ @mt.set_grammar_by_name("Ruby")
290
+ end
291
+
292
+ it "should parse a long line in a reasonable time" do
293
+ s = Time.now
294
+ @st.text = "() "*500
295
+ e = Time.now
296
+ (e - s).should < 2
297
+ end
298
+
299
+ it "should parse a big file in a reasonable time" do
300
+ s = Time.now
301
+ @st.text = File.read("/Users/danlucraft/Redcar/redcar/plugins/redcar/redcar.rb")
302
+ e = Time.now
303
+ (e - s).should < 2
304
+ end
305
+ end
306
+
307
+ describe "when parsing Perl from scratch" do
308
+ before(:each) do
309
+ @mt.set_grammar_by_name("Perl").should be_true
310
+ end
311
+
312
+ it "Parses simple perl comment line" do
313
+ source = <<-Perl
314
+ # Comment line with enter
315
+ Perl
316
+ @st.text = source
317
+ @mt.parser.root.pretty(0).should == (t=<<END)
318
+ + source.perl (0,0)-(1,0) open
319
+ + meta.comment.full-line.perl (0,0)-(0,25) closed
320
+ c comment.line.number-sign.perl (0,0)-(0,25) closed
321
+ c punctuation.definition.comment.perl (0,0)-(0,1) closed
322
+ END
323
+ end
324
+
325
+ it "Parses single perl declaration" do
326
+ @st.text = "my $a;"
327
+ @mt.parser.root.pretty(0).should == (t=<<END)
328
+ + source.perl (0,0)-(0,6) open
329
+ + storage.modifier.perl (0,0)-(0,2) closed
330
+ + variable.other.predefined.perl (0,3)-(0,5) closed
331
+ c punctuation.definition.variable.perl (0,3)-(0,4) closed
332
+ END
333
+ end
334
+
335
+ it "Parses some Perl code correctly" do
336
+ @st.text = <<END
337
+ sub RedCar {
338
+ my $car = shift;
339
+ my $color = "red";
340
+ my $i = 1;
341
+
342
+ while ( $i == 1 ) {
343
+ print "My car is $car, its color is $color\n";
344
+ }
345
+ }
346
+ END
347
+ @mt.parser.root.pretty(0).should == (t=<<END)
348
+ + source.perl (0,0)-(10,0) open
349
+ + meta.function.perl (0,0)-(0,11) closed
350
+ c storage.type.sub.perl (0,0)-(0,3) closed
351
+ c entity.name.function.perl (0,4)-(0,10) closed
352
+ + storage.modifier.perl (1,1)-(1,3) closed
353
+ + variable.other.readwrite.global.perl (1,4)-(1,8) closed
354
+ c punctuation.definition.variable.perl (1,4)-(1,5) closed
355
+ + support.function.perl (1,11)-(1,16) closed
356
+ + storage.modifier.perl (2,1)-(2,3) closed
357
+ + variable.other.readwrite.global.perl (2,4)-(2,10) closed
358
+ c punctuation.definition.variable.perl (2,4)-(2,5) closed
359
+ + string.quoted.double.perl (2,13)-(2,18) closed
360
+ c punctuation.definition.string.begin.perl (2,13)-(2,14) closed
361
+ c punctuation.definition.string.end.perl (2,17)-(2,18) closed
362
+ + storage.modifier.perl (3,1)-(3,3) closed
363
+ + variable.other.readwrite.global.perl (3,4)-(3,6) closed
364
+ c punctuation.definition.variable.perl (3,4)-(3,5) closed
365
+ + keyword.control.perl (5,1)-(5,6) closed
366
+ + variable.other.readwrite.global.perl (5,9)-(5,11) closed
367
+ c punctuation.definition.variable.perl (5,9)-(5,10) closed
368
+ + support.function.perl (6,3)-(6,8) closed
369
+ + string.quoted.double.perl (6,9)-(7,1) closed
370
+ c punctuation.definition.string.begin.perl (6,9)-(6,10) closed
371
+ + variable.other.readwrite.global.perl (6,20)-(6,24) closed
372
+ c punctuation.definition.variable.perl (6,20)-(6,21) closed
373
+ + variable.other.readwrite.global.perl (6,39)-(6,45) closed
374
+ c punctuation.definition.variable.perl (6,39)-(6,40) closed
375
+ c punctuation.definition.string.end.perl (7,0)-(7,1) closed
376
+ END
377
+ end
378
+ end
379
+
380
+ describe "When parsing HTML:" do
381
+
382
+ before do
383
+ @mt.set_grammar_by_name("HTML")
384
+ end
385
+
386
+ it "should parse an † without blowing up" do
387
+ @st.text = "<h1 class=\"†\">\n"
388
+ end
389
+
390
+ it "Test an embedded php string which starts at the beginning of the line" do
391
+ @st.text = "<? print(\"Asdf\") ?>"
392
+ @mt.parser.root.pretty(0).should == (t=<<END)
393
+ + text.html.basic (0,0)-(0,19) open
394
+ + [noname] (0,0)-(0,19) open
395
+ + [noname] (0,0)-(0,19) closed
396
+ c punctuation.whitespace.embedded.leading.php (0,0)-(0,0) closed
397
+ + source.php.embedded.block.html (0,0)-(0,19) closed
398
+ c punctuation.section.embedded.begin.php (0,0)-(0,2) closed
399
+ + support.function.construct.php (0,3)-(0,8) closed
400
+ + string.quoted.double.php meta.string-contents.quoted.double.php (0,9)-(0,15) closed
401
+ c punctuation.definition.string.begin.php (0,9)-(0,10) closed
402
+ c punctuation.definition.string.end.php (0,14)-(0,15) closed
403
+ c punctuation.section.embedded.end.php (0,17)-(0,19) closed
404
+ c source.php (0,17)-(0,18) closed
405
+ c punctuation.whitespace.embedded.trailing.php (0,19)-(0,19) closed
406
+ END
407
+ end
408
+ end
409
+
410
+ describe "When parsing Java" do
411
+ before do
412
+ @mt.set_grammar_by_name("Java")
413
+ end
414
+
415
+ it "should parse constants correctly" do
416
+ @st.text = <<JAVA
417
+ Level.SEVERE
418
+ JAVA
419
+ @mt.parser.root.pretty(0).should == (t=<<END)
420
+ + source.java (0,0)-(1,0) open
421
+ + storage.type.java (0,0)-(0,5) closed
422
+ + constant.other.java (0,5)-(0,12) closed
423
+ c keyword.operator.dereference.java (0,5)-(0,6) closed
424
+ END
425
+ end
426
+
427
+ it "should not have a weird comment bug" do
428
+ @st.text = <<JAVA
429
+ public class Foo {
430
+ public int nonn() {
431
+ // }
432
+ }
433
+ }
434
+
435
+ JAVA
436
+ @mt.parser.root.pretty(0).should == (t=<<END)
437
+ + source.java (0,0)-(6,0) open
438
+ + meta.class.java (0,0)-(4,1) closed
439
+ + [noname] (0,0)-(0,6) closed
440
+ c storage.modifier.java (0,0)-(0,6) closed
441
+ + meta.class.identifier.java (0,7)-(0,16) closed
442
+ c storage.modifier.java (0,7)-(0,12) closed
443
+ c entity.name.type.class.java (0,13)-(0,16) closed
444
+ + meta.class.body.java (0,17)-(4,0) closed
445
+ + meta.method.java (1,1)-(3,2) closed
446
+ + [noname] (1,1)-(1,7) closed
447
+ c storage.modifier.java (1,1)-(1,7) closed
448
+ + meta.method.return-type.java (1,8)-(1,12) closed
449
+ + storage.type.primitive.array.java (1,8)-(1,11) closed
450
+ + meta.method.identifier.java (1,12)-(1,18) closed
451
+ c entity.name.function.java (1,12)-(1,16) closed
452
+ + meta.method.body.java (1,19)-(3,1) closed
453
+ + [noname] (2,0)-(2,5) closed
454
+ c comment.line.double-slash.java (2,0)-(2,5) closed
455
+ c punctuation.definition.comment.java (2,0)-(2,2) closed
456
+ c punctuation.section.class.end.java (4,0)-(4,1) closed
457
+ END
458
+ end
459
+ end
460
+
461
+ describe "when parsing JavaScript" do
462
+ before do
463
+ @mt.set_grammar_by_name("JavaScript")
464
+ end
465
+
466
+ it "should parse the following line and not hang" do
467
+ @st.text = <<JAVASCRIPT
468
+ C=z&&z.events;if(z&&C){if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(e in C)c.event.remove(a,e+b)}else{for(b=b.split(" ");e=b[j++];){n=e;i=e.indexOf(".")<0;o=[];if(!i){o=e.split(".");e=o.shift();k=new RegExp("(^|\\.)"+c.map(o.slice(0).sort(),db).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(r=C[e])if(d){n=c.event.special[e]||{};for(B=f||0;B<r.length;B++){u=r[B];if(d.guid===u.guid){if(i||k.test(u.namespace)){f==null&&r.splice(B--,1);n.remove&&n.remove.call(a,u)}if(f!=
469
+ JAVASCRIPT
470
+ @mt.parser.root.pretty(0)
471
+ end
472
+ end
473
+ end
474
+
475
+
476
+