-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate vscode-textmate from TypeScript to Java to support
tokenizeLine2. See #38
- Loading branch information
1 parent
81fcb8d
commit b28d76f
Showing
335 changed files
with
1,185,063 additions
and
394 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
....tm4e.core.tests/src/test/java/org/eclipse/tm4e/core/tests/grammar/VSCodeGrammarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright (c) 2015-2017 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.tests.grammar; | ||
|
||
import org.eclipse.tm4e.core.internal.grammar.StackElementMetadata; | ||
import org.eclipse.tm4e.core.internal.grammar.StandardTokenType; | ||
import org.eclipse.tm4e.core.theme.FontStyle; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* {@link StackElementMetadata} tests same than vscode-textmate. | ||
* | ||
* @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/grammar.test.ts | ||
* | ||
*/ | ||
public class VSCodeGrammarTest { | ||
|
||
@Test | ||
public void works() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
} | ||
|
||
@Test | ||
public void canOverwriteLanguageId() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
|
||
value = StackElementMetadata.set(value, 2, StandardTokenType.Other, FontStyle.NotSet, 0, 0); | ||
assertEquals(value, 2, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
} | ||
|
||
@Test | ||
public void canOverwriteTokenType() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
|
||
value = StackElementMetadata.set(value, 0, StandardTokenType.Comment, FontStyle.NotSet, 0, 0); | ||
assertEquals(value, 1, StandardTokenType.Comment, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
} | ||
|
||
@Test | ||
public void canOverwriteFontStyle() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
|
||
value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.None, 0, 0); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.None, 101, 102); | ||
} | ||
|
||
@Test | ||
public void canOverwriteForeground() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
|
||
value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 5, 0); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 5, 102); | ||
} | ||
|
||
@Test | ||
public void canOverwriteBackground() { | ||
int value = StackElementMetadata.set(0, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, | ||
102); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 102); | ||
|
||
value = StackElementMetadata.set(value, 0, StandardTokenType.Other, FontStyle.NotSet, 0, 7); | ||
assertEquals(value, 1, StandardTokenType.RegEx, FontStyle.Underline | FontStyle.Bold, 101, 7); | ||
} | ||
|
||
@Test | ||
public void canWorkAtMaxValues() { | ||
int maxLangId = 255; | ||
int maxTokenType = StandardTokenType.Comment | StandardTokenType.Other | StandardTokenType.RegEx | ||
| StandardTokenType.String; | ||
int maxFontStyle = FontStyle.Bold | FontStyle.Italic | FontStyle.Underline; | ||
int maxForeground = 511; | ||
int maxBackground = 511; | ||
|
||
int value = StackElementMetadata.set(0, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); | ||
assertEquals(value, maxLangId, maxTokenType, maxFontStyle, maxForeground, maxBackground); | ||
} | ||
|
||
private static void assertEquals(int metadata, int languageId, int tokenType, int fontStyle, int foreground, int background) { | ||
String actual = "{\n" + | ||
"languageId: " + StackElementMetadata.getLanguageId(metadata) + ",\n" + | ||
"tokenType: " + StackElementMetadata.getTokenType(metadata) + ",\n" + | ||
"fontStyle: " + StackElementMetadata.getFontStyle(metadata) + ",\n" + | ||
"foreground: " + StackElementMetadata.getForeground(metadata) + ",\n" + | ||
"background: " + StackElementMetadata.getBackground(metadata) + ",\n" + | ||
"}"; | ||
|
||
String expected = "{\n" + | ||
"languageId: " + languageId + ",\n" + | ||
"tokenType: " + tokenType + ",\n" + | ||
"fontStyle: " + fontStyle + ",\n" + | ||
"foreground: " + foreground + ",\n" + | ||
"background: " + background + ",\n" + | ||
"}"; | ||
|
||
Assert.assertEquals("equals for " + StackElementMetadata.toBinaryStr(metadata), expected, actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.grammar.test; | ||
package org.eclipse.tm4e.core.tests.grammar; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
|
@@ -17,6 +17,8 @@ | |
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.tm4e.core.tests.grammar.internal.MatcherTestImpl; | ||
import org.eclipse.tm4e.core.tests.grammar.internal.RawTestImpl; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.AllTests; | ||
|
||
|
@@ -25,6 +27,13 @@ | |
|
||
import junit.framework.TestSuite; | ||
|
||
/** | ||
* VSCode TextMate grammar tests which uses same vscode-textmate tests located | ||
* at src\test\resources\test-cases | ||
* | ||
* @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/tests.ts | ||
* | ||
*/ | ||
@RunWith(AllTests.class) | ||
public class VSCodeTextMateTest { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.grammar.test; | ||
package org.eclipse.tm4e.core.tests.grammar.internal; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.grammar.test; | ||
package org.eclipse.tm4e.core.tests.grammar.internal; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
@@ -23,7 +23,7 @@ | |
import org.eclipse.tm4e.core.grammar.ITokenizeLineResult; | ||
import org.eclipse.tm4e.core.grammar.StackElement; | ||
import org.eclipse.tm4e.core.logger.SystemLogger; | ||
import org.eclipse.tm4e.core.registry.IGrammarLocator; | ||
import org.eclipse.tm4e.core.registry.IRegistryOptions; | ||
import org.eclipse.tm4e.core.registry.Registry; | ||
import org.junit.Assert; | ||
import org.junit.runner.Describable; | ||
|
@@ -84,7 +84,7 @@ public int countTestCases() { | |
} | ||
|
||
private static void executeTest(RawTestImpl test, File testLocation) throws Exception { | ||
IGrammarLocator locator = new IGrammarLocator() { | ||
IRegistryOptions locator = new IRegistryOptions() { | ||
|
||
@Override | ||
public String getFilePath(String scopeName) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.grammar.test; | ||
package org.eclipse.tm4e.core.tests.grammar.internal; | ||
|
||
import java.util.List; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.grammar.test; | ||
package org.eclipse.tm4e.core.tests.grammar.internal; | ||
|
||
import java.util.List; | ||
|
||
|
54 changes: 54 additions & 0 deletions
54
...ipse.tm4e.core.tests/src/test/java/org/eclipse/tm4e/core/tests/theme/VSCodeThemeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.eclipse.tm4e.core.tests.theme; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.tm4e.core.internal.theme.reader.ThemeReader; | ||
import org.eclipse.tm4e.core.theme.ColorMap; | ||
import org.eclipse.tm4e.core.theme.FontStyle; | ||
import org.eclipse.tm4e.core.theme.Theme; | ||
import org.eclipse.tm4e.core.theme.ThemeTrieElementRule; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @see https://github.com/Microsoft/vscode-textmate/blob/master/src/tests/themes.test.ts | ||
* | ||
*/ | ||
public class VSCodeThemeTest { | ||
|
||
@Test | ||
public void givesHigherPriorityToDeeperMatches() throws Exception { | ||
Theme theme = loadTheme("{" + | ||
"\"settings\": ["+ | ||
"{ \"settings\": { \"foreground\": \"#100000\", \"background\": \"#200000\" } },"+ | ||
"{ \"scope\": \"punctuation.definition.string.begin.html\", \"settings\": { \"foreground\": \"#300000\" } },"+ | ||
"{ \"scope\": \"meta.tag punctuation.definition.string\", \"settings\": { \"foreground\": \"#400000\" } }"+ | ||
// { scope: 'a', settings: { foreground: '#500000' } }, | ||
"]"+ | ||
"}"); | ||
|
||
|
||
ColorMap colorMap = new ColorMap(); | ||
int _NOT_SET = 0; | ||
int _A = colorMap.getId("#100000"); | ||
int _B = colorMap.getId("#200000"); | ||
int _C = colorMap.getId("#400000"); | ||
int _D = colorMap.getId("#300000"); | ||
|
||
List<ThemeTrieElementRule> actual = theme.match("punctuation.definition.string.begin.html"); | ||
|
||
/*Assert.assertEquals(actual, Arrays.asList( | ||
new ThemeTrieElementRule(5, null, FontStyle.NotSet, _D, _NOT_SET), | ||
new ThemeTrieElementRule(3, Arrays.asList("meta.tag"), FontStyle.NotSet, _C, _NOT_SET) | ||
));*/ | ||
|
||
|
||
} | ||
|
||
private Theme loadTheme(String theme) throws Exception { | ||
return Theme.createFromRawTheme(ThemeReader.JSON_PARSER.parse(new ByteArrayInputStream(theme.getBytes()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
org.eclipse.tm4e.core.tests/src/test/resources/test-cases/themes/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/tests/*.diff.html |
Oops, something went wrong.