-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeBlockValidator.cs
More file actions
65 lines (57 loc) · 2.02 KB
/
CodeBlockValidator.cs
File metadata and controls
65 lines (57 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// BlockForge CodeBlockValidator
/// Author: Angus Grewal
/// Date: Mar 4 2026
/// Source: Self-written, with AI coaching. All code submitted is human written, based on ChatGPT guidance.
/// </summary>
namespace COMP_3951_BlockForge_TechPro
{
/// <summary>
/// Handles the validation related tasks of CodeBlocks.
/// For now, it is a very basic implementation but will be expanded to throw custom exceptions instead of returning a list of error message strings.
/// </summary>
public class CodeBlockValidator
{
public static List<String> Validate(List<CodeBlock> blocks)
{
var errors = new List<String>();
var encountered = new HashSet<String>();
if (blocks.Count == 0)
{
errors.Add("Workspace is empty.");
return errors;
}
foreach (var block in blocks)
{
if (string.IsNullOrWhiteSpace(block.Uid))
{
errors.Add("Block UID is missing.");
continue;
}
if (!encountered.Add(block.Uid))
{
errors.Add($"{block.Uid} is a duplicate.");
}
if (block.BlockType == CodeBlockType.Unknown)
{
errors.Add($"Unsupported block type for {block.Uid}.");
}
if (block.BlockType == CodeBlockType.Variable)
{
if (!block.VariableType.HasValue)
{
errors.Add($"Variable block {block.Uid} is missing a VariableType.");
}
if (string.IsNullOrWhiteSpace(block.BlockName))
{
errors.Add($"Variable block {block.Uid} is missing a variable name.");
}
}
}
return errors;
}
}
}