Ejemplo n.º 1
0
        public void CancelEscrowPreventsOutputOfPendingLine()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);

            source
                .WriteLine()
                .WriteLine("begin")
                .AddIndent()
                .WriteLine("if")
                .AddIndent()
                .WriteLine("do this")
                .RemoveIndent()
                .EscrowLine("endif")
                .ClearEscrowLine()
                .WriteLine("else")
                .AddIndent()
                .WriteLine("do that")
                .RemoveIndent()
                .EscrowLine("endif")
                .RemoveIndent()
                .WriteLine("done");
            Assert.That(source.ToString(), Is.EqualTo(@"
            begin
            if
            do this
            else
            do that
            endif
            done
            "));
        }
Ejemplo n.º 2
0
 public void VisitChunk(IChunkVisitor visitor, OutputLocation location, IList<Chunk> body, StringBuilder output)
 {
     if (location == OutputLocation.ClassMembers)
     {
         foreach (var snippet in body.OfType<CodeStatementChunk>().SelectMany(chunk => chunk.Code))
         {
             snippet.Value = snippet.Value.Replace("@class", "class");
         }
         var source = new SourceWriter(new StringWriter(output));
         var generator = new GeneratedCodeVisitor(source, new Dictionary<string, object>(), NullBehaviour.Strict);
         generator.Accept(body);
     }
 }
Ejemplo n.º 3
0
        public void IndentationShouldAddLeadingSpace()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);

            source
                .WriteLine()
                .WriteLine("one")
                .AddIndent()
                .WriteLine("two")
                .RemoveIndent()
                .WriteLine("three");
            Assert.That(source.ToString(), Is.EqualTo(@"
            one
            two
            three
            "));
        }
Ejemplo n.º 4
0
        public void EscrowLineWritesFirstAtIndentationWhenItWasAdded()
        {
            var writer = new StringWriter();
            var source = new SourceWriter(writer);
            source.WriteLine().AddIndent();

            source
                .WriteLine("one")
                .AddIndent()
                .WriteLine("two")
                .EscrowLine("two-b")
                .RemoveIndent()
                .WriteLine("three")
                .RemoveIndent();
            Assert.That(source.ToString(), Is.EqualTo(@"
            one
            two
            two-b
            three
            "));
        }
Ejemplo n.º 5
0
 public GlobalFunctionsVisitor(SourceWriter source, IDictionary<string, object> globals)
 {
     _source = source;
     _globals = globals;
 }
Ejemplo n.º 6
0
 public GeneratedCodeVisitor(SourceWriter source, IDictionary<string, object> globals)
 {
     _source = source;
     _variables = new VariableTracker(globals);
 }
Ejemplo n.º 7
0
 public GlobalInitializeVisitor(SourceWriter sourceWriter)
 {
     _source = sourceWriter;
 }
Ejemplo n.º 8
0
 public GlobalMembersVisitor(SourceWriter sourceWriter, Dictionary<string, object> globals)
 {
     _source = sourceWriter;
     _globals = globals;
 }