Ejemplo n.º 1
0
        public void CanUseCacheOnResolutionIntegration()
        {
            var xml  = BSharpCompiler.Compile(ProductionCode)["tiles"].Compiled;
            var conf = new HostConfig(xml);
            var qh   = new HostServer(conf);

            qh.Start();
            try
            {
                var response = new HttpClient().Call("http://127.0.0.1:14990/map/8/173/76.png");
                Assert.AreEqual(200, response.State);
                Assert.AreEqual("image/png; charset=utf-8", response.ContentType);
                var png = (Bitmap)Image.FromStream(new MemoryStream(response.Data));
                Assert.AreEqual(ImageFormat.Png, png.RawFormat);
                var pixel = png.GetPixel(70, 40);
                Assert.AreEqual(174, pixel.R);
                Assert.AreEqual(209, pixel.G);
                Assert.AreEqual(160, pixel.B);
                response = new HttpClient().Call("http://127.0.0.1:14990/map/6/11/26.png");
                Assert.AreEqual(200, response.State);
                Assert.AreEqual("image/png; charset=utf-8", response.ContentType);
                png = (Bitmap)Image.FromStream(new MemoryStream(response.Data));
                Assert.AreEqual(ImageFormat.Png, png.RawFormat);
                pixel = png.GetPixel(54, 18);
                Assert.AreEqual(181, pixel.R);
                Assert.AreEqual(171, pixel.G);
                Assert.AreEqual(201, pixel.B);
            }
            finally
            {
                qh.Stop();
            }
        }
Ejemplo n.º 2
0
        public void ExplicitElementCanOverrideImplicit()
        {
            var ctx = BSharpCompiler.Compile(@"
class X
	element a extend=z 
	a 1
	b 2
	c 3
class Y
	import X
	element b override=y
");
            var cls = ctx["Y"];
            var a   = cls.AllElements.FirstOrDefault(_ => _.Name == "a");
            var b   = cls.AllElements.FirstOrDefault(_ => _.Name == "b");
            var c   = cls.AllElements.FirstOrDefault(_ => _.Name == "c");

            Assert.NotNull(a);
            Assert.NotNull(b);
            Assert.NotNull(c);
            Assert.True(c.Implicit);
            Assert.False(a.Implicit);
            Assert.False(b.Implicit);
            Assert.AreEqual(BSharpElementType.Define, c.Type);
            Assert.AreEqual(BSharpElementType.Extension, a.Type);
            Assert.AreEqual(BSharpElementType.Override, b.Type);
        }
Ejemplo n.º 3
0
        private static XElement CompileWithBSharp(XElement result)
        {
            var compileroptions = new BSharpConfig
            {
                UseInterpolation = true,
                SingleSource     = true
            };
            var compileresult = BSharpCompiler.Compile(new[] { result }, compileroptions);
            var newresult     = new XElement("bsharp");

            foreach (var w in compileresult.Get(BSharpContextDataType.Working))
            {
                var copy = new XElement(w.Compiled);
                if (null != w.Error)
                {
                    copy.AddFirst(new XElement("error", new XText(w.Error.ToString())));
                }
                newresult.Add(copy);
            }
            var e = new XElement("errors");

            foreach (var er in compileresult.GetErrors())
            {
                e.Add(XElement.Parse(new XmlSerializer().Serialize("error", er)).Element("error"));
            }
            if (e.HasElements)
            {
                newresult.Add(e);
            }
            result = newresult;
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///		Установка контекста
        /// </summary>
        /// <param name="bSharps">Массив кода на B#</param>
        public void SetContext(string[] bSharps)
        {
            var parsed   = bSharps.Select(_ => BxlParser.Parse(_));
            var compiled = BSharpCompiler.Compile(parsed);

            SetContext(compiled);
        }
Ejemplo n.º 5
0
        public void BaseKeywordSupport()
        {
            var code   = @"
class a abstract
    e c=1
        e2 c=2
            e3 c='1:${.c},2:${self.c},3:${self.x},4:${base.x},5:${base.c.x},6:${base.y},7:${self.y}'
class c abstract x=1
class d abstract y=2 x=5
a b c=4 x=3 w=${base.c.x}
    import c
    import d
";
            var result = BSharpCompiler.Compile(code);
            var b      = result["b"];
            var x      = b.Compiled;

            Console.WriteLine(x.ToString().Replace("\"", "'"));
            Assert.AreEqual(@"<a code='b' c='4' x='3' w='1' fullcode='b' y='2'>
  <e c='1'>
    <e2 c='2'>
      <e3 c='1:2,2:4,3:3,4:5,5:1,6:2,7:2' />
    </e2>
  </e>
</a>".Simplify(SimplifyOptions.Full), x.ToString().Simplify(SimplifyOptions.Full));
        }
Ejemplo n.º 6
0
        public void NestedElementPartials()
        {
            var ctx = BSharpCompiler.Compile(@"
class A partial x=1
	x u a=1
		b
class A partial y=2
	x u b=2

");

            Assert.AreEqual(0, ctx.GetErrors().Count());
            var cls = ctx["A"];

            Assert.AreEqual("1", cls.Compiled.Attr("x"));
            Assert.AreEqual("2", cls.Compiled.Attr("y"));
            var xs = cls.Compiled.Elements("x");

            Assert.AreEqual(1, xs.Count());
            var x = xs.First();

            Assert.NotNull(x.Element("b"));
            Assert.AreEqual("u", x.GetCode());
            Assert.AreEqual("1", x.Attr("a"));
            Assert.AreEqual("2", x.Attr("b"));
        }
Ejemplo n.º 7
0
        public void PreventAttributeConflict()
        {
            var ctx = BSharpCompiler.Compile(@"
class A partial x=1
class A partial x=2
");

            Assert.AreEqual(1, ctx.GetErrors(ErrorLevel.Error).Count());
        }
Ejemplo n.º 8
0
        public void DetectMetaAndRawClasses(string code, string metamask, string rawmask)
        {
            var ctx  = BSharpCompiler.Compile(code);
            var meta = string.Join(", ", ctx.MetaClasses.Values.OrderBy(_ => _.FullName).Select(_ => _.FullName + ":" + _.GetAttributes()));
            var raw  = string.Join(", ", ctx.RawClasses.Values.OrderBy(_ => _.FullName).Select(_ => _.FullName + ":" + _.GetAttributes()));

            Assert.AreEqual(metamask, meta);
            Assert.AreEqual(rawmask, raw);
        }
Ejemplo n.º 9
0
        public void AssignToSingleClass()
        {
            var ctx = BSharpCompiler.Compile(@"
namespace A
class B
");
            var cls = ctx["B"];

            Assert.AreEqual("A", cls.Namespace);
        }
		/// <summary>
		/// Выполнение цели
		/// </summary>
		/// <param name="context"></param>
		public override void Execute(IBSharpContext context) {
			var compiler = new BSharpCompiler();
		    foreach (var e in Project.CompilerExtensions ) {
		        compiler.Extensions.Add(e);
		    }
		    var cfg = GetConfig();
			compiler.Initialize(cfg);
            compiler.Compile(Project.Sources, context);
            HandleErrorStream(context);
		}
Ejemplo n.º 11
0
        public void CanDisableImplicitElements()
        {
            var ctx = BSharpCompiler.Compile(@"
class X explicit
	a 1
");
            var cls = ctx["X"];
            var a   = cls.SelfElements.FirstOrDefault(_ => _.Name == "a");

            Assert.Null(a);
        }
Ejemplo n.º 12
0
        public void NotCodedElementsNotCauseElementDefinition()
        {
            var ctx = BSharpCompiler.Compile(string.Format(@"
class X
	a
"));
            var cls = ctx["X"];
            var a   = cls.SelfElements.FirstOrDefault(_ => _.Name == "a");

            Assert.Null(a);
        }
Ejemplo n.º 13
0
        public void CanPreventExplicitInAllHierarchy()
        {
            var ctx = BSharpCompiler.Compile(@"
class X explicit
	a 1
");
            var cls = ctx["X"];
            var a   = cls.SelfElements.FirstOrDefault(_ => _.Name == "a");

            Assert.Null(a);
        }
Ejemplo n.º 14
0
        protected BSharpContext CompileAll(bool single, params string[] code)
        {
            var parser = new BxlParser();
            var idx    = 0;
            var xmls   = code.Select(_ => parser.Parse(_, (idx++) + ".bxl")).ToArray();
            var cfg    = new BSharpConfig {
                SingleSource = single, KeepLexInfo = false
            };
            var result = BSharpCompiler.Compile(xmls, cfg);

            return((BSharpContext)result);
        }
Ejemplo n.º 15
0
        public void CanSetupElement(string prefix)
        {
            var ctx = BSharpCompiler.Compile(string.Format(@"
class X
	{0}a 1
", prefix));
            var cls = ctx["X"];
            var a   = cls.SelfElements.FirstOrDefault(_ => _.Name == "a");

            Assert.NotNull(a);
            Assert.AreEqual(BSharpElementType.Define, a.Type);
            Assert.True(a.Implicit);
        }
Ejemplo n.º 16
0
        public void PreventElementBodyConflict()
        {
            var ctx = BSharpCompiler.Compile(@"
class A partial
	x 1 a=1
		x
class A partial
	x 1
		y
");

            Assert.AreEqual(1, ctx.GetErrors(ErrorLevel.Error).Count());
        }
Ejemplo n.º 17
0
        public void SimplestTestWithFirstNotPartial()
        {
            var ctx = BSharpCompiler.Compile(@"
class A x=1
class A partial y=2
");

            Assert.AreEqual(0, ctx.GetErrors().Count());
            var cls = ctx["A"];

            Assert.AreEqual("1", cls.Compiled.Attr("x"));
            Assert.AreEqual("2", cls.Compiled.Attr("y"));
        }
Ejemplo n.º 18
0
        public void BUG_CannotInheritTwoStatics()
        {
            var code   = @"
class a static
a b	static
	"    ;
            var result = BSharpCompiler.Compile(code);

            foreach (var error in result.GetErrors())
            {
                Console.WriteLine(error.ToLogString());
            }
            Assert.AreEqual(0, result.GetErrors().Count());
        }
Ejemplo n.º 19
0
        public void FlagsAreMerged()
        {
            var ctx   = BSharpCompiler.Compile(@"
class A partial x=1 explicit
class A partial y=2 abstract
");
            var clses = ctx.Get(BSharpContextDataType.SrcPkg);

            Assert.AreEqual(1, clses.Count());
            var cls = clses.First();

            Assert.True(cls.Is(BSharpClassAttributes.Abstract));
            Assert.True(cls.Is(BSharpClassAttributes.ExplicitElements));
        }
Ejemplo n.º 20
0
        public void MultipleNamespaces()
        {
            var ctx = BSharpCompiler.Compile(@"
namespace A
class B
namespace C
class D
");
            var cls = ctx["B"];

            Assert.AreEqual("A", cls.Namespace);
            cls = ctx["D"];
            Assert.AreEqual("C", cls.Namespace);
        }
        public void BugPreprocessorsAreNotDetectedAsClasses()
        {
            var code = @"
require preprocessor
using 
	preprocess=Qorpent.BSharp.PreprocessScript
preprocess a b";
            var ctx  = BSharpCompiler.Compile(code);

            foreach (var error in ctx.GetErrors(ErrorLevel.Error))
            {
                Console.WriteLine(error.ToLogString());
            }
            Assert.AreEqual(0, ctx.GetErrors(ErrorLevel.Error).Count());
        }
Ejemplo n.º 22
0
        public void CanSetupValidProxyModeFromBSharp()
        {
            const string code   = @"
class myapp
       proxize /others appid=15
       proxize /others2 appid=16 secure=true
       proxize /others3 url='http://yandex.ru'
";
            var          xml    = BSharpCompiler.Compile(code)["myapp"].Compiled;
            var          config = new HostConfig(xml);

            Assert.AreEqual("appid=15;", config.Proxize["/others"]);
            Assert.AreEqual("appid=16;secure=true;", config.Proxize["/others2"]);
            Assert.AreEqual("http://yandex.ru", config.Proxize["/others3"]);
        }
Ejemplo n.º 23
0
        private XElement BSharpExecutor(string arg)
        {
            var root    = new XElement("root");
            var context = (BSharpContext)BSharpCompiler.Compile(arg);

            foreach (IBSharpClass cls in context.Get(BSharpContextDataType.LibPkg))
            {
                root.Add(cls.Compiled);
            }
            foreach (BSharpError e in context.GetErrors(ErrorLevel.Warning))
            {
                root.Add(new XElement("bx-error", new XAttribute("level", e.Level), e.GetDigest().ToString()));
            }
            return(root);
        }
        public void CanUseDataPackage()
        {
            var code = @"
require data
class mytable1
	import Qorpent.Db.TableBase
";

            var result = BSharpCompiler.Compile(new[] { new BxlParser().Parse(code) }, (IBSharpConfig)null);
            var cls    = result.Get("mytable1");

            Assert.NotNull(cls);
            Assert.GreaterOrEqual(cls.Compiled.Elements("datatype").Count(), 5);
            Console.WriteLine(cls.Compiled);
        }
Ejemplo n.º 25
0
        public void CanSetupRequireWithProxying()
        {
            const string code   = @"
class app1
     appid 76
     service /myserv1

class app2
     appid 78
     require app1 proxize
";
            var          ctx    = BSharpCompiler.Compile(code);
            var          app    = ctx["app2"].Compiled;
            var          config = new HostConfig(app, ctx);

            Assert.AreEqual("appid=76;", config.Proxize["/myserv1"]);
        }
Ejemplo n.º 26
0
        public void CanCheckoutConfigUsingMachineNameToResolve()
        {
            const string code   = @"
class local
     connection a y

class remote
     machine t use=^local
     connection b z
";
            var          ctx    = BSharpCompiler.Compile(code);
            var          local  = ctx["local"].Compiled;
            var          remote = ctx["remote"].Compiled;
            var          config = new HostConfig(remote, ctx, "t");

            Assert.AreSame(local, config.Definition);
        }
Ejemplo n.º 27
0
        public void SimpleAfterBuildPatch()
        {
            var code = @"
class A x=1 prototype=x
class B x=2 prototype=y
	import A
patch for=x y=${x} z=3 build
";
            var ctx  = BSharpCompiler.Compile(code);
            var a    = ctx["A"];
            var b    = ctx["B"];

            Console.WriteLine(a.Compiled.ToString().Replace("\"", "\"\""));
            Console.WriteLine(b.Compiled.ToString().Replace("\"", "\"\""));
            Assert.AreEqual(@"<class code=""A"" x=""1"" prototype=""x"" fullcode=""A"" z=""3"" />".Trim().LfOnly(), a.Compiled.ToString().Trim().LfOnly());
            Assert.AreEqual(@"<class code=""B"" x=""2"" prototype=""y"" fullcode=""B"" />".Trim().LfOnly(), b.Compiled.ToString().Trim().LfOnly());
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     Парсит текущий JSON контекст
        /// </summary>
        public void CompileContext()
        {
            BSharpConfig config = GetBSharpConfig();
            var          list   = new List <XElement>();

            foreach (string json in _jsonContext)
            {
                list.AddRange(
                    RebuildJsonToBSharpStyle(json)
                    );
            }

            _bSharpCompiler.Initialize(config);
            IBSharpContext compiled = _bSharpCompiler.Compile(list, (IBSharpContext)null);

            _bSharpContext.Merge(compiled);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Выполнение цели
        /// </summary>
        /// <param name="context"></param>
        public override void Execute(IBSharpContext context)
        {
            var compiler = new BSharpCompiler();

            compiler.Log     = Project.Log;
            Project.Compiler = compiler;
            foreach (var e in Project.CompilerExtensions)
            {
                compiler.Extensions.Add(e);
            }
            var cfg = GetConfig();

            compiler.Initialize(cfg);
            compiler.Compile(Project.Sources, context);

            HandleErrorStream(context);
        }
Ejemplo n.º 30
0
        public void BugNotNormalReportCompilation()
        {
            var code = @"
class report abstract  prototype=report
	basedir='c:/mnt/reporthub'
		
class bankreport abstract
	import report
	outdir = '${basedir}/~{commonkey}/raw/~{objname}/'
	outfile = '${reportname}${ext}.html'
	period = '${tp.period:1}'
	year = '${tp.year:2014}'

generator
	import bankreport
	dataset
		item out_valuta=RUB 
	dataset 
		item obj=445
	
	dataset
		item template=balans2011_corp_bank	reportname = 'Бухгалтерский баланс (Форма №1)'

";
            var cfg  = new BSharpConfig {
                Global = new Scope()
            };

            cfg.Global["tp.year"]   = "2013";
            cfg.Global["tp.period"] = "2";
            var ctx = BSharpCompiler.Compile(code, cfg);

            foreach (var e in ctx.GetErrors(ErrorLevel.Warning))
            {
                Console.WriteLine(e.ToLogString());
            }
            Assert.AreEqual(0, ctx.GetErrors(ErrorLevel.Warning).Count());
            Assert.AreEqual(1, ctx.Get(BSharpContextDataType.Working).Count());
            var cls = ctx.Get(BSharpContextDataType.Working).First();

            Assert.AreEqual("2013", cls.Compiled.Attr("year"));
            Assert.AreEqual("2", cls.Compiled.Attr("period"));
        }
Ejemplo n.º 31
0
        protected BSharpContext Compile(string code, object globals = null, IDictionary <string, string> conditions = null, BSharpConfig _cfg = null)
        {
            var cfg = new BSharpConfig();

            cfg.Conditions = conditions;
            if (null != globals)
            {
                cfg.Global = new Scope(globals.ToDict())
                {
                    UseInheritance = false
                };
            }
            if (null != _cfg)
            {
                _cfg.SetParent(cfg);
                cfg = _cfg;
            }
            return((BSharpContext)BSharpCompiler.Compile(code, cfg));
        }