Inheritance: IProjectSerializer
コード例 #1
0
        public void TestBrokenTranslationMissingArrow()
        {
            ProjectSerializer ps = new ProjectSerializer("a b c\n", null, null);

            TranslationNode tn = new TranslationNode(ps);

            Assert.IsFalse(tn.Successful);
        }
コード例 #2
0
        public void TestWorkingTranslation()
        {
            ProjectSerializer ps = new ProjectSerializer("a b c => d e f\n", null, null);

            TranslationNode tn = new TranslationNode(ps);

            Assert.IsTrue(tn.Successful);
            Assert.AreEqual(new string[] { "a", "b", "c" }, tn.Source.ToArray());
            Assert.AreEqual(new string[] { "d", "e", "f" }, tn.Destination.ToArray());
        }
コード例 #3
0
        public void TestIndentationLevelVerification()
        {
            Mockery mockery = new Mockery();
            IProjectNode pn = mockery.NewMock<IProjectNode>();
            ProjectSerializer ps = new ProjectSerializer("\tged\r\n\t  hest \r\n\tnejj\r\n", null, null);
            ps.SpacesIndent = 2;

            Token t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);

            t = ps.ReadTextToken(pn);

            Assert.AreEqual(TokenType.Text, t.Type);
            Assert.AreEqual("ged", t.Text);

            t = ps.ReadLineBreakToken(pn);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t  ", t.Text);
            Assert.AreEqual(2, ps.GetIndentationLevel(t.Text));

            t = ps.ReadTextToken(pn);

            Assert.AreEqual(TokenType.Text, t.Type);
            Assert.AreEqual("hest", t.Text);

            t = ps.ReadLineBreakToken(pn);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);
            Assert.AreEqual(1, ps.GetIndentationLevel(t.Text));

            ps.RollBackToken(t);

            t = ps.ReadIndentationToken(pn);

            Assert.AreEqual(TokenType.Indentation, t.Type);
            Assert.AreEqual("\t", t.Text);
            Assert.AreEqual(1, ps.GetIndentationLevel(t.Text));
        }
コード例 #4
0
        public void TestLineNumber()
        {
            Mockery mockery = new Mockery();
            IProjectNode pn = mockery.NewMock<IProjectNode>();
            ProjectSerializer ps = new ProjectSerializer("a\r\nb;\n\nc", null, null);

            Token t = ps.ReadTextToken(pn);
            Assert.AreEqual(1, t.LineNumber);

            Token newLine = ps.ReadLineBreakToken(pn);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(2, t.LineNumber);

            newLine = ps.ReadLineBreakToken(pn);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(4, t.LineNumber);
        }
コード例 #5
0
        public static IProjectNode LoadString(string script, IRandom random, IWarningViewHelper warningViewHelper)
        {
            ProjectSerializer serializer = new ProjectSerializer(script, random, warningViewHelper);

            return(new ProjectNode(serializer));
        }
コード例 #6
0
        public void TestRepeatingToken()
        {
            Mockery mockery = new Mockery();
            IProjectNode pn = mockery.NewMock<IProjectNode>();
            ProjectSerializer ps = new ProjectSerializer("4[a] 15[b c] 6[", null, null);

            int reps;
            string data;
            Token four = ps.ReadRepeatingToken(pn, out reps, out data);

            Assert.IsNotNull(four);
            Assert.AreEqual(4, reps);
            Assert.AreEqual("a", data);

            Token five = ps.ReadRepeatingToken(pn, out reps, out data);
            Assert.IsNotNull(five);
            Assert.AreEqual(15, reps);
            Assert.AreEqual("b c", data);

            Token sixPartial = ps.ReadRepeatingToken(pn, out reps, out data);
            Assert.IsNull(sixPartial);
        }
コード例 #7
0
        public void TestReadTextToken()
        {
            Mockery mockery = new Mockery();
            IProjectNode pn = mockery.NewMock<IProjectNode>();
            ProjectSerializer ps = new ProjectSerializer("a \"b\" c\"d \"e\\\"f\" g \"h i\"", null, null);

            Token t = ps.ReadTextToken(pn);
            Assert.AreEqual(0, t.Offset);
            Assert.AreEqual(1, t.Length);
            Assert.AreEqual("a", t.Text);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(2, t.Offset);
            Assert.AreEqual(3, t.Length);
            Assert.AreEqual("b", t.Text);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(6, t.Offset);
            Assert.AreEqual(3, t.Length);
            Assert.AreEqual("c\"d", t.Text);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(10, t.Offset);
            Assert.AreEqual(6, t.Length);
            Assert.AreEqual("e\"f", t.Text);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(17, t.Offset);
            Assert.AreEqual(1, t.Length);
            Assert.AreEqual("g", t.Text);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(19, t.Offset);
            Assert.AreEqual(5, t.Length);
            Assert.AreEqual("h i", t.Text);
        }
コード例 #8
0
 public static IProjectNode LoadString(string script, IRandom random, IWarningViewHelper warningViewHelper)
 {
     ProjectSerializer serializer = new ProjectSerializer(script, random, warningViewHelper);
     return new ProjectNode(serializer);
 }