コード例 #1
0
ファイル: WhenAScriptHasRandom.cs プロジェクト: Joelone/FFWD
 public void WeWillTranslateItToFFWDRandom()
 {
     ScriptTranslator trans = new ScriptTranslator(testScript);
     trans.Translate();
     string newScript = trans.ToString();
     Assert.That(newScript, Is.StringContaining("PressPlay.FFWD.Random"));
     Assert.That(newScript, Is.Not.StringContaining("PressPlay.FFWD.PressPlay.FFWD."));
 }
コード例 #2
0
        public void WeWillOverrideTheMethod()
        {
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.StringContaining("public override void LateUpdate"));
        }
コード例 #3
0
ファイル: WhenAScriptHasRandom.cs プロジェクト: Joelone/FFWD
 public void WeWillNotDeleteSymboldBeforeRandom()
 {
     ScriptTranslator trans = new ScriptTranslator(testScript);
     trans.Translate();
     string newScript = trans.ToString();
     Assert.That(newScript, Is.StringContaining("(PressPlay.FFWD.Random"));
     Assert.That(newScript, Is.Not.StringContaining("(Random."));
 }
コード例 #4
0
 public void WeCanAddExtraUsings()
 {
     string myNamespace = "MyNamespace";
     ScriptTranslator trans = new ScriptTranslator(testScript);
     ScriptTranslator.DefaultUsings.Add(myNamespace);
     trans.Translate();
     string newScript = trans.ToString();
     Assert.That(newScript, Is.StringContaining("using " + myNamespace + ";"));
 }
コード例 #5
0
        public void WeCanAlsoRemoveAttributesThatHasParameters()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AddComponentMenu", "" } };
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.Not.StringContaining("[AddComponentMenu"));
        }
コード例 #6
0
        public void IfAnAttributeHasACommentedSectionRemoveTheCommentMarkers()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AttributeWithComment", "ConvertedAttribute" } };
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.StringContaining("[ConvertedAttribute("));
        }
コード例 #7
0
        public void IfAnAttributeHasACommentedSectionItCanBeRemoved()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AttributeWithComment", "" } };
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.Not.StringContaining("[AttributeWithComment"));
        }
コード例 #8
0
 public void WeWillRemoveUsingsNotSetToBeKept()
 {
     ScriptTranslator trans = new ScriptTranslator(testScript);
     ScriptTranslator.UsingsThatShouldBeKept = new List<string> { "System", "System.Diagnostics" };
     trans.Translate();
     string newScript = trans.ToString();
     Assert.That(newScript, Is.StringContaining("System;"));
     Assert.That(newScript, Is.StringContaining("System.Diagnostics;"));
     Assert.That(newScript, Is.Not.StringContaining("UnityEngine;"));
     Assert.That(newScript, Is.Not.StringContaining("SomeSystem;"));
 }
コード例 #9
0
        public void WeWillAddTheDefinedUsings()
        {
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            foreach (string u in ScriptTranslator.DefaultUsings)
            {
                Assert.That(newScript, Is.StringContaining("using " + u + ";"));
            }
        }
コード例 #10
0
        public void IfAnAttributeHasACommentedSectionItCanBeRemoved()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>()
            {
                { "AttributeWithComment", "" }
            };
            ScriptTranslator trans = new ScriptTranslator(testScript);

            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.Not.StringContaining("[AttributeWithComment"));
        }
コード例 #11
0
        public void WeCanAlsoReplaceAttributesThatHasParameters()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>()
            {
                { "AddComponentMenu", "AddMenu" }
            };
            ScriptTranslator trans = new ScriptTranslator(testScript);

            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.Not.StringContaining("[AddComponentMenu("));
            Assert.That(newScript, Is.StringContaining("[AddMenu("));
        }
コード例 #12
0
        public void WeCanRemoveAnAttribute()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>()
            {
                { "HideInInspector", "" }
            };
            ScriptTranslator trans = new ScriptTranslator(testScript);

            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.Not.StringContaining("[]"));
            Assert.That(newScript, Is.Not.StringContaining("[HideInInspector]"));
        }
コード例 #13
0
        public void WeWillRemoveUsingsNotSetToBeKept()
        {
            ScriptTranslator trans = new ScriptTranslator(testScript);

            ScriptTranslator.UsingsThatShouldBeKept = new List <string> {
                "System", "System.Diagnostics"
            };
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.StringContaining("System;"));
            Assert.That(newScript, Is.StringContaining("System.Diagnostics;"));
            Assert.That(newScript, Is.Not.StringContaining("UnityEngine;"));
            Assert.That(newScript, Is.Not.StringContaining("SomeSystem;"));
        }
コード例 #14
0
 public void WeCanTranslateTheTestScripts()
 {
     foreach (string filename in Directory.GetFiles("TestScripts", "*.cs"))
     {
         try
         {
             ScriptTranslator trans = new ScriptTranslator(File.ReadAllLines(filename));
             trans.Translate();
         }
         catch (Exception ex)
         {
             Assert.Fail("Exception while translating " + Path.GetFileNameWithoutExtension(filename) + ": " + ex.Message);
         }
     }
     Assert.Pass("We have translated all scripts");
 }
コード例 #15
0
 private void TranslateScriptFile(string scriptFile)
 {
     try
     {
         string   scriptText = File.ReadAllText(scriptFile);
         string[] textLines  = scriptText.Split('\n');
         PressPlay.FFWD.Exporter.ScriptTranslator trans = new ScriptTranslator(textLines);
         trans.Translate();
         string newText = trans.ToString();
         string newPath = scriptFile.Replace(Path.Combine(Application.dataPath, config.unityScriptDir), Path.Combine(xnaBaseDir, config.xnaAssets.ScriptDir));
         if (!Directory.Exists(Path.GetDirectoryName(newPath)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(newPath));
         }
         File.WriteAllText(newPath, newText);
     }
     catch (Exception ex)
     {
         Debug.LogError("Error when converting script " + Path.GetFileName(scriptFile) + ": " + ex.Message);
     }
 }
コード例 #16
0
        public void WeWillReplaceAttributes()
        {
            ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "HideInInspector", "InspectorGadget" } };
            ScriptTranslator trans = new ScriptTranslator(testScript);
            trans.Translate();
            string newScript = trans.ToString();

            Assert.That(newScript, Is.StringContaining("[InspectorGadget]"));
            Assert.That(newScript, Is.Not.StringContaining("[HideInInspector]"));
        }