redcar-javamateview 0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +34 -0
- data/README +58 -0
- data/Rakefile +94 -0
- data/lib/javamateview.rb +41 -0
- data/lib/javamateview/example.rb +334 -0
- data/lib/javamateview/jar/java-mateview.jar +0 -0
- data/lib/javamateview/jcodings.jar +0 -0
- data/lib/javamateview/jdom.jar +0 -0
- data/lib/javamateview/joni.jar +0 -0
- data/spec/onig/match_spec.rb +50 -0
- data/spec/parsing/dynamic_parsing_spec.rb +172 -0
- data/spec/parsing/static_parsing_spec.rb +476 -0
- data/spec/spec_helper.rb +33 -0
- data/src/com/redcareditor/mate/Bundle.java +81 -0
- data/src/com/redcareditor/mate/DoublePattern.java +89 -0
- data/src/com/redcareditor/mate/Grammar.java +129 -0
- data/src/com/redcareditor/mate/IAnnotationAreaListener.java +7 -0
- data/src/com/redcareditor/mate/IGrammarListener.java +5 -0
- data/src/com/redcareditor/mate/IncludePattern.java +10 -0
- data/src/com/redcareditor/mate/LineNumberRulerColumn.java +922 -0
- data/src/com/redcareditor/mate/Marker.java +22 -0
- data/src/com/redcareditor/mate/MateText.java +697 -0
- data/src/com/redcareditor/mate/ParseThunk.java +71 -0
- data/src/com/redcareditor/mate/Parser.java +627 -0
- data/src/com/redcareditor/mate/ParserScheduler.java +237 -0
- data/src/com/redcareditor/mate/Pattern.java +152 -0
- data/src/com/redcareditor/mate/RangeSet.java +91 -0
- data/src/com/redcareditor/mate/Scanner.java +178 -0
- data/src/com/redcareditor/mate/Scope.java +534 -0
- data/src/com/redcareditor/mate/ScopeMatcher.java +162 -0
- data/src/com/redcareditor/mate/SharedTextColors.java +110 -0
- data/src/com/redcareditor/mate/SinglePattern.java +20 -0
- data/src/com/redcareditor/mate/WhitespaceCharacterPainter.java +395 -0
- data/src/com/redcareditor/mate/colouring/Colourer.java +16 -0
- data/src/com/redcareditor/mate/colouring/swt/MarginPaintListener.java +62 -0
- data/src/com/redcareditor/mate/colouring/swt/SwtColourer.java +501 -0
- data/src/com/redcareditor/mate/document/MateDocument.java +15 -0
- data/src/com/redcareditor/mate/document/MateTextFactory.java +9 -0
- data/src/com/redcareditor/mate/document/MateTextLocation.java +8 -0
- data/src/com/redcareditor/mate/document/MateTextLocationComparator.java +17 -0
- data/src/com/redcareditor/mate/document/MateTextRange.java +18 -0
- data/src/com/redcareditor/mate/document/swt/SwtMateDocument.java +143 -0
- data/src/com/redcareditor/mate/document/swt/SwtMateTextLocation.java +88 -0
- data/src/com/redcareditor/mate/document/swt/SwtMateTextRange.java +92 -0
- data/src/com/redcareditor/mate/document/swt/SwtScopePositionUpdater.java +90 -0
- data/src/com/redcareditor/mate/undo/MateTextUndoManager.java +11 -0
- data/src/com/redcareditor/mate/undo/swt/SwtMateTextUndoManager.java +166 -0
- data/src/com/redcareditor/onig/Match.java +212 -0
- data/src/com/redcareditor/onig/NullMatch.java +57 -0
- data/src/com/redcareditor/onig/NullRx.java +29 -0
- data/src/com/redcareditor/onig/Range.java +45 -0
- data/src/com/redcareditor/onig/Rx.java +167 -0
- data/src/com/redcareditor/plist/Dict.java +119 -0
- data/src/com/redcareditor/plist/PlistNode.java +52 -0
- data/src/com/redcareditor/plist/PlistPropertyLoader.java +44 -0
- data/src/com/redcareditor/theme/ScopeSelector.java +39 -0
- data/src/com/redcareditor/theme/Theme.java +122 -0
- data/src/com/redcareditor/theme/ThemeManager.java +41 -0
- data/src/com/redcareditor/theme/ThemeSetting.java +78 -0
- data/src/com/redcareditor/util/FileUtility.java +64 -0
- data/src/com/redcareditor/util/SingleLineFormatter.java +11 -0
- data/src/com/redcareditor/util/swt/ColourUtil.java +56 -0
- data/src/ruby/java-mateview.rb +68 -0
- data/test/com/redcareditor/mate/BundleTest.java +33 -0
- data/test/com/redcareditor/mate/EmptyRangeSetTest.java +27 -0
- data/test/com/redcareditor/mate/FilledRangeSetTest.java +82 -0
- data/test/com/redcareditor/mate/GrammarTest.java +158 -0
- data/test/com/redcareditor/mate/MateTextTest.java +35 -0
- data/test/com/redcareditor/mate/ScopeMatcherMatchingTest.java +55 -0
- data/test/com/redcareditor/mate/ScopeMatcherRankingTest.java +40 -0
- data/test/com/redcareditor/onig/RxTest.java +54 -0
- data/test/com/redcareditor/plist/DictTest.java +33 -0
- data/test/com/redcareditor/theme/RailsCastThemeTest.java +37 -0
- data/test/com/redcareditor/theme/ScopeSelectorTest.java +38 -0
- data/test/com/redcareditor/theme/ThemeManagerTest.java +29 -0
- data/test/com/redcareditor/util/swt/ColourUtilTest.java +17 -0
- metadata +142 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
package com.redcareditor.mate;
|
2
|
+
|
3
|
+
import static org.junit.Assert.*;
|
4
|
+
|
5
|
+
import org.junit.Before;
|
6
|
+
import org.junit.Test;
|
7
|
+
|
8
|
+
public class BundleTest {
|
9
|
+
|
10
|
+
@Before
|
11
|
+
public void setUp() {
|
12
|
+
Bundle.loadBundles("input/");
|
13
|
+
}
|
14
|
+
|
15
|
+
@Test
|
16
|
+
public void shouldHaveCreatedCorrectBundles() {
|
17
|
+
String[] bundleNames = new String[] { "Apache", "Ruby", "HTML", "CSS", "JavaScript", "Perl" };
|
18
|
+
for (String bundleName : bundleNames) {
|
19
|
+
containsBundleNamed(bundleName);
|
20
|
+
}
|
21
|
+
assertEquals(11, Bundle.getBundles().size());
|
22
|
+
}
|
23
|
+
|
24
|
+
private void containsBundleNamed(String bundleName) {
|
25
|
+
assertNotNull(Bundle.getBundleByName(bundleName));
|
26
|
+
}
|
27
|
+
|
28
|
+
@Test
|
29
|
+
public void shouldHaveCreatedCorrectGrammars() {
|
30
|
+
assertEquals(1, Bundle.getBundleByName("Apache").getGrammars().size());
|
31
|
+
assertEquals(1, Bundle.getBundleByName("Ruby").getGrammars().size());
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
package com.redcareditor.mate;
|
2
|
+
|
3
|
+
import static org.junit.Assert.*;
|
4
|
+
|
5
|
+
import org.junit.*;
|
6
|
+
|
7
|
+
public class EmptyRangeSetTest {
|
8
|
+
private RangeSet rs;
|
9
|
+
|
10
|
+
@Before
|
11
|
+
public void setUp() throws Exception {
|
12
|
+
rs = new RangeSet();
|
13
|
+
}
|
14
|
+
|
15
|
+
@Test
|
16
|
+
public void testShouldReportEmpty() {
|
17
|
+
assertTrue(rs.isEmpty());
|
18
|
+
}
|
19
|
+
|
20
|
+
@Test
|
21
|
+
public void testShouldAddARange() {
|
22
|
+
rs.add(1, 3);
|
23
|
+
assertEquals(1, rs.length());
|
24
|
+
assertEquals(3, rs.rangeSize());
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
package com.redcareditor.mate;
|
2
|
+
|
3
|
+
import static org.junit.Assert.*;
|
4
|
+
|
5
|
+
import org.junit.Before;
|
6
|
+
import org.junit.Test;
|
7
|
+
|
8
|
+
import com.redcareditor.onig.Range;
|
9
|
+
|
10
|
+
|
11
|
+
public class FilledRangeSetTest {
|
12
|
+
private RangeSet rs;
|
13
|
+
|
14
|
+
@Before
|
15
|
+
public void setUp() throws Exception {
|
16
|
+
rs = new RangeSet();
|
17
|
+
rs.add(1, 3);
|
18
|
+
rs.add(5, 5);
|
19
|
+
rs.add(10, 15);
|
20
|
+
}
|
21
|
+
|
22
|
+
@Test
|
23
|
+
public void testShouldReportLength() {
|
24
|
+
assertEquals(3, rs.length());
|
25
|
+
}
|
26
|
+
|
27
|
+
@Test
|
28
|
+
public void testShouldReportSize() {
|
29
|
+
assertEquals(10, rs.rangeSize());
|
30
|
+
}
|
31
|
+
|
32
|
+
@Test
|
33
|
+
public void testShouldMergeRanges() {
|
34
|
+
rs.add(14, 16);
|
35
|
+
assertEquals(rs.length(), 3);
|
36
|
+
assertEquals(rs.get(0), new Range(1,3));
|
37
|
+
assertEquals(rs.get(1), new Range(5,5));
|
38
|
+
assertEquals(rs.get(2), new Range(10,16));
|
39
|
+
}
|
40
|
+
|
41
|
+
@Test
|
42
|
+
public void testShouldMergeRanges2() {
|
43
|
+
rs.add(7, 11);
|
44
|
+
assertEquals(rs.length(), 3);
|
45
|
+
assertEquals(rs.get(0), new Range(1,3));
|
46
|
+
assertEquals(rs.get(1), new Range(5,5));
|
47
|
+
assertEquals(rs.get(2), new Range(7,15));
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testShouldMergeTwoRanges() {
|
52
|
+
rs.add(4, 11);
|
53
|
+
assertEquals(rs.length(), 1);
|
54
|
+
assertEquals(rs.get(0), new Range(1,15));
|
55
|
+
}
|
56
|
+
|
57
|
+
@Test
|
58
|
+
public void testShouldMergeAllRanges() {
|
59
|
+
rs.add(1, 20);
|
60
|
+
assertEquals(rs.length(), 1);
|
61
|
+
assertEquals(rs.get(0), new Range(1,20));
|
62
|
+
}
|
63
|
+
|
64
|
+
@Test
|
65
|
+
public void testShouldMergeAdjacentRanges() {
|
66
|
+
rs.add(16, 18);
|
67
|
+
assertEquals(rs.length(), 3);
|
68
|
+
assertEquals(rs.get(0), new Range(1,3));
|
69
|
+
assertEquals(rs.get(1), new Range(5,5));
|
70
|
+
assertEquals(rs.get(2), new Range(10,18));
|
71
|
+
}
|
72
|
+
|
73
|
+
@Test
|
74
|
+
public void testShouldMergeTwoAdjacentRanges() {
|
75
|
+
rs.add(4, 4);
|
76
|
+
assertEquals(rs.length(), 2);
|
77
|
+
assertEquals(rs.get(0), new Range(1,5));
|
78
|
+
assertEquals(rs.get(1), new Range(10,15));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
package com.redcareditor.mate;
|
2
|
+
|
3
|
+
import static org.junit.Assert.*;
|
4
|
+
|
5
|
+
import java.util.ArrayList;
|
6
|
+
import java.util.List;
|
7
|
+
|
8
|
+
import org.junit.Before;
|
9
|
+
import org.junit.Test;
|
10
|
+
|
11
|
+
public class GrammarTest {
|
12
|
+
private Grammar g;
|
13
|
+
|
14
|
+
@Before
|
15
|
+
public void setUp() {
|
16
|
+
g = new Grammar("input/Bundles/Apache.tmbundle/Syntaxes/Apache.plist");
|
17
|
+
g.initForUse();
|
18
|
+
}
|
19
|
+
|
20
|
+
@Test
|
21
|
+
public void shouldLoadGrammarInformation() {
|
22
|
+
assertEquals("Apache", g.name);
|
23
|
+
assertEquals("source.apache-config", g.scopeName);
|
24
|
+
}
|
25
|
+
|
26
|
+
@Test
|
27
|
+
public void shouldLoadJavaScriptInformation() {
|
28
|
+
Grammar jg = new Grammar("input/Bundles/JavaScript.tmbundle/Syntaxes/JavaScript.plist");
|
29
|
+
jg.initForUse();
|
30
|
+
assertEquals("JavaScript", jg.name);
|
31
|
+
// assertEquals("source.apache-config", g.scopeName);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void shouldLoadPatternsIntoMemory() {
|
36
|
+
assertTrue("allPatterns is not empty", g.allPatterns.size() > 0);
|
37
|
+
List<String> patternNames = patternNames(g.allPatterns);
|
38
|
+
assertTrue(patternNames.contains("comment.line.number-sign.apache-config"));
|
39
|
+
assertTrue(patternNames.contains("source.include.apache-config"));
|
40
|
+
assertTrue(patternNames.contains("support.constant.apache-config"));
|
41
|
+
}
|
42
|
+
|
43
|
+
@Test
|
44
|
+
public void shouldLoadPatternsWithoutNames() {
|
45
|
+
Pattern foundPattern = find(g.allPatterns, new Predicate() {
|
46
|
+
public boolean match(Pattern p) {
|
47
|
+
return (p instanceof DoublePattern) &&
|
48
|
+
((DoublePattern)p).bothCaptures != null &&
|
49
|
+
((DoublePattern)p).bothCaptures.values().contains("support.constant.rewritecond.apache-config");
|
50
|
+
}
|
51
|
+
});
|
52
|
+
assertNotNull("Unable to find unnamed rewrite pattern", foundPattern);
|
53
|
+
}
|
54
|
+
|
55
|
+
public void assertNotIncludePattern(Pattern p) {
|
56
|
+
assertFalse(p instanceof IncludePattern);
|
57
|
+
}
|
58
|
+
|
59
|
+
@Test
|
60
|
+
public void shouldReplaceAllIncludePatterns() {
|
61
|
+
for (Pattern p : g.allPatterns) {
|
62
|
+
assertNotIncludePattern(p);
|
63
|
+
if (p instanceof DoublePattern) {
|
64
|
+
for (Pattern p1 : ((DoublePattern)p).patterns) {
|
65
|
+
assertNotIncludePattern(p1);
|
66
|
+
if (p1 instanceof DoublePattern) {
|
67
|
+
for (Pattern p2 : ((DoublePattern)p1).patterns)
|
68
|
+
assertNotIncludePattern(p2);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
@Test
|
76
|
+
public void shouldReplacePatternBaseProperly() {
|
77
|
+
Pattern p = find(g.allPatterns, new Predicate() {
|
78
|
+
public boolean match(Pattern p) {
|
79
|
+
return "meta.vhost.apache-config".equals(p.name);
|
80
|
+
}
|
81
|
+
});
|
82
|
+
if (p instanceof DoublePattern) {
|
83
|
+
List<String> patternNames = patternNames(((DoublePattern)p).patterns);
|
84
|
+
assertTrue(patternNames.contains("meta.vhost.apache-config"));
|
85
|
+
} else {
|
86
|
+
fail("Expected \"meta.vhost.apache-config\" to parse as a DoublePattern.");
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void shouldReplaceVarsProperly() {
|
92
|
+
Pattern pt = find(g.allPatterns, new Predicate() {
|
93
|
+
public boolean match(Pattern p) {
|
94
|
+
return (p instanceof DoublePattern) &&
|
95
|
+
((DoublePattern)p).bothCaptures != null &&
|
96
|
+
((DoublePattern)p).bothCaptures.values().contains("support.constant.rewritecond.apache-config");
|
97
|
+
}
|
98
|
+
});
|
99
|
+
List<String> names = patternNames(((DoublePattern)((DoublePattern)pt).patterns.get(0)).patterns);
|
100
|
+
assertTrue(names.contains("support.variable.apache-config"));
|
101
|
+
assertTrue(names.contains("invalid.illegal.bad-var.apache-config"));
|
102
|
+
}
|
103
|
+
|
104
|
+
@Test
|
105
|
+
public void shouldLoadCaptures() {
|
106
|
+
for (Pattern p : g.allPatterns) {
|
107
|
+
if ("comment.line.number-sign.apache-config".equals(p.name)) {
|
108
|
+
assertEquals("punctuation.definition.comment.apache-config", ((SinglePattern) p).captures.get(1));
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
@Test
|
114
|
+
public void shouldMarkDisabledPatternsAsDisabled() {
|
115
|
+
Bundle.loadBundles("input/");
|
116
|
+
Bundle htmlBundle = Bundle.getBundleByName("HTML");
|
117
|
+
|
118
|
+
Grammar html = null;
|
119
|
+
for (Grammar g : htmlBundle.getGrammars()) {
|
120
|
+
if ("HTML".equals(g.name)) {
|
121
|
+
html = g; break;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
if (html != null) {
|
126
|
+
html.initForUse();
|
127
|
+
Pattern smarty = find(html.allPatterns, new Predicate() {
|
128
|
+
public boolean match(Pattern p) {
|
129
|
+
return "source.smarty.embedded.html".equals(p.name);
|
130
|
+
}
|
131
|
+
});
|
132
|
+
assertTrue(smarty.disabled);
|
133
|
+
} else {
|
134
|
+
fail("Unable to find HTML grammar in HTML bundle.");
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
public ArrayList<String> patternNames(List<Pattern> patterns) {
|
139
|
+
ArrayList<String> result = new ArrayList<String>();
|
140
|
+
for (Pattern p : patterns) {
|
141
|
+
result.add(p.name);
|
142
|
+
}
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
public Pattern find(List<Pattern> patterns, Predicate pred) {
|
147
|
+
for (Pattern p : patterns) {
|
148
|
+
if (pred.match(p)) {
|
149
|
+
return p;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
|
155
|
+
interface Predicate {
|
156
|
+
public boolean match(Pattern p);
|
157
|
+
}
|
158
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
package com.redcareditor.mate;
|
2
|
+
|
3
|
+
import org.eclipse.swt.widgets.Shell;
|
4
|
+
import org.junit.Before;
|
5
|
+
import org.junit.Test;
|
6
|
+
import static org.junit.Assert.*;
|
7
|
+
|
8
|
+
public class MateTextTest {
|
9
|
+
private MateText mt;
|
10
|
+
|
11
|
+
@Before
|
12
|
+
public void setUp() {
|
13
|
+
Bundle.loadBundles("input/");
|
14
|
+
Shell shell = new Shell();
|
15
|
+
mt = new MateText(shell);
|
16
|
+
}
|
17
|
+
|
18
|
+
@Test
|
19
|
+
public void shouldSetTheGrammarByName() {
|
20
|
+
assertTrue(mt.setGrammarByName("Ruby"));
|
21
|
+
assertEquals("Ruby", mt.parser.grammar.name);
|
22
|
+
}
|
23
|
+
|
24
|
+
@Test
|
25
|
+
public void shouldSetTheGrammarByFilename() {
|
26
|
+
assertEquals("Ruby", mt.setGrammarByFilename("foo.rb"));
|
27
|
+
assertEquals("Apache", mt.setGrammarByFilename(".htaccess"));
|
28
|
+
assertEquals("Ruby", mt.setGrammarByFilename("Rakefile"));
|
29
|
+
}
|
30
|
+
|
31
|
+
@Test
|
32
|
+
public void shouldSetTheGrammarByFirstLine() {
|
33
|
+
assertEquals("Ruby", mt.setGrammarByFirstLine("#!/usr/bin/ruby\n"));
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
package com.redcareditor.mate;
|
3
|
+
|
4
|
+
import static org.junit.Assert.*;
|
5
|
+
import org.junit.Test;
|
6
|
+
|
7
|
+
public class ScopeMatcherMatchingTest {
|
8
|
+
public boolean testMatch(String a, String b) {
|
9
|
+
return ScopeMatcher.testMatch(a, b);
|
10
|
+
}
|
11
|
+
|
12
|
+
@Test
|
13
|
+
public void shouldMatchSimpleWords() {
|
14
|
+
assertTrue(testMatch("comment", "ruby.comment"));
|
15
|
+
assertFalse(testMatch("string", "ruby.comment"));
|
16
|
+
assertTrue(testMatch("source.ruby", "source.ruby comment"));
|
17
|
+
}
|
18
|
+
|
19
|
+
@Test
|
20
|
+
public void shouldNotMatchSubstrings() {
|
21
|
+
assertFalse(testMatch("source.c", "source.coffee"));
|
22
|
+
}
|
23
|
+
|
24
|
+
@Test
|
25
|
+
public void shouldTransformDots() {
|
26
|
+
assertFalse(testMatch("source.ruby", "sourcearuby comment"));
|
27
|
+
assertTrue(testMatch("source.ruby", "source.ruby comment"));
|
28
|
+
}
|
29
|
+
|
30
|
+
@Test
|
31
|
+
public void shouldMatchAtSeparateLocationsInTheString() {
|
32
|
+
assertTrue(testMatch("ruby string", "ruby interpolated string.quoted"));
|
33
|
+
}
|
34
|
+
|
35
|
+
@Test
|
36
|
+
public void shouldMatchWithSelectorOrs() {
|
37
|
+
assertTrue(testMatch("string, comment", "ruby.string"));
|
38
|
+
assertTrue(testMatch("string, comment", "ruby.comment"));
|
39
|
+
}
|
40
|
+
|
41
|
+
@Test
|
42
|
+
public void shouldDealWithNegativeMatches() {
|
43
|
+
assertTrue(testMatch("string - string.double", "ruby.string"));
|
44
|
+
assertFalse(testMatch("string - string.double", "ruby.string.double"));
|
45
|
+
}
|
46
|
+
|
47
|
+
@Test
|
48
|
+
public void shouldDealWithMultipleNegativeMatches() {
|
49
|
+
assertFalse(testMatch("string - string.double - comment", "ruby.string.double"));
|
50
|
+
assertFalse(testMatch("string - string.double - comment", "ruby.string.comment"));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
package com.redcareditor.mate;
|
3
|
+
|
4
|
+
import static org.junit.Assert.*;
|
5
|
+
|
6
|
+
import org.junit.Test;
|
7
|
+
|
8
|
+
public class ScopeMatcherRankingTest {
|
9
|
+
public String testRank(String a, String b, String scope) {
|
10
|
+
return ScopeMatcher.testRank(a, b, scope);
|
11
|
+
}
|
12
|
+
|
13
|
+
@Test
|
14
|
+
public void shouldRankTwoMatchesByTheirElementDepth() {
|
15
|
+
assertEquals("string", testRank("string", "ruby", "ruby string"));
|
16
|
+
}
|
17
|
+
|
18
|
+
@Test
|
19
|
+
public void shouldRankTwoMatchesByElementDepthNotStringDepth() {
|
20
|
+
assertEquals("string == quoted", testRank("string", "quoted", "string.quoted"));
|
21
|
+
}
|
22
|
+
|
23
|
+
@Test
|
24
|
+
public void shouldRankTwoMatchesByTheLengthOfTheMatch() {
|
25
|
+
assertEquals("string.quoted", testRank("string.quoted", "string", "string.quoted"));
|
26
|
+
}
|
27
|
+
|
28
|
+
@Test
|
29
|
+
public void shouldMoveUpTheElementMatchesInCaseOfATieAndCheckElementDepth() {
|
30
|
+
assertEquals("ruby string", testRank("ruby string", "source string", "source ruby string"));
|
31
|
+
assertEquals("ruby string", testRank("source string", "ruby string", "source ruby string"));
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void shouldMoveUpTheElementMatchesInCaseOfATieAndCheckMatchLength() {
|
36
|
+
assertEquals("source.ruby string", testRank("ruby string", "source.ruby string", "source.ruby string"));
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
package com.redcareditor.onig;
|
2
|
+
|
3
|
+
import java.io.BufferedReader;
|
4
|
+
import java.io.StringReader;
|
5
|
+
|
6
|
+
import org.junit.Test;
|
7
|
+
import static org.junit.Assert.*;
|
8
|
+
|
9
|
+
import com.redcareditor.util.FileUtility;
|
10
|
+
|
11
|
+
public class RxTest {
|
12
|
+
@Test
|
13
|
+
public void testSingleFoo() {
|
14
|
+
String pattern = "^\\s*(class)\\s+(([.a-zA-Z0-9_:]+(\\s*(<)\\s*[.a-zA-Z0-9_:]+)?)|((<<)\\s*[.a-zA-Z0-9_:]+))+";
|
15
|
+
String fileContents = "";
|
16
|
+
try {
|
17
|
+
fileContents = new String(FileUtility.readFully("input/autocompleter.rb"));
|
18
|
+
|
19
|
+
BufferedReader reader = new BufferedReader(new StringReader(fileContents));
|
20
|
+
|
21
|
+
Rx regex = Rx.createRx(pattern);
|
22
|
+
|
23
|
+
String line;
|
24
|
+
while ((line = reader.readLine()) != null) {
|
25
|
+
Match m = regex.search(line, 0, line.length());
|
26
|
+
|
27
|
+
if (m != null) {
|
28
|
+
System.out.println(line);
|
29
|
+
for (Range r : m) {
|
30
|
+
System.out.println(r);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
} catch (Exception e) {
|
35
|
+
e.printStackTrace();
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
@Test
|
40
|
+
public void testNullObject() {
|
41
|
+
String pattern = null;
|
42
|
+
Rx rx = Rx.createRx(pattern);
|
43
|
+
assertTrue(rx instanceof Rx);
|
44
|
+
assertTrue(rx instanceof NullRx);
|
45
|
+
|
46
|
+
Match match = rx.search("baz");
|
47
|
+
assertTrue(match instanceof NullMatch);
|
48
|
+
// now check that the object behaves in a reasonable way.
|
49
|
+
|
50
|
+
assertEquals(0, match.numCaptures());
|
51
|
+
assertFalse(match.iterator().hasNext());
|
52
|
+
assertEquals(0, match.ranges().size());
|
53
|
+
}
|
54
|
+
}
|