public void Replace() { SymbolTable table = new SymbolTable(); MiniRE miniRe = new MiniRE(); StatementList sl = new StatementList(); miniRe.StatementList = sl; Statement statement = new Statement(); statement.Id = new StringNode("x"); sl.Statement = statement; StatementListTail tail = new StatementListTail(); sl.Tail = tail; Statement s2 = new Statement(); s2.Id = new StringNode("y"); tail.Statement = s2; StatementListTail tail2 = new StatementListTail(); tail.Tail = tail2; #region Statement 1 AssignmentStatement asStmt = new AssignmentStatement(); statement.AssignmentStatement = asStmt; Exp exp = new Exp(); asStmt.Exp = exp; Term term = new Term(); exp.Term = term; Regex regex = new Regex(); regex.Pattern = "a"; term.Regex = regex; Filename filename = new Filename(); filename.Path = "../../../TestFiles/file1.txt"; term.Filename = filename; #endregion #region Statement 2 AssignmentStatement as2 = new AssignmentStatement(); as2.Type = AssignmentStatementType.Length; s2.AssignmentStatement = as2; Exp exp2 = new Exp(); exp2.Id = new StringNode("x"); as2.Exp = exp2; #endregion #region Statement 3 Statement s3 = new Statement(); tail2.Statement = s3; OtherStatement os = new OtherStatement(); os.Mode = OtherStatementMode.Replace; os.ReplaceText = "b"; s3.OtherStatement = os; Regex regex3 = new Regex(); regex3.Pattern = "(a|A)"; os.Regex = regex3; Filenames filenames = new Filenames(); os.Filenames = filenames; Filename filename2 = new Filename(); filename2.Path = "../../../TestFiles/file2.txt"; filenames.Filename = filename2; Filename destimation = new Filename(); destimation.Path = "../../../TestFiles/file3.txt"; filenames.Destimation = destimation; #endregion miniRe.Execute(table); String expected = "brgument brgumentbtive predicbment mentoring bpple"; StringBuilder actual = new StringBuilder(); using(FileStream fs = new FileStream("../../../TestFiles/file3.txt", FileMode.Open)) { using(StreamReader sr = new StreamReader(fs)) { actual.Append(sr.ReadToEnd()); } } Assert.AreEqual(expected, actual.ToString()); }
public void MiniRE() { SymbolTable table = new SymbolTable(); MiniRE miniRe = new MiniRE(); StatementList sl = new StatementList(); miniRe.StatementList = sl; Statement statement = new Statement(); statement.Id = new StringNode("x"); sl.Statement = statement; StatementListTail tail = new StatementListTail(); sl.Tail = tail; Statement s2 = new Statement(); s2.Id = new StringNode("y"); tail.Statement = s2; StatementListTail tail2 = new StatementListTail(); tail.Tail = tail2; #region Statement 1 AssignmentStatement asStmt = new AssignmentStatement(); statement.AssignmentStatement = asStmt; Exp exp = new Exp(); asStmt.Exp = exp; Term term = new Term(); exp.Term = term; Regex regex = new Regex(); regex.Pattern = "a"; term.Regex = regex; Filename filename = new Filename(); filename.Path = "../../../TestFiles/file1.txt"; term.Filename = filename; #endregion #region Statement 2 AssignmentStatement as2 = new AssignmentStatement(); as2.Type = AssignmentStatementType.Length; s2.AssignmentStatement = as2; Exp exp2 = new Exp(); exp2.Id = new StringNode("x"); as2.Exp = exp2; #endregion miniRe.Execute(table); object value = table["x"]; Assert.AreEqual(7, (int)table["y"]); }
public void Print() { SymbolTable table = new SymbolTable(); MiniRE miniRe = new MiniRE(); StatementList sl = new StatementList(); miniRe.StatementList = sl; Statement statement = new Statement(); statement.Id = new StringNode("x"); sl.Statement = statement; StatementListTail tail = new StatementListTail(); sl.Tail = tail; Statement s2 = new Statement(); s2.Id = new StringNode("y"); tail.Statement = s2; StatementListTail tail2 = new StatementListTail(); tail.Tail = tail2; #region Statement 1 AssignmentStatement asStmt = new AssignmentStatement(); statement.AssignmentStatement = asStmt; Exp exp = new Exp(); asStmt.Exp = exp; Term term = new Term(); exp.Term = term; Regex regex = new Regex(); regex.Pattern = "a"; term.Regex = regex; Filename filename = new Filename(); filename.Path = "../../../TestFiles/file1.txt"; term.Filename = filename; #endregion #region Statement 2 AssignmentStatement as2 = new AssignmentStatement(); as2.Type = AssignmentStatementType.Length; s2.AssignmentStatement = as2; Exp exp2 = new Exp(); exp2.Id = new StringNode("x"); as2.Exp = exp2; #endregion #region Statement 3 Statement s3 = new Statement(); tail2.Statement = s3; OtherStatement print = new OtherStatement(); print.Mode = OtherStatementMode.Print; s3.OtherStatement = print; ExpList expList = new ExpList(); print.ExpList = expList; Exp exp3 = new Exp(); exp3.Id = new StringNode("y"); expList.Exp = exp3; #endregion using (MemoryStream ms = new MemoryStream()) { StreamWriter sw = new StreamWriter(ms); Console.SetOut(sw); miniRe.Execute(table); sw.Flush(); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { String actual = sr.ReadToEnd(); Assert.AreEqual(7, Int32.Parse(actual)); } } }
public void Maxfreqstr() { SymbolTable table = new SymbolTable(); MiniRE miniRe = new MiniRE(); StatementList sl = new StatementList(); miniRe.StatementList = sl; Statement statement = new Statement(); statement.Id = new StringNode("x"); sl.Statement = statement; AssignmentStatement as1 = new AssignmentStatement(); statement.AssignmentStatement = as1; Exp exp1 = new Exp(); as1.Exp = exp1; Term term = new Term(); exp1.Term = term; Regex r1 = new Regex(); r1.Pattern = "[a-z]([a-z])*"; term.Regex = r1; Filename filename = new Filename(); filename.Path = "../../../TestFiles/maxfreq.txt"; term.Filename = filename; StatementListTail tail = new StatementListTail(); sl.Tail = tail; Statement s2 = new Statement(); s2.Id = new StringNode("y"); tail.Statement = s2; AssignmentStatement as2 = new AssignmentStatement(); as2.Type = AssignmentStatementType.MaxFreqString; as2.Id = new StringNode("x"); s2.AssignmentStatement = as2; miniRe.Execute(table); Assert.AreEqual("hey", table["y"]); }