Inheritance: IFileLookup
Esempio n. 1
0
        private string TryCompile(string text, IFileLookup lookup = null, bool reset = true)
        {
            Context context;
            Options opts;
            WriterMode mode;

            if (reset)
            {
                context = new Context(new FileCache());
                opts = Options.None;
                mode = WriterMode.Minimize;
            }
            else
            {
                context = Current.InnerContext.Value;
                opts = Current.Options;
                mode = Current.WriterMode;
            }

            var fakeFile = "error-fake-file" + Interlocked.Increment(ref TryCompileNumber) + ".more";
            var fileLookup = new TestLookup(new Dictionary<string, string>() { { fakeFile, text } }, lookup);

            var compiler = Compiler.Get();
            compiler.Compile(Environment.CurrentDirectory, fakeFile, fakeFile + ".out", fileLookup, context, opts, mode);
            return fileLookup.WriteMap.ElementAt(0).Value;
        }
Esempio n. 2
0
        private string TryCompile(string text, string fakeFile = null, IFileLookup lookup = null, bool minify = false, WriterMode mode = WriterMode.Minimize, bool cacheBreak = false, bool prefix = false)
        {
            if (mode == WriterMode.Minimize)
            {
                try
                {
                    TryCompile(text, null, lookup, minify, WriterMode.Pretty);
                }
                catch (Exception e)
                {
                    Assert.Fail("Pretty writing failed");
                }
            }

            fakeFile = fakeFile ?? "compiler-fake-file " + Interlocked.Increment(ref TryCompileNumber) + ".more";

            Options opts = Options.None;
            if (minify)
            {
                opts |= Options.Minify;
            }

            if (cacheBreak)
            {
                opts |= Options.GenerateCacheBreakers;
            }

            if (prefix)
            {
                opts |= Options.AutomateVendorPrefixes;
            }

            var fileLookup = new TestLookup(new Dictionary<string, string>() { { fakeFile, text } }, lookup);

            var compiler = Compiler.Get();
            var ctx = new Context(new FileCache());

            // it's hard to test minification steps if they all always run, so let's just go for a single pass in the "text comparison" cases
            //   still do the full thing when we're doing our test "pretty pass" elsewhere to make sure it always terminates
            ctx.DisableMultipleMinificationPasses = mode != WriterMode.Pretty;

            compiler.Compile(Environment.CurrentDirectory, fakeFile, fakeFile + ".out", fileLookup, ctx, opts, mode);
            var ret =  fileLookup.WriteMap.ElementAt(0).Value;

            return ret;
        }