コード例 #1
0
        public void YarnImporter_OnValidYarnFile_ShouldParse()
        {
            string fileName = Path.GetRandomFileName();

            var path = Application.dataPath + "/" + fileName + ".yarn";

            createdFilePaths.Add(path);

            File.WriteAllText(path, TestYarnScriptSource, System.Text.Encoding.UTF8);
            AssetDatabase.Refresh();
            var result = AssetImporter.GetAtPath("Assets/" + fileName + ".yarn") as YarnImporter;

            Assert.True(result.isSuccessfullyParsed);
            Assert.False(YarnPreventPlayMode.HasCompileErrors(), "Should not have compiler errors");
        }
コード例 #2
0
        public void YarnProjectImporter_OnInvalidYarnFile_ImportsButDoesNotCompile()
        {
            // Arrange:
            // Set up a Yarn project and a Yarn script, with invalid code.
            var project = SetUpProject("This is invalid yarn script, and will not compile.");

            var yarnProjectImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(project)) as YarnProjectImporter;
            var scriptImporter      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(yarnProjectImporter.sourceScripts.First())) as YarnImporter;

            // Assert:
            // The Yarn script will fail to compile, and both the script
            // and the project will know about this, but they otherwise
            // have correct asset references to each other.
            Assert.IsNotEmpty(scriptImporter.parseErrorMessages);
            Assert.AreSame(scriptImporter.DestinationProject, project);
            Assert.AreSame(project, scriptImporter.DestinationProject);

            Assert.True(YarnPreventPlayMode.HasCompileErrors(), "Should show compiler errors");
        }
コード例 #3
0
        public void YarnProjectImporter_OnValidYarnFile_ImportsAndCompilesSuccessfully()
        {
            // Arrange:
            // Set up a Yarn project and a Yarn script.
            var project = SetUpProject("");

            var yarnProjectImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(project)) as YarnProjectImporter;
            var scriptImporter      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(yarnProjectImporter.sourceScripts.First())) as YarnImporter;

            // Assert:
            // The Yarn project has a reference to the Yarn script. They
            // all report no compilation errors.
            Assert.IsEmpty(scriptImporter.parseErrorMessages);
            Assert.IsEmpty(yarnProjectImporter.compileErrors);
            Assert.True(scriptImporter.isSuccessfullyParsed);
            Assert.AreSame(project, scriptImporter.DestinationProject);

            Assert.False(YarnPreventPlayMode.HasCompileErrors(), "Should show compiler errors");
        }
コード例 #4
0
        public void YarnImporter_OnInvalidYarnFile_ShouldNotParse()
        {
            const string textYarnAsset = "This is not a valid yarn file and thus compilation should fail.";
            string       fileName      = Path.GetRandomFileName();

            string path = Application.dataPath + "/" + fileName + ".yarn";

            createdFilePaths.Add(path);
            File.WriteAllText(path, textYarnAsset, System.Text.Encoding.UTF8);

            LogAssert.ignoreFailingMessages = true;
            AssetDatabase.Refresh();
            LogAssert.ignoreFailingMessages = false;
            var result = AssetImporter.GetAtPath("Assets/" + fileName + ".yarn") as YarnImporter;

            Assert.False(result.isSuccessfullyParsed);
            Assert.True(YarnPreventPlayMode.HasCompileErrors(), "Should have compiler errors");

            AssetDatabase.DeleteAsset(result.assetPath);
            AssetDatabase.Refresh();

            Assert.False(YarnPreventPlayMode.HasCompileErrors(), "Should not have compiler errors after deletion");
        }