Exemplo n.º 1
0
 public void SimpleQuineGeneratedMinifiedInput()
 {
     var generator = new QuineGenerator() { };
     var minifier = new Minifier(new MinifierOptions(true) { CommentsRemoving = false, ConsoleApp = true });
     var minified = minifier.MinifyFromString(File.ReadAllText(Path.Combine(QuineTests.PatternsFolder, "CustomQuine.cs")));
     var generated = generator.Generate(minified);
     var checkingResult = _cSharpChecker.CheckQuineProgram(generated);
     Assert.IsTrue(checkingResult.HasNotErrors());
     Assert.IsTrue(!checkingResult.First().Output.Contains(QuineGenerator.Newline));
 }
Exemplo n.º 2
0
        private void btnMinifyInput_Click(object sender, EventArgs e)
        {
            var ignoredIdentifiers = new HashSet<string>();
            var ignoredComments = new HashSet<string>();
            ignoredComments.Add(tbKernel.Text);
            for (int i = 0; i < dgvExtraParams.Rows.Count; i++)
                if (!string.IsNullOrEmpty(dgvExtraParams[2, i].Value as string) ||
                    !string.IsNullOrEmpty(dgvExtraParams[3, i].Value as string))
                {
                    var keyBegin = dgvExtraParams[0, i].Value == null ? "" : (string)dgvExtraParams[0, i].Value;
                    var keyEnd = dgvExtraParams[1, i].Value == null ? "" : (string)dgvExtraParams[1, i].Value;
                    var value = dgvExtraParams[2, i].Value == null ? "" : (string)dgvExtraParams[2, i].Value;
                    var keySubstitute = dgvExtraParams[3, i].Value == null ? "" : (string)dgvExtraParams[3, i].Value;

                    var matches = Regex.Matches(keyBegin, BlockCommentsRegex);
                    foreach (Match match in matches)
                        ignoredComments.Add(match.Value);
                    matches = Regex.Matches(keyBegin, LineCommentsRegex);
                    foreach (Match match in matches)
                        ignoredComments.Add(match.Value);
                    matches = Regex.Matches(keyEnd, BlockCommentsRegex);
                    foreach (Match match in matches)
                        ignoredComments.Add(match.Value);
                    matches = Regex.Matches(keyEnd, LineCommentsRegex);
                    foreach (Match match in matches)
                        ignoredComments.Add(match.Value);

                    matches = Regex.Matches(value, IdRegex);
                    foreach (Match match in matches)
                        ignoredIdentifiers.Add(match.Value);
                    matches = Regex.Matches(keySubstitute, IdRegex);
                    foreach (Match match in matches)
                        ignoredIdentifiers.Add(match.Value);
                }
            ignoredIdentifiers = new HashSet<string>(ignoredIdentifiers.Where(id => { long result; return !long.TryParse(id, out result); }));
            ignoredIdentifiers.Add(tbQuineStr.Text);

            var minifier = new Minifier(new MinifierOptions(false)
            {
                SpacesRemoving = cbRemoveSpaces.Checked,
                LineLength = (int)nudLineLength.Value,
                LocalVarsCompressing = cbCompressIdentifiers.Checked,
                MembersCompressing = cbCompressIdentifiers.Checked,
                TypesCompressing = cbCompressIdentifiers.Checked,
                MiscCompressing = true,
                RegionsRemoving = true,
                CommentsRemoving = false,
                ConsoleApp = true,
                ToStringMethodsRemoving = true,
                PublicCompressing = true,
                NamespacesRemoving = true,
                UselessMembersCompressing = true,
                EnumToIntConversion = true,
            }, ignoredIdentifiers.ToArray(), ignoredComments.ToArray());
            tbInput.Text = minifier.MinifyFromString(tbInput.Text);

            MinifiedInput = true;
        }
Exemplo n.º 3
0
 public static string RemoveSpacesInSource(string csharpCode)
 {
     var minifierOptions = new MinifierOptions(false);
     minifierOptions.SpacesRemoving = true;
     minifierOptions.NamespacesRemoving = true;
     var minifier = new Minifier(minifierOptions);
     return minifier.MinifyFromString(csharpCode);
 }