コード例 #1
0
ファイル: FileModelTest.cs プロジェクト: slamj1/lyniconanc
        public void TestModelOps()
        {
            var doc = new List <string>
            {
                "using abc.def;",
                "",
                "namespace abc.def",
                "{",
                "// hello",
                "\tpublic class Startup",      // POS 5
                "\t{",
                "\t\tpublic Startup(Thing x)", // POS 7
                "\t\t{",
                "\t\t\tblah blah",
                "\t\t\tvar x = \"321\";",
                "\t\t\t",
                "\t\t\tif (check)",
                "\t\t\t{",
                "\t\t\t\blah",
                "\t\t\t}",
                "\t\t}",
                "",
                "\t\ttpublic void Thingy()", // POS 18
                "\t\t{",
                "\t\t}",
                "\t}",
                "}"
            };

            var fm = new FileModel(doc);

            bool found = fm.FindLineContains("Startup(");

            Assert.Equal(7, fm.LineNum);

            fm.Jump(1);
            string wordFound = fm.FindLineContainsAny(new string[] { "public", "private", "protected" });

            Assert.Equal(18, fm.LineNum);
            Assert.Equal("public", wordFound);

            fm.FindPrevLineIs("}");
            Assert.Equal(16, fm.LineNum);

            fm.ToTop();

            fm.FindLineContains("Startup(");
            fm.FindEndOfMethod();
            Assert.Equal(15, fm.LineNum);

            fm.FindLineContains("Thingy(");
            fm.FindEndOfMethod();
            Assert.Equal(19, fm.LineNum);
        }
コード例 #2
0
ファイル: FileModelTest.cs プロジェクト: slamj1/lyniconanc
        public void TestModelBracketInsert()
        {
            var doc = new List <string>
            {
                "// hello",
                "{",
                "var x = y.Func1(x =>",
                "\t(isZ ? 0 : 1));",
                "}"
            };

            var fm = new FileModel(doc);

            fm.FindLineContains("Func1(");
            bool succeed = fm.InsertTextAfterMatchingBracket("Func1(", ".qqq()");

            Assert.True(succeed, "Insert Text failed");
            Assert.Equal("\t(isZ ? 0 : 1)).qqq();", doc[3]);

            fm.ToTop();
            fm.FindLineIs("{");
            succeed = fm.InsertTextAfterMatchingBracket("{", "bbb", '{', '}');
            Assert.True(succeed, "Insert text after } failed");
            Assert.Equal("}bbb", doc[4]);
        }