상속: ICommentParser
예제 #1
0
 public void WhenParseAbConfigGetVariantOnOneLineWeirdSpacing_ReturnCorrectComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("var x = AB.getVariant(   'AbConfigs.Test.Name' );").Single();
     comment.LineNumber.ShouldEqual(1);
     comment.Value.ShouldEqual("@abconfig AbConfigs.Test.Name");
 }
예제 #2
0
        public void WhenParseAbConfigGetVariantComplex_DontReturnInvalidComments()
        {
            var js =
                @"Hogan.Template.prototype.render = function render(context, partials, indent) {

            context = context || {};

            context.AB = function () {
            return function (s) {

            if (!AB
                || typeof AB.getVariant !== 'function')
            {
                throw new Error('Could not check if AB test is on.');
            }

            if (!AB.getVariant(s))
            {
                throw new Error('Could not check if AB test is on for test: ""' + s + '""');
            }

            return AB.getVariant(s);
            };
            };

            return this.ri([context], partials || {}, indent);
            };";
            var parser = new JavaScriptCommentParser();
            var comments = parser.Parse(js).ToArray();
            comments.Length.ShouldEqual(0);
        }
예제 #3
0
 public void WhenParseAbConfigGetVariantOnMultipleLines_ReturnCorrectComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("var x = AB.getVariant(\r'AbConfigs.Test.Name'\n);").Single();
     comment.LineNumber.ShouldEqual(2);
     comment.Value.ShouldEqual("@abconfig AbConfigs.Test.Name");
 }
예제 #4
0
 public void WhenParseSingleLineComment_ThenReturnOneComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("// text").Single();
     comment.LineNumber.ShouldEqual(1);
     comment.Value.ShouldEqual(" text");
 }
예제 #5
0
        public void WhenParseSingleLineComment_ThenReturnOneComment()
        {
            var parser  = new JavaScriptCommentParser();
            var comment = parser.Parse("// text").Single();

            comment.LineNumber.ShouldEqual(1);
            comment.Value.ShouldEqual(" text");
        }
예제 #6
0
 public void WhenParseTwoSingleLineComments_ThenReturnTwoComments()
 {
     var parser = new JavaScriptCommentParser();
     var comments = parser.Parse("// text1\r\n// text2").ToArray();
     comments[0].LineNumber.ShouldEqual(1);
     comments[0].Value.ShouldEqual(" text1");
     comments[1].LineNumber.ShouldEqual(2);
     comments[1].Value.ShouldEqual(" text2");
 }
예제 #7
0
 public void WhenParseMultilineComment_ThenReturnCommentPerLine()
 {
     var parser = new JavaScriptCommentParser();
     var comments = parser.Parse("/*text1\r\ntext2*/").ToArray();
     comments[0].LineNumber.ShouldEqual(1);
     comments[0].Value.ShouldEqual("text1");
     comments[1].LineNumber.ShouldEqual(2);
     comments[1].Value.ShouldEqual("text2");
 }
예제 #8
0
        public void WhenParseMultilineCommentWithUnixNewLines_ThenReturnCommentPerLine()
        {
            var parser   = new JavaScriptCommentParser();
            var comments = parser.Parse("/*text1\ntext2*/").ToArray();

            comments[0].LineNumber.ShouldEqual(1);
            comments[0].Value.ShouldEqual("text1");
            comments[1].LineNumber.ShouldEqual(2);
            comments[1].Value.ShouldEqual("text2");
        }
예제 #9
0
        public void WhenParseTwoSingleLineCommentsSeperatedByUnixNewLine_ThenReturnTwoComments()
        {
            var parser   = new JavaScriptCommentParser();
            var comments = parser.Parse("// text1\n// text2").ToArray();

            comments[0].LineNumber.ShouldEqual(1);
            comments[0].Value.ShouldEqual(" text1");
            comments[1].LineNumber.ShouldEqual(2);
            comments[1].Value.ShouldEqual(" text2");
        }
예제 #10
0
 public void WhenParseLocalizedStringOnOneLineWeirdSpacing_ReturnCorrectComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("var x = i18n.t(   'Localized.String.Here' );").Single();
     comment.LineNumber.ShouldEqual(1);
     comment.Value.ShouldEqual("@localize Localized.String.Here");
 }
예제 #11
0
 public void WhenParseLocalizedStringOnMultipleLines_ReturnCorrectComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("var x = i18n.t(\r'Localized.String.Here'\n);").Single();
     comment.LineNumber.ShouldEqual(2);
     comment.Value.ShouldEqual("@localize Localized.String.Here");
 }
예제 #12
0
        public void WhenParseLocalizedStringComplex_DontReturnInvalidComments()
        {
            var js =
                @"Hogan.Template.prototype.render = function render(context, partials, indent) {

            context = context || {};

            context.i18n = function () {
            return function (s) {

            if (!i18n
                || typeof i18n.t !== 'function')
            {
                throw new Error('Could not find locale data.');
            }

            if (!i18n.t(s))
            {
                throw new Error('Could not find locale data for key: ""' + s + '""');
            }

            return i18n.t(s);
            };
            };

            return this.ri([context], partials || {}, indent);
            };";
            var parser = new JavaScriptCommentParser();
            var comments = parser.Parse(js).ToArray();
            comments.Length.ShouldEqual(0);
        }
예제 #13
0
 public void WhenParseAbConfigIsOnOnOneLineSingleQuotes_ReturnCorrectComment()
 {
     var parser = new JavaScriptCommentParser();
     var comment = parser.Parse("var x = AB.isOn('AbConfigs.Test.Name');").Single();
     comment.LineNumber.ShouldEqual(1);
     comment.Value.ShouldEqual("@abconfig AbConfigs.Test.Name");
 }