Beispiel #1
0
        private static void ReadOptTemplate(
            EngineState s, CodeType?opType,
            List <string> rawCodes, string testFile, string sampleStr, string[] compStrs,
            ErrorCheck check = ErrorCheck.Success)
        {
            if (File.Exists(testFile))
            {
                File.Delete(testFile);
            }
            File.Create(testFile).Close();
            try
            {
                EncodingHelper.WriteTextBom(testFile, Encoding.UTF8);
                using (StreamWriter w = new StreamWriter(testFile, true, Encoding.UTF8))
                {
                    w.Write(sampleStr);
                }

                for (int i = 0; i < compStrs.Length; i++)
                {
                    s.Variables.Delete(VarsType.Local, $"Dest{i}");
                }
                EngineTests.EvalOptLines(s, opType, rawCodes, check);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    for (int i = 0; i < compStrs.Length; i++)
                    {
                        string compStr = compStrs[i];
                        string destKey = $"Dest{i}";
                        Assert.IsTrue(s.Variables.ContainsKey(destKey));
                        Assert.IsTrue(s.Variables[destKey].Equals(compStr, StringComparison.Ordinal));
                    }
                }
            }
            finally
            {
                if (File.Exists(testFile))
                {
                    File.Delete(testFile);
                }
            }
        }
        private static void OptTemplate(
            EngineState s, CodeType?opType,
            List <string> rawCodes, string testFile, string sampleStr, string compStr,
            ErrorCheck check = ErrorCheck.Success)
        {
            if (File.Exists(testFile))
            {
                File.Delete(testFile);
            }
            File.Create(testFile).Close();
            try
            {
                EncodingHelper.WriteTextBom(testFile, Encoding.UTF8);
                using (StreamWriter w = new StreamWriter(testFile, true, Encoding.UTF8))
                {
                    w.Write(sampleStr);
                }

                EngineTests.EvalOptLines(s, opType, rawCodes, check);
                if (check == ErrorCheck.Success || check == ErrorCheck.Warning)
                {
                    string dest;
                    using (StreamReader r = new StreamReader(testFile, Encoding.UTF8))
                    {
                        dest = r.ReadToEnd();
                    }

                    Assert.IsTrue(dest.Equals(compStr, StringComparison.Ordinal));
                }
            }
            finally
            {
                if (File.Exists(testFile))
                {
                    File.Delete(testFile);
                }
            }
        }