From e2d7724807a5372467bd4a0e7a87a39a416e5559 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Wed, 23 Aug 2023 17:21:58 -0700 Subject: [PATCH] Manual decaf `language-xml` --- packages/language-xml/spec/xml-spec.coffee | 212 --------------------- packages/language-xml/spec/xml-spec.js | 50 +++-- 2 files changed, 22 insertions(+), 240 deletions(-) delete mode 100644 packages/language-xml/spec/xml-spec.coffee diff --git a/packages/language-xml/spec/xml-spec.coffee b/packages/language-xml/spec/xml-spec.coffee deleted file mode 100644 index bbc993136..000000000 --- a/packages/language-xml/spec/xml-spec.coffee +++ /dev/null @@ -1,212 +0,0 @@ -describe "XML grammar", -> - grammar = null - - beforeEach -> - waitsForPromise -> - atom.packages.activatePackage("language-xml") - - runs -> - grammar = atom.grammars.grammarForScopeName("text.xml") - - it "parses the grammar", -> - expect(grammar).toBeTruthy() - expect(grammar.scopeName).toBe "text.xml" - - it "tokenizes comments in internal subsets correctly", -> - lines = grammar.tokenizeLines """ - - - - ]> - """ - - expect(lines[1][1]).toEqual value: '') - expect(tokens[0]).toEqual value: '') - expect(tokens[0]).toEqual value: '', scopes: ['text.xml', 'comment.block.xml'] - - it "tokenizes empty element meta.tag.no-content.xml", -> - {tokens} = grammar.tokenizeLine('') - expect(tokens[0]).toEqual value: '<', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml'] - expect(tokens[1]).toEqual value: 'n', scopes: ['text.xml', 'meta.tag.no-content.xml', 'entity.name.tag.xml', 'entity.name.tag.localname.xml'] - expect(tokens[2]).toEqual value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml'] - expect(tokens[3]).toEqual value: '', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml'] - - it "tokenizes attribute-name of multi-line tag", -> - linesWithIndent = grammar.tokenizeLines """ - - - """ - expect(linesWithIndent[1][1]).toEqual value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - linesWithoutIndent = grammar.tokenizeLines """ - - - """ - expect(linesWithoutIndent[1][0]).toEqual value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - it "tokenizes attribute-name.namespace contains period", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][3]).toEqual value: 'name.space', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml'] - - it "tokenizes attribute-name.namespace contains East-Asian Kanji", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][3]).toEqual value: '名前空間名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml'] - - it "tokenizes attribute-name.localname contains period", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][3]).toEqual value: 'attr.name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - it "tokenizes attribute-name.localname contains colon", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][5]).toEqual value: 'attr:name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - it "tokenizes attribute-name.localname contains East-Asian Kanji", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][3]).toEqual value: '属性名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - it "tokenizes attribute-name.localname when followed by spaces", -> - lines = grammar.tokenizeLines """ - - - """ - expect(lines[0][3]).toEqual value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml'] - - describe "firstLineMatch", -> - it "recognises Emacs modelines", -> - valid = """ - #-*-xml-*- - #-*-mode:xml-*- - /* -*-xml-*- */ - // -*- XML -*- - /* -*- mode:xml -*- */ - // -*- font:bar;mode:XML -*- - // -*- font:bar;mode:XMl;foo:bar; -*- - // -*-font:mode;mode:XML-*- - // -*- foo:bar mode: xml bar:baz -*- - " -*-foo:bar;mode:xML;bar:foo-*- "; - " -*-font-mode:foo;mode:XML;foo-bar:quux-*-" - "-*-font:x;foo:bar; mode : xml;bar:foo;foooooo:baaaaar;fo:ba;-*-"; - "-*- font:x;foo : bar ; mode : xMl ; bar : foo ; foooooo:baaaaar;fo:ba-*-"; - """ - for line in valid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull() - - invalid = """ - /* --*XML-*- */ - /* -*-- XML -*- - /* -*- -- XML -*- - /* -*- HXML -;- -*- - // -*- iXML -*- - // -*- XML; -*- - // -*- xml-stuff -*- - /* -*- model:xml -*- - /* -*- indent-mode:xml -*- - // -*- font:mode;xml -*- - // -*- mode: -*- XML - // -*- mode: grok-with-xml -*- - // -*-font:mode;mode:xml--*- - """ - for line in invalid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull() - - it "recognises Vim modelines", -> - valid = """ - vim: se filetype=xml: - # vim: se ft=xml: - # vim: set ft=xml: - # vim: set filetype=XML: - # vim: ft=xml - # vim: syntax=xML - # vim: se syntax=XML: - # ex: syntax=xml - # vim:ft=xml - # vim600: ft=xml - # vim>600: set ft=xml: - # vi:noai:sw=3 ts=6 ft=xml - # vi::::::::::noai:::::::::::: ft=xml - # vim:ts=4:sts=4:sw=4:noexpandtab:ft=xml - # vi:: noai : : : : sw =3 ts =6 ft =xml - # vim: ts=4: pi sts=4: ft=xml: noexpandtab: sw=4: - # vim: ts=4 sts=4: ft=xml noexpandtab: - # vim:noexpandtab sts=4 ft=xml ts=4 - # vim:noexpandtab:ft=xml - # vim:ts=4:sts=4 ft=xml:noexpandtab:\x20 - # vim:noexpandtab titlestring=hi\|there\\\\ ft=xml ts=4 - """ - for line in valid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull() - - invalid = """ - ex: se filetype=xml: - _vi: se filetype=xml: - vi: se filetype=xml - # vim set ft=xmlz - # vim: soft=xml - # vim: hairy-syntax=xml: - # vim set ft=xml: - # vim: setft=xml: - # vim: se ft=xml backupdir=tmp - # vim: set ft=xml set cmdheight=1 - # vim:noexpandtab sts:4 ft:xml ts:4 - # vim:noexpandtab titlestring=hi\\|there\\ ft=xml ts=4 - # vim:noexpandtab titlestring=hi\\|there\\\\\\ ft=xml ts=4 - """ - for line in invalid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull() - - it "recognises a valid XML declaration", -> - valid = """ - - - - - - """ - for line in valid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull() - - invalid = """ - - - - - - - - - """ - for line in invalid.split /\n/ - expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull() diff --git a/packages/language-xml/spec/xml-spec.js b/packages/language-xml/spec/xml-spec.js index 92b52cbeb..e6946ace7 100644 --- a/packages/language-xml/spec/xml-spec.js +++ b/packages/language-xml/spec/xml-spec.js @@ -1,22 +1,16 @@ -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * DS205: Consider reworking code to avoid use of IIFEs - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ + describe("XML grammar", function() { let grammar = null; beforeEach(function() { waitsForPromise(() => atom.packages.activatePackage("language-xml")); - return runs(() => grammar = atom.grammars.grammarForScopeName("text.xml")); + runs(() => grammar = atom.grammars.grammarForScopeName("text.xml")); }); it("parses the grammar", function() { expect(grammar).toBeTruthy(); - return expect(grammar.scopeName).toBe("text.xml"); + expect(grammar.scopeName).toBe("text.xml"); }); it("tokenizes comments in internal subsets correctly", function() { @@ -31,14 +25,14 @@ describe("XML grammar", function() { expect(lines[1][1]).toEqual({value: ''); expect(tokens[0]).toEqual({value: '', scopes: ['text.xml', 'comment.block.xml']}); + expect(tokens[3]).toEqual({value: ' comment -->', scopes: ['text.xml', 'comment.block.xml']}); }); it("tokenizes empty element meta.tag.no-content.xml", function() { @@ -56,7 +50,7 @@ describe("XML grammar", function() { expect(tokens[2]).toEqual({value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']}); expect(tokens[3]).toEqual({value: '', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']}); + expect(tokens[5]).toEqual({value: '>', scopes: ['text.xml', 'meta.tag.no-content.xml', 'punctuation.definition.tag.xml']}); }); it("tokenizes attribute-name of multi-line tag", function() { @@ -74,7 +68,7 @@ attrName="attrValue"> \ ` ); - return expect(linesWithoutIndent[1][0]).toEqual({value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); + expect(linesWithoutIndent[1][0]).toEqual({value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); }); it("tokenizes attribute-name.namespace contains period", function() { @@ -83,7 +77,7 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][3]).toEqual({value: 'name.space', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml']}); + expect(lines[0][3]).toEqual({value: 'name.space', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml']}); }); it("tokenizes attribute-name.namespace contains East-Asian Kanji", function() { @@ -92,7 +86,7 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][3]).toEqual({value: '名前空間名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml']}); + expect(lines[0][3]).toEqual({value: '名前空間名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.namespace.xml']}); }); it("tokenizes attribute-name.localname contains period", function() { @@ -101,7 +95,7 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][3]).toEqual({value: 'attr.name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); + expect(lines[0][3]).toEqual({value: 'attr.name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); }); it("tokenizes attribute-name.localname contains colon", function() { @@ -110,7 +104,7 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][5]).toEqual({value: 'attr:name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); + expect(lines[0][5]).toEqual({value: 'attr:name', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); }); it("tokenizes attribute-name.localname contains East-Asian Kanji", function() { @@ -119,7 +113,7 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][3]).toEqual({value: '属性名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); + expect(lines[0][3]).toEqual({value: '属性名', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); }); it("tokenizes attribute-name.localname when followed by spaces", function() { @@ -128,10 +122,10 @@ attrName="attrValue"> \ ` ); - return expect(lines[0][3]).toEqual({value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); + expect(lines[0][3]).toEqual({value: 'attrName', scopes: ['text.xml', 'meta.tag.xml', 'entity.other.attribute-name.localname.xml']}); }); - return describe("firstLineMatch", function() { + describe("firstLineMatch", function() { it("recognises Emacs modelines", function() { let line; const valid = `\ @@ -149,7 +143,7 @@ attrName="attrValue"> "-*-font:x;foo:bar; mode : xml;bar:foo;foooooo:baaaaar;fo:ba;-*-"; "-*- font:x;foo : bar ; mode : xMl ; bar : foo ; foooooo:baaaaar;fo:ba-*-";\ `; - for (line of Array.from(valid.split(/\n/))) { + for (line of valid.split(/\n/)) { expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull(); } @@ -170,7 +164,7 @@ attrName="attrValue"> `; return (() => { const result = []; - for (line of Array.from(invalid.split(/\n/))) { + for (line of invalid.split(/\n/)) { result.push(expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull()); } return result; @@ -202,7 +196,7 @@ vim: se filetype=xml: # vim:ts=4:sts=4 ft=xml:noexpandtab:\x20 # vim:noexpandtab titlestring=hi\|there\\\\ ft=xml ts=4\ `; - for (line of Array.from(valid.split(/\n/))) { + for (line of valid.split(/\n/)) { expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull(); } @@ -223,14 +217,14 @@ _vi: se filetype=xml: `; return (() => { const result = []; - for (line of Array.from(invalid.split(/\n/))) { + for (line of invalid.split(/\n/)) { result.push(expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull()); } return result; })(); }); - return it("recognises a valid XML declaration", function() { + it("recognises a valid XML declaration", function() { let line; const valid = `\ @@ -239,7 +233,7 @@ _vi: se filetype=xml: \ `; - for (line of Array.from(valid.split(/\n/))) { + for (line of valid.split(/\n/)) { expect(grammar.firstLineRegex.findNextMatchSync(line)).not.toBeNull(); } @@ -255,7 +249,7 @@ _vi: se filetype=xml: `; return (() => { const result = []; - for (line of Array.from(invalid.split(/\n/))) { + for (line of invalid.split(/\n/)) { result.push(expect(grammar.firstLineRegex.findNextMatchSync(line)).toBeNull()); } return result;