< Summary - pva.SuperV

Information
Class: pva.SuperV.Engine.Processing.ScriptDefinition
Assembly: pva.SuperV.Engine
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/Processing/ScriptDefinition.cs
Tag: dotnet-ubuntu_22190969454
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 84
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Name()100%11100%
get_TopicName()100%11100%
get_Source()100%11100%
.ctor(...)100%11100%
GetCode()100%22100%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/Processing/ScriptDefinition.cs

#LineLine coverage
 1using pva.Helpers.Extensions;
 2using System.Text;
 3using System.Text.Json.Serialization;
 4
 5namespace pva.SuperV.Engine.Processing
 6{
 7    /// <summary>
 8    /// Script definition used in a <see cref="Project"/>.
 9    /// </summary>
 10    public class ScriptDefinition
 11    {
 12        /// <summary>
 13        /// Gets the name of the script.
 14        /// </summary>
 15        /// <value>
 16        /// The name.
 17        /// </value>
 67418        public string Name { get; }
 19        /// <summary>
 20        /// Gets the name of the topic on which the script registers.
 21        /// </summary>
 22        /// <value>
 23        /// The name of the topic.
 24        /// </value>
 12225        public string TopicName { get; }
 26        /// <summary>
 27        /// Gets the source code of the script.
 28        /// </summary>
 29        /// <value>
 30        /// The source.
 31        /// </value>
 16932        public string Source { get; }
 33        /// <summary>
 34        /// The field references used in the script.
 35        /// </summary>
 36        [JsonIgnore]
 37        public List<FieldReference> fieldReferences;
 38        /// <summary>
 39        /// The parsed lines
 40        /// </summary>
 41        [JsonIgnore]
 42        public List<string> lines;
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="ScriptDefinition"/> class.
 46        /// </summary>
 47        /// <param name="name">The name.</param>
 48        /// <param name="topicName">Name of the topicon which the script registers.</param>
 49        /// <param name="source">The source code of script.</param>
 16250        public ScriptDefinition(string name, string topicName, string source)
 16251        {
 16252            Name = IdentifierValidation.ValidateIdentifier("script", name);
 16253            TopicName = topicName;
 16254            Source = source;
 16255            lines = ScriptParser.ParseLine(Source);
 16256            fieldReferences = ScriptParser.ParseFieldReferences(lines);
 16257        }
 58
 59        /// <summary>
 60        /// Gets the code to be used when building project.
 61        /// </summary>
 62        /// <returns>The code for the script.</returns>
 63        public string GetCode()
 11564        {
 11565            List<string> replacedScriptCode = ScriptParser.ReplaceFieldReferences(ScriptBase.ChangedInstance, lines, fie
 11566            StringBuilder generatedCode = new();
 34567            HashSet<string> instanceReferences = [.. fieldReferences.Select(f => f.InstanceName ?? ScriptBase.ChangedIns
 11568            generatedCode.AppendLine($"public class {Name}Class : ScriptBase")
 11569                .AppendLine("{")
 11570                .AppendLine($"  public {Name}Class(RunnableProject project, ScriptDefinition scriptDefinition): base(pro
 11571                .AppendLine("  {")
 11572                .AppendLine("  }")
 11573                .AppendLine("public override void HandleFieldValueChange(RunnableProject project, Dictionary<string, IIn
 11574                .AppendLine("  {");
 11575            instanceReferences.ForEach(instance =>
 23176                generatedCode.AppendLine($"    var {instance} = instances[\"{instance}\"] as dynamic;"));
 11577            replacedScriptCode.ForEach(line =>
 23078                generatedCode.AppendLine(line));
 11579            generatedCode.AppendLine("  }")
 11580                .AppendLine("}");
 11581            return generatedCode.ToString();
 11582        }
 83    }
 84}