提交 7547666e 编写于 作者: A Alex Dima

PHP mode tests should not depend on Typescript mode

上级 814e85a1
......@@ -4,9 +4,11 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as modes from 'vs/editor/common/modes';
import {IMode, IState, IStream, ITokenizationResult, ITokenizationSupport} from 'vs/editor/common/modes';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
import {TokenizationSupport} from 'vs/editor/common/modes/supports/tokenizationSupport';
export class MockMode implements modes.IMode {
export class MockMode implements IMode {
private _id:string;
......@@ -18,7 +20,43 @@ export class MockMode implements modes.IMode {
return this._id;
}
public toSimplifiedMode(): modes.IMode {
public toSimplifiedMode(): IMode {
return this;
}
}
export class StateForMockTokenizingMode extends AbstractState {
private _tokenType: string;
constructor(mode:IMode, tokenType:string) {
super(mode);
this._tokenType = tokenType;
}
public makeClone():StateForMockTokenizingMode {
return this;
}
public equals(other:IState):boolean {
return true;
}
public tokenize(stream:IStream):ITokenizationResult {
stream.advanceToEOS();
return { type: this._tokenType };
}
}
export class MockTokenizingMode extends MockMode {
public tokenizationSupport: ITokenizationSupport;
constructor(id:string, tokenType:string) {
super(id);
this.tokenizationSupport = new TokenizationSupport(this, {
getInitialState: () => new StateForMockTokenizingMode(this, tokenType)
}, false, false);
}
}
......@@ -19,42 +19,15 @@ import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService';
import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {HTMLMode} from 'vs/languages/html/common/html';
import htmlWorker = require('vs/languages/html/common/htmlWorker');
import {MockMode} from 'vs/editor/test/common/mocks/mockMode';
import {TokenizationSupport} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
import {MockTokenizingMode} from 'vs/editor/test/common/mocks/mockMode';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
export class MockJSState extends AbstractState {
export class MockJSMode extends MockTokenizingMode {
constructor(mode:Modes.IMode, stateCount:number) {
super(mode);
}
public makeClone():MockJSState {
return this;
}
public equals(other:Modes.IState):boolean {
return true;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
stream.advanceToEOS();
return { type: 'mock-js' };
}
}
export class MockJSMode extends MockMode {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
constructor() {
super();
this.tokenizationSupport = new TokenizationSupport(this, {
getInitialState: () => new MockJSState(this, 0)
}, false, false);
super('js', 'mock-js');
this.richEditSupport = new RichEditSupport(this.getId(), null, {
brackets: [
......@@ -117,7 +90,7 @@ suite('Colorizing - HTML', () => {
let tokenizationSupport: Modes.ITokenizationSupport;
let _mode: Modes.IMode;
suiteSetup(() => {
(function() {
let threadService = NULL_THREAD_SERVICE;
let modeService = new HTMLMockModeService();
let inst = createInstantiationService({
......@@ -134,7 +107,7 @@ suite('Colorizing - HTML', () => {
);
tokenizationSupport = _mode.tokenizationSupport;
});
})();
test('Open Start Tag #1', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
......
......@@ -11,42 +11,7 @@ import {MockModeService} from 'vs/editor/test/common/mocks/mockModeService';
import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService';
import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {LESSMode} from 'vs/languages/less/common/less';
import {MockMode} from 'vs/editor/test/common/mocks/mockMode';
import {TokenizationSupport} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {AbstractState} from 'vs/editor/common/modes/abstractState';
export class MockJSState extends AbstractState {
constructor(mode:Modes.IMode, stateCount:number) {
super(mode);
}
public makeClone():MockJSState {
return this;
}
public equals(other:Modes.IState):boolean {
return true;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
stream.advanceToEOS();
return { type: 'mock-js' };
}
}
export class MockJSMode extends MockMode {
public tokenizationSupport: Modes.ITokenizationSupport;
constructor() {
super();
this.tokenizationSupport = new TokenizationSupport(this, {
getInitialState: () => new MockJSState(this, 0)
}, false, false);
}
}
import {MockTokenizingMode} from 'vs/editor/test/common/mocks/mockMode';
class LESSMockModeService extends MockModeService {
isRegisteredMode(mimetypeOrModeId: string): boolean {
......@@ -58,7 +23,7 @@ class LESSMockModeService extends MockModeService {
getMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): Modes.IMode {
if (commaSeparatedMimetypesOrCommaSeparatedIds === 'javascript') {
return new MockJSMode();
return new MockTokenizingMode('js', 'mock-js');
}
throw new Error('Not implemented');
}
......@@ -76,7 +41,7 @@ suite('LESS-tokenization', () => {
let tokenizationSupport: Modes.ITokenizationSupport;
let assertOnEnter: modesUtil.IOnEnterAsserter;
setup(() => {
(function() {
let threadService = NULL_THREAD_SERVICE;
let modeService = new LESSMockModeService();
let inst = createInstantiationService({
......@@ -96,7 +61,7 @@ suite('LESS-tokenization', () => {
tokenizationSupport = mode.tokenizationSupport;
assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport);
});
})();
test('', () => {
modesUtil.executeTests(tokenizationSupport, [
......
......@@ -4,15 +4,42 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/languages/php/common/php.contribution';
import 'vs/languages/html/common/html.contribution';
import 'vs/languages/typescript/common/typescript.contribution';
import 'vs/languages/css/common/css.contribution';
import Modes = require('vs/editor/common/modes');
import modesUtil = require('vs/editor/test/common/modesUtil');
import {htmlTokenTypes} from 'vs/languages/html/common/html';
import {HTMLMode, htmlTokenTypes} from 'vs/languages/html/common/html';
import {cssTokenTypes} from 'vs/languages/css/common/css';
import {MockModeService} from 'vs/editor/test/common/mocks/mockModeService';
import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService';
import {createInstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {PHPMode} from 'vs/languages/php/common/php';
import {MockTokenizingMode} from 'vs/editor/test/common/mocks/mockMode';
class PHPMockModeService extends MockModeService {
private _htmlMode: HTMLMode<any>;
constructor() {
super();
this._htmlMode = null;
}
setHTMLMode(htmlMode: HTMLMode<any>) {
this._htmlMode = htmlMode;
}
getMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): Modes.IMode {
if (commaSeparatedMimetypesOrCommaSeparatedIds === 'text/html') {
return this._htmlMode;
}
if (commaSeparatedMimetypesOrCommaSeparatedIds === 'text/javascript') {
return new MockTokenizingMode('js', 'mock-js');
}
if (commaSeparatedMimetypesOrCommaSeparatedIds === 'text/css') {
return new MockTokenizingMode('css', 'mock-css');
}
throw new Error('Not implemented');
}
}
suite('Syntax Highlighting - PHP', () => {
......@@ -21,14 +48,32 @@ suite('Syntax Highlighting - PHP', () => {
var tokenizationSupport: Modes.ITokenizationSupport;
var assertOnEnter: modesUtil.IOnEnterAsserter;
setup((done) => {
modesUtil.load('php', ['html', 'javascript', 'css']).then(mode => {
tokenizationSupport = mode.tokenizationSupport;
assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport);
wordDefinition = mode.richEditSupport.wordDefinition;
done();
(function() {
let threadService = NULL_THREAD_SERVICE;
let modeService = new PHPMockModeService();
let inst = createInstantiationService({
threadService: threadService,
modeService: modeService
});
});
threadService.setInstantiationService(inst);
modeService.setHTMLMode(new HTMLMode<any>(
{ id: 'html' },
inst,
modeService,
threadService
));
let mode = new PHPMode(
{ id: 'php' },
modeService,
null
);
tokenizationSupport = mode.tokenizationSupport;
assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport);
wordDefinition = mode.richEditSupport.wordDefinition;
})();
test('', () => {
modesUtil.executeTests(tokenizationSupport, [
......@@ -1685,13 +1730,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: htmlTokenTypes.getTag('script') },
{ startIndex:12, type: htmlTokenTypes.DELIM_START },
{ startIndex:13, type: 'keyword.js' },
{ startIndex:16, type: '' },
{ startIndex:17, type: 'identifier.js' },
{ startIndex:18, type: 'delimiter.js' },
{ startIndex:19, type: '' },
{ startIndex:20, type: 'number.js' },
{ startIndex:22, type: 'delimiter.js' },
{ startIndex:13, type: 'mock-js' },
{ startIndex:23, type: htmlTokenTypes.DELIM_END },
{ startIndex:25, type: htmlTokenTypes.getTag('script') },
{ startIndex:31, type: htmlTokenTypes.DELIM_END },
......@@ -1715,13 +1754,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: htmlTokenTypes.getTag('script') },
{ startIndex:12, type: htmlTokenTypes.DELIM_START },
{ startIndex:13, type: 'keyword.js' },
{ startIndex:16, type: '' },
{ startIndex:17, type: 'identifier.js' },
{ startIndex:18, type: 'delimiter.js' },
{ startIndex:19, type: '' },
{ startIndex:20, type: 'number.js' },
{ startIndex:22, type: 'delimiter.js' },
{ startIndex:13, type: 'mock-js' },
{ startIndex:23, type: htmlTokenTypes.DELIM_END },
{ startIndex:25, type: htmlTokenTypes.getTag('script') },
{ startIndex:31, type: htmlTokenTypes.DELIM_END },
......@@ -1733,13 +1766,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:42, type: htmlTokenTypes.DELIM_START },
{ startIndex:43, type: htmlTokenTypes.getTag('script') },
{ startIndex:49, type: htmlTokenTypes.DELIM_START },
{ startIndex:50, type: 'keyword.js' },
{ startIndex:53, type: '' },
{ startIndex:54, type: 'identifier.js' },
{ startIndex:55, type: 'delimiter.js' },
{ startIndex:56, type: '' },
{ startIndex:57, type: 'number.js' },
{ startIndex:59, type: 'delimiter.js' },
{ startIndex:50, type: 'mock-js' },
{ startIndex:60, type: htmlTokenTypes.DELIM_END },
{ startIndex:62, type: htmlTokenTypes.getTag('script') },
{ startIndex:68, type: htmlTokenTypes.DELIM_END }
......@@ -1761,14 +1788,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:7, type: 'metatag.php' },
{ startIndex:10, type: 'string.php' },
{ startIndex:15, type: 'metatag.php' },
{ startIndex:17, type: 'punctuation.bracket.css' },
{ startIndex:18, type: '' },
{ startIndex:19, type: cssTokenTypes.TOKEN_PROPERTY + '.css' },
{ startIndex:24, type: 'punctuation.css' },
{ startIndex:25, type: cssTokenTypes.TOKEN_VALUE + '.css' },
{ startIndex:29, type: 'punctuation.css' },
{ startIndex:30, type: '' },
{ startIndex:31, type: 'punctuation.bracket.css' },
{ startIndex:17, type: 'mock-css' },
{ startIndex:32, type: htmlTokenTypes.DELIM_END },
{ startIndex:34, type: htmlTokenTypes.getTag('style') },
{ startIndex:39, type: htmlTokenTypes.DELIM_END }
......@@ -1781,14 +1801,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:7, type: 'metatag.php' },
{ startIndex:10, type: 'string.php' },
{ startIndex:15, type: 'metatag.php' },
{ startIndex:17, type: 'punctuation.bracket.css' },
{ startIndex:18, type: '' },
{ startIndex:19, type: cssTokenTypes.TOKEN_PROPERTY + '.css' },
{ startIndex:24, type: 'punctuation.css' },
{ startIndex:25, type: cssTokenTypes.TOKEN_VALUE + '.css' },
{ startIndex:29, type: 'punctuation.css' },
{ startIndex:30, type: '' },
{ startIndex:31, type: 'punctuation.bracket.css' },
{ startIndex:17, type: 'mock-css' },
{ startIndex:32, type: htmlTokenTypes.DELIM_END },
{ startIndex:34, type: htmlTokenTypes.getTag('style') },
{ startIndex:39, type: htmlTokenTypes.DELIM_END }
......@@ -1807,15 +1820,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:13, type: 'metatag.php' },
{ startIndex:16, type: 'string.php' },
{ startIndex:21, type: 'metatag.php' },
{ startIndex:23, type: '' },
{ startIndex:24, type: 'punctuation.bracket.css' },
{ startIndex:25, type: '' },
{ startIndex:26, type: cssTokenTypes.TOKEN_PROPERTY + '.css' },
{ startIndex:31, type: 'punctuation.css' },
{ startIndex:32, type: cssTokenTypes.TOKEN_VALUE + '.css' },
{ startIndex:36, type: 'punctuation.css' },
{ startIndex:37, type: '' },
{ startIndex:38, type: 'punctuation.bracket.css' },
{ startIndex:23, type: 'mock-css' },
{ startIndex:39, type: htmlTokenTypes.DELIM_END },
{ startIndex:41, type: htmlTokenTypes.getTag('style') },
{ startIndex:46, type: htmlTokenTypes.DELIM_END },
......@@ -1827,28 +1832,12 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:73, type: htmlTokenTypes.DELIM_START },
{ startIndex:74, type: htmlTokenTypes.getTag('script') },
{ startIndex:80, type: htmlTokenTypes.DELIM_START },
{ startIndex:81, type: 'keyword.js' },
{ startIndex:84, type: '' },
{ startIndex:85, type: 'identifier.js' },
{ startIndex:86, type: '' },
{ startIndex:87, type: 'delimiter.js' },
{ startIndex:88, type: '' },
{ startIndex:89, type: 'number.js' },
{ startIndex:90, type: 'delimiter.js' },
{ startIndex:91, type: 'comment.js' },
{ startIndex:81, type: 'mock-js' },
{ startIndex:94, type: 'metatag.php' },
{ startIndex:97, type: 'string.php' },
{ startIndex:109, type: 'comment.php' },
{ startIndex:122, type: 'metatag.php' },
{ startIndex:124, type: 'comment.js' },
{ startIndex:127, type: 'keyword.js' },
{ startIndex:130, type: '' },
{ startIndex:131, type: 'identifier.js' },
{ startIndex:132, type: '' },
{ startIndex:133, type: 'delimiter.js' },
{ startIndex:134, type: '' },
{ startIndex:135, type: 'number.js' },
{ startIndex:136, type: 'delimiter.js' },
{ startIndex:124, type: 'mock-js' },
{ startIndex:137, type: htmlTokenTypes.DELIM_END },
{ startIndex:139, type: htmlTokenTypes.getTag('script') },
{ startIndex:145, type: htmlTokenTypes.DELIM_END },
......@@ -1882,7 +1871,7 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: htmlTokenTypes.DELIM_START },
{ startIndex:8, type: 'comment.js' },
{ startIndex:8, type: 'mock-js' },
{ startIndex:10, type: 'metatag.php' }
]}],
......@@ -1892,13 +1881,13 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: htmlTokenTypes.DELIM_START },
{ startIndex:8, type: 'string.js' },
{ startIndex:8, type: 'mock-js' },
{ startIndex:9, type: 'metatag.php' },
{ startIndex:14, type: 'number.php' },
{ startIndex:15, type: 'delimiter.php' },
{ startIndex:16, type: 'number.php' },
{ startIndex:17, type: 'metatag.php' },
{ startIndex:19, type: 'string.js' }
{ startIndex:19, type: 'mock-js' }
]}],
[{
......
......@@ -4,23 +4,29 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/languages/typescript/common/typescript.contribution';
import Modes = require('vs/editor/common/modes');
import modesUtil = require('vs/editor/test/common/modesUtil');
import {NULL_THREAD_SERVICE} from 'vs/platform/test/common/nullThreadService';
import {JavaScriptMode} from 'vs/languages/typescript/common/mode';
suite('TS/JS - syntax highlighting', () => {
var tokenizationSupport: Modes.ITokenizationSupport;
var assertOnEnter: modesUtil.IOnEnterAsserter;
setup((done) => {
modesUtil.load('javascript').then(mode => {
tokenizationSupport = mode.tokenizationSupport;
assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport);
done();
});
setup(() => {
let threadService = NULL_THREAD_SERVICE;
let mode = new JavaScriptMode(
{ id: 'javascript' },
threadService,
null,
null
);
tokenizationSupport = mode.tokenizationSupport;
assertOnEnter = modesUtil.createOnEnterAsserter(mode.getId(), mode.richEditSupport);
});
test('onEnter', function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册