123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- import {testTokenization} from './testRunner';
- testTokenization('xml', [
- // Complete Start Tag with Whitespace
- [{
- line: '<person>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-person.xml' },
- { startIndex: 7, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<person/>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-person.xml' },
- { startIndex: 8, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<person >',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-person.xml' },
- { startIndex: 7, type: '' },
- { startIndex: 8, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<person />',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-person.xml' },
- { startIndex: 7, type: '' },
- { startIndex: 8, type: 'tag.tag-person.xml' },
- { startIndex: 9, type: 'delimiter.start.xml' }
- ]}],
- // Incomplete Start Tag
- [{
- line: '<',
- tokens: [
- { startIndex: 0, type: '' }
- ]}],
- [{
- line: '<person',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-person.xml' }
- ]}],
- [{
- line: '<input',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-input.xml' }
- ]}],
- // Invalid Open Start Tag
- [{
- line: '< person',
- tokens: [
- { startIndex: 0, type: '' }
- ]}],
- [{
- line: '< person>',
- tokens: [
- { startIndex: 0, type: '' }
- ]}],
- [{
- line: 'i <person;',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 2, type: 'delimiter.start.xml' },
- { startIndex: 3, type: 'tag.tag-person.xml' },
- { startIndex: 9, type: '' }
- ]}],
- // Tag with Attribute
- [{
- line: '<tool name="">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 13, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<tool name="Monaco">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 19, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<tool name=\'Monaco\'>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 19, type: 'delimiter.start.xml' }
- ]}],
- // Tag with Attributes
- [{
- line: '<tool name="Monaco" version="1.0">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 19, type: '' },
- { startIndex: 20, type: 'attribute.name.xml' },
- { startIndex: 27, type: '' },
- { startIndex: 28, type: 'attribute.value.xml' },
- { startIndex: 33, type: 'delimiter.start.xml' }
- ]}],
- // Tag with Name-Only-Attribute
- [{
- line: '<tool name>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<tool name version>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.name.xml' },
- { startIndex: 18, type: 'delimiter.start.xml' }
- ]}],
- // Tag with Attribute And Whitespace
- [{
- line: '<tool name= "monaco">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 13, type: 'attribute.value.xml' },
- { startIndex: 21, type: 'delimiter.start.xml' }
- ]}],
- [{
- line: '<tool name = "monaco">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 13, type: 'attribute.value.xml' },
- { startIndex: 21, type: 'delimiter.start.xml' }
- ]}],
- // Tag with Invalid Attribute Name
- [{
- line: '<tool name!@#="bar">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 15, type: 'attribute.name.xml' },
- { startIndex: 18, type: '' },
- { startIndex: 19, type: 'delimiter.start.xml' }
- ]}],
- // Tag with Invalid Attribute Value
- [{
- line: '<tool name=">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tool.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 12, type: 'delimiter.start.xml' }
- ]}],
- // Complete End Tag
- [{
- line: '</person>',
- tokens: [
- { startIndex: 0, type: 'delimiter.end.xml' },
- { startIndex: 2, type: 'tag.tag-person.xml' },
- { startIndex: 8, type: 'delimiter.end.xml' }
- ]}],
- // Complete End Tag with Whitespace
- [{
- line: '</person >',
- tokens: [
- { startIndex: 0, type: 'delimiter.end.xml' },
- { startIndex: 2, type: 'tag.tag-person.xml' },
- { startIndex: 8, type: '' },
- { startIndex: 10, type: 'delimiter.end.xml' }
- ]}],
- // Incomplete End Tag
- [{
- line: '</person',
- tokens: [
- { startIndex: 0, type: '' }
- ]}],
- // Comments
- [{
- line: '<!-- -->',
- tokens: [
- { startIndex: 0, type: 'comment.xml' },
- { startIndex: 4, type: 'comment.content.xml' },
- { startIndex: 5, type: 'comment.xml' }
- ]}],
- [{
- line: '<!--a>monaco</a -->',
- tokens: [
- { startIndex: 0, type: 'comment.xml' },
- { startIndex: 4, type: 'comment.content.xml' },
- { startIndex: 16, type: 'comment.xml' }
- ]}],
- [{
- line: '<!--a>',
- tokens: [
- { startIndex: 0, type: 'comment.xml' },
- { startIndex: 4, type: 'comment.content.xml' }
- ]},{
- line: 'monaco ',
- tokens: [
- { startIndex: 0, type: 'comment.content.xml' }
- ]},{
- line: 'tools</a -->',
- tokens: [
- { startIndex: 0, type: 'comment.content.xml' },
- { startIndex: 9, type: 'comment.xml' }
- ]}],
- // CDATA
- [{
- line: '<tools><![CDATA[<person/>]]></tools>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tools.xml' },
- { startIndex: 6, type: 'delimiter.start.xml' },
- { startIndex: 7, type: 'delimiter.cdata.xml' },
- { startIndex: 16, type: '' },
- { startIndex: 25, type: 'delimiter.cdata.xml' },
- { startIndex: 28, type: 'delimiter.end.xml' },
- { startIndex: 30, type: 'tag.tag-tools.xml' },
- { startIndex: 35, type: 'delimiter.end.xml' }
- ]}],
- [{
- line: '<tools>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-tools.xml' },
- { startIndex: 6, type: 'delimiter.start.xml' }
- ]},{
- line: '\t<![CDATA[',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.cdata.xml' }
- ]},{
- line: '\t\t<person/>',
- tokens: [
- { startIndex: 0, type: '' }
- ]},{
- line: '\t]]>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.cdata.xml' },
- ]},{
- line: '</tools>',
- tokens: [
- { startIndex: 0, type: 'delimiter.end.xml' },
- { startIndex: 2, type: 'tag.tag-tools.xml' },
- { startIndex: 7, type: 'delimiter.end.xml' }
- ]}],
- // Generated from sample
- [{
- line: '<?xml version="1.0"?>',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'metatag.instruction.xml' },
- { startIndex: 5, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 13, type: '' },
- { startIndex: 14, type: 'attribute.value.xml' },
- { startIndex: 19, type: 'delimiter.start.xml' }
- ]}, {
- line: '<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">',
- tokens: [
- { startIndex: 0, type: 'delimiter.start.xml' },
- { startIndex: 1, type: 'tag.tag-configuration.xml' },
- { startIndex: 14, type: '' },
- { startIndex: 15, type: 'attribute.name.xml' },
- { startIndex: 24, type: '' },
- { startIndex: 25, type: 'attribute.value.xml' },
- { startIndex: 78, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <connectionStrings>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 2, type: 'delimiter.start.xml' },
- { startIndex: 3, type: 'tag.tag-connectionstrings.xml' },
- { startIndex: 20, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <add name="MyDB" ',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 4, type: 'delimiter.start.xml' },
- { startIndex: 5, type: 'tag.tag-add.xml' },
- { startIndex: 8, type: '' },
- { startIndex: 9, type: 'attribute.name.xml' },
- { startIndex: 13, type: '' },
- { startIndex: 14, type: 'attribute.value.xml' },
- { startIndex: 20, type: '' }
- ]}, {
- line: ' connectionString="value for the deployed Web.config file" ',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 22, type: '' },
- { startIndex: 23, type: 'attribute.value.xml' },
- { startIndex: 63, type: '' }
- ]}, {
- line: ' xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 19, type: '' },
- { startIndex: 20, type: 'attribute.value.xml' },
- { startIndex: 35, type: '' },
- { startIndex: 36, type: 'attribute.name.xml' },
- { startIndex: 47, type: '' },
- { startIndex: 48, type: 'attribute.value.xml' },
- { startIndex: 61, type: 'tag.tag-add.xml' },
- { startIndex: 62, type: 'delimiter.start.xml' }
- ]}, {
- line: ' </connectionStrings>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 2, type: 'delimiter.end.xml' },
- { startIndex: 4, type: 'tag.tag-connectionstrings.xml' },
- { startIndex: 21, type: 'delimiter.end.xml' }
- ]}, {
- line: ' <system.web>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 2, type: 'delimiter.start.xml' },
- { startIndex: 3, type: 'tag.tag-system.web.xml' },
- { startIndex: 13, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <customErrors defaultRedirect="GenericError.htm"',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 4, type: 'delimiter.start.xml' },
- { startIndex: 5, type: 'tag.tag-customerrors.xml' },
- { startIndex: 17, type: '' },
- { startIndex: 18, type: 'attribute.name.xml' },
- { startIndex: 33, type: '' },
- { startIndex: 34, type: 'attribute.value.xml' }
- ]}, {
- line: ' mode="RemoteOnly" xdt:Transform="Replace">',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 6, type: 'attribute.name.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.value.xml' },
- { startIndex: 23, type: '' },
- { startIndex: 24, type: 'attribute.name.xml' },
- { startIndex: 37, type: '' },
- { startIndex: 38, type: 'attribute.value.xml' },
- { startIndex: 47, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <error statusCode="500" redirect="InternalError.htm"/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 6, type: 'delimiter.start.xml' },
- { startIndex: 7, type: 'tag.tag-error.xml' },
- { startIndex: 12, type: '' },
- { startIndex: 13, type: 'attribute.name.xml' },
- { startIndex: 23, type: '' },
- { startIndex: 24, type: 'attribute.value.xml' },
- { startIndex: 29, type: '' },
- { startIndex: 30, type: 'attribute.name.xml' },
- { startIndex: 38, type: '' },
- { startIndex: 39, type: 'attribute.value.xml' },
- { startIndex: 58, type: 'tag.tag-error.xml' },
- { startIndex: 59, type: 'delimiter.start.xml' }
- ]}, {
- line: ' </customErrors>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 4, type: 'delimiter.end.xml' },
- { startIndex: 6, type: 'tag.tag-customerrors.xml' },
- { startIndex: 18, type: 'delimiter.end.xml' }
- ]}, {
- line: ' </system.web>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 2, type: 'delimiter.end.xml' },
- { startIndex: 4, type: 'tag.tag-system.web.xml' },
- { startIndex: 14, type: 'delimiter.end.xml' }
- ]}, {
- line: ' ',
- tokens: [
- { startIndex: 0, type: '' }
- ]}, {
- line: ' <!-- The stuff below was added for extra tokenizer testing -->',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'comment.xml' },
- { startIndex: 5, type: 'comment.content.xml' },
- { startIndex: 60, type: 'comment.xml' }
- ]}, {
- line: ' <!-- A multi-line comment <with> </with>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'comment.xml' },
- { startIndex: 5, type: 'comment.content.xml' }
- ]}, {
- line: ' <tags>',
- tokens: [
- { startIndex: 0, type: 'comment.content.xml' }
- ]}, {
- line: ' -->',
- tokens: [
- { startIndex: 0, type: 'comment.content.xml' },
- { startIndex: 5, type: 'comment.xml' }
- ]}, {
- line: ' <!DOCTYPE another meta tag>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 3, type: 'metatag.declaration.xml' },
- { startIndex: 10, type: '' },
- { startIndex: 11, type: 'attribute.name.xml' },
- { startIndex: 18, type: '' },
- { startIndex: 19, type: 'attribute.name.xml' },
- { startIndex: 23, type: '' },
- { startIndex: 24, type: 'attribute.name.xml' },
- { startIndex: 27, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <tools><![CDATA[Some text and tags <person/>]]></tools>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-tools.xml' },
- { startIndex: 7, type: 'delimiter.start.xml' },
- { startIndex: 8, type: 'delimiter.cdata.xml' },
- { startIndex: 17, type: '' },
- { startIndex: 45, type: 'delimiter.cdata.xml' },
- { startIndex: 48, type: 'delimiter.end.xml' },
- { startIndex: 50, type: 'tag.tag-tools.xml' },
- { startIndex: 55, type: 'delimiter.end.xml' }
- ]}, {
- line: ' <aSelfClosingTag with="attribute" />',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-aselfclosingtag.xml' },
- { startIndex: 17, type: '' },
- { startIndex: 18, type: 'attribute.name.xml' },
- { startIndex: 22, type: '' },
- { startIndex: 23, type: 'attribute.value.xml' },
- { startIndex: 34, type: '' },
- { startIndex: 35, type: 'tag.tag-aselfclosingtag.xml' },
- { startIndex: 36, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <aSelfClosingTag with="attribute"/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-aselfclosingtag.xml' },
- { startIndex: 17, type: '' },
- { startIndex: 18, type: 'attribute.name.xml' },
- { startIndex: 22, type: '' },
- { startIndex: 23, type: 'attribute.value.xml' },
- { startIndex: 34, type: 'tag.tag-aselfclosingtag.xml' },
- { startIndex: 35, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <namespace:aSelfClosingTag otherspace:with="attribute"/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-namespace:aselfclosingtag.xml' },
- { startIndex: 27, type: '' },
- { startIndex: 28, type: 'attribute.name.xml' },
- { startIndex: 43, type: '' },
- { startIndex: 44, type: 'attribute.value.xml' },
- { startIndex: 55, type: 'tag.tag-namespace:aselfclosingtag.xml' },
- { startIndex: 56, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <valid-name also_valid this.one=\'too is valid\'/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-valid-name.xml' },
- { startIndex: 12, type: '' },
- { startIndex: 13, type: 'attribute.name.xml' },
- { startIndex: 23, type: '' },
- { startIndex: 24, type: 'attribute.name.xml' },
- { startIndex: 32, type: '' },
- { startIndex: 33, type: 'attribute.value.xml' },
- { startIndex: 47, type: 'tag.tag-valid-name.xml' },
- { startIndex: 48, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <aSimpleSelfClosingTag />',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-asimpleselfclosingtag.xml' },
- { startIndex: 23, type: '' },
- { startIndex: 24, type: 'tag.tag-asimpleselfclosingtag.xml' },
- { startIndex: 25, type: 'delimiter.start.xml' }
- ]}, {
- line: ' <aSimpleSelfClosingTag/>',
- tokens: [
- { startIndex: 0, type: '' },
- { startIndex: 1, type: 'delimiter.start.xml' },
- { startIndex: 2, type: 'tag.tag-asimpleselfclosingtag.xml' },
- { startIndex: 24, type: 'delimiter.start.xml' }
- ]}, {
- line: '</configuration>',
- tokens: [
- { startIndex: 0, type: 'delimiter.end.xml' },
- { startIndex: 2, type: 'tag.tag-configuration.xml' },
- { startIndex: 15, type: 'delimiter.end.xml' }
- ]}]
- ]);
|