<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NUnit.Framework;
using kgrep;

namespace Tests {

    [TestFixture]
    public class ReplacementArgumentTests {

        [Test]
        public void TestSimpleArgument() {
            ReplacementFile rf = new ReplacementFile("a~bc");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual(reps[0].frompattern.ToString(), (new Regex("a".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[0].topattern, "bc");
        }

        [Test]
        public void TestTwoArguments() {
            ReplacementFile rf = new ReplacementFile("a~bc; g~jk");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual(reps[0].topattern, "bc");
            Assert.AreEqual(reps[1].frompattern.ToString(), (new Regex("g".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[1].topattern, "jk");
        }

        [Test]
        public void TestThreeArgument() {
            ReplacementFile rf = new ReplacementFile("a~bc;   hello~world  ;  third ~ fourth ");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual(reps[2].frompattern.ToString(), (new Regex("third".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[2].topattern, "fourth");
        }

        [Test]
        public void TestEmbeddedDelim() {
            ReplacementFile rf = new ReplacementFile("delim=,; a,bc;   hello,world  ;  third , fourth ");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual(reps[2].frompattern.ToString(), (new Regex("third".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[2].topattern, "fourth");
        }

        [Test]
        public void TestEmbeddedDelimAndScopeFirst() {
            ReplacementFile rf = new ReplacementFile("scope=first;delim=,; a,b; b,c");
            List<Replacement> reps = rf.GetReplacements();
            Assert.IsTrue(reps.Count == 2);
            Assert.AreEqual(reps[0].frompattern.ToString(), (new Regex("a".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[0].topattern, "b");
        }

        [Test]
        public void TestEmbeddedDelimAndScopeAll() {
            ReplacementFile rf = new ReplacementFile("scope=all;delim=,; a,b; b,c");
            List<Replacement> reps = rf.GetReplacements();
            Assert.IsTrue(reps.Count == 2);
            Assert.AreEqual(reps[1].frompattern.ToString(), (new Regex("b".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[1].topattern, "c");
        }

        [Test]
        public void TestEmbeddedComment() {
            ReplacementFile rf = new ReplacementFile("#comment; a~bc");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual(reps[0].frompattern.ToString(), (new Regex("a".Trim(), RegexOptions.Compiled)).ToString());
            Assert.AreEqual(reps[0].topattern, "bc");
        }

        [Test]
        public void TestRemoveOneArgument() {
            ReplacementFile rf = new ReplacementFile("# remove a from arg; a~");
            List<Replacement> reps = rf.GetReplacements();

            KgrepEngine engine = new KgrepEngine();
            string result = engine.ApplyReplacementsAll("a b ca", reps);
            Assert.AreEqual(result, " b c");
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexFromPattern() {
            ReplacementFile rf = new ReplacementFile("a[.~b");
            List<Replacement> reps = rf.GetReplacements();
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexToPattern() {
            ReplacementFile rf = new ReplacementFile("a~b[.");
            List<Replacement> reps = rf.GetReplacements();
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexWithAnchor() {
            ReplacementFile rf = new ReplacementFile("[.a~c~b");
            List<Replacement> reps = rf.GetReplacements();
        }
    }
}
<commit_msg>fix ReplacementArgumentsTest.cs where expected and actuals were reversed<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NUnit.Framework;
using kgrep;

namespace Tests {

    [TestFixture]
    public class ReplacementArgumentTests {

        [Test]
        public void TestSimpleArgument() {
            ReplacementFile rf = new ReplacementFile("a~bc");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual((new Regex("a".Trim(), RegexOptions.Compiled)).ToString(), reps[0].frompattern.ToString());
            Assert.AreEqual( "bc", reps[0].topattern);
        }

        [Test]
        public void TestTwoArguments() {
            ReplacementFile rf = new ReplacementFile("a~bc; g~jk");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual("bc",reps[0].topattern);
            Assert.AreEqual((new Regex("g".Trim(), RegexOptions.Compiled)).ToString(), reps[1].frompattern.ToString());
            Assert.AreEqual("jk",  reps[1].topattern);
        }

        [Test]
        public void TestThreeArgument() {
            ReplacementFile rf = new ReplacementFile("a~bc;   hello~world  ;  third ~ fourth ");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual((new Regex("third".Trim(), RegexOptions.Compiled)).ToString(), reps[2].frompattern.ToString());
            Assert.AreEqual( "fourth", reps[2].topattern);
        }

        [Test]
        public void TestEmbeddedDelim() {
            ReplacementFile rf = new ReplacementFile("delim=,; a,bc;   hello,world  ;  third , fourth ");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual((new Regex("third".Trim(), RegexOptions.Compiled)).ToString(), reps[2].frompattern.ToString());
            Assert.AreEqual("fourth", reps[2].topattern);
        }

        [Test]
        public void TestEmbeddedDelimAndScopeFirst() {
            ReplacementFile rf = new ReplacementFile("scope=first;delim=,; a,b; b,c");
            List<Replacement> reps = rf.GetReplacements();
            Assert.IsTrue(reps.Count == 2);
            Assert.AreEqual((new Regex("a".Trim(), RegexOptions.Compiled)).ToString(), reps[0].frompattern.ToString());
            Assert.AreEqual("b", reps[0].topattern);
        }

        [Test]
        public void TestEmbeddedDelimAndScopeAll() {
            ReplacementFile rf = new ReplacementFile("scope=all;delim=,; a,b; b,c");
            List<Replacement> reps = rf.GetReplacements();
            Assert.IsTrue(reps.Count == 2);
            Assert.AreEqual((new Regex("b".Trim(), RegexOptions.Compiled)).ToString(), reps[1].frompattern.ToString());
            Assert.AreEqual( "c", reps[1].topattern);
        }

        [Test]
        public void TestEmbeddedComment() {
            ReplacementFile rf = new ReplacementFile("#comment; a~bc");
            List<Replacement> reps = rf.GetReplacements();
            Assert.AreEqual((new Regex("a".Trim(), RegexOptions.Compiled)).ToString(), reps[0].frompattern.ToString());
            Assert.AreEqual( "bc", reps[0].topattern);
        }

        [Test]
        public void TestRemoveOneArgument() {
            ReplacementFile rf = new ReplacementFile("# remove a from arg; a~");
            List<Replacement> reps = rf.GetReplacements();

            KgrepEngine engine = new KgrepEngine();
            string result = engine.ApplyReplacementsAll("a b ca", reps);
            Assert.AreEqual(" b c", result);
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexFromPattern() {
            ReplacementFile rf = new ReplacementFile("a[.~b");
            List<Replacement> reps = rf.GetReplacements();
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexToPattern() {
            ReplacementFile rf = new ReplacementFile("a~b[.");
            List<Replacement> reps = rf.GetReplacements();
        }

        [Test]
        [ExpectedException(typeof(System.Exception))]
        public void TestInvalidRegexWithAnchor() {
            ReplacementFile rf = new ReplacementFile("[.a~c~b");
            List<Replacement> reps = rf.GetReplacements();
        }
    }
}

{'fraction_non_alphanumeric': 0.13402532223109387, 'fraction_numerical': 0.0038781795368997376, 'mean_word_length': 2.3762033115132843, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3201549', 'n_tokens_mistral': 2580, 'n_tokens_neox': 2454, 'n_words': 449}