Skip to content

Commit

Permalink
Translate vscode-textmate from TypeScript to Java to support
Browse files Browse the repository at this point in the history
tokenizeLine2. See #38
  • Loading branch information
angelozerr committed May 10, 2017
1 parent 81fcb8d commit a2d9f98
Show file tree
Hide file tree
Showing 334 changed files with 1,184,941 additions and 394 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@
"value": "html",
"scopes": [
"text.jade",
"meta.tag.other entity.name.tag.jade"
"meta.tag.other",
"entity.name.tag.jade"
]
}
]
Expand All @@ -609,7 +610,8 @@
"value": "head",
"scopes": [
"text.jade",
"meta.tag.other entity.name.tag.jade"
"meta.tag.other",
"entity.name.tag.jade"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/*.diff.html
Loading

0 comments on commit a2d9f98

Please sign in to comment.