Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Assets/Tests/Editor/SkillSourceFrontmatterReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using NUnit.Framework;

using io.github.hatayama.UnityCliLoop.Infrastructure;

namespace io.github.hatayama.UnityCliLoop.Tests.Editor
{
/// <summary>
/// Verifies scalar normalization for SKILL.md frontmatter fields.
/// </summary>
[TestFixture]
public class SkillSourceFrontmatterReaderTests
{
// Tests that string scalar fields strip surrounding whitespace and single or double quotes.
[Test]
public void ParseScalarFields_WhenQuoted_StripsWhitespaceAndQuotes()
{
string content =
"---\n" +
"name: 'uloop-compile' \n" +
"toolName: \"compile\" \n" +
"description: 'Compile the project.' \n" +
"---\n";

Assert.That(
SkillSourceFrontmatterReader.ParseNameFromFrontmatter(content),
Is.EqualTo("uloop-compile"));
Assert.That(
SkillSourceFrontmatterReader.ParseToolNameFromFrontmatter(content),
Is.EqualTo("compile"));
Assert.That(
SkillSourceFrontmatterReader.ParseDescriptionFromFrontmatter(content),
Is.EqualTo("Compile the project."));
}

// Tests that tool names preserve their original casing after scalar normalization.
[Test]
public void ParseToolNameFromFrontmatter_WhenQuoted_PreservesCasing()
{
string content = "---\ntoolName: 'Compile'\n---\n";

string toolName = SkillSourceFrontmatterReader.ParseToolNameFromFrontmatter(content);

Assert.That(toolName, Is.EqualTo("Compile"));
}

// Tests that internal flags accept quoted true values without changing case-insensitive semantics.
[TestCase("\"TrUe\"")]
[TestCase("'TrUe'")]
[TestCase(" \"TrUe\" ")]
public void IsInternalSkill_WhenTrueIsQuoted_ReturnsTrue(string scalar)
{
string content = $"---\ninternal: {scalar}\n---\n";

bool isInternal = SkillSourceFrontmatterReader.IsInternalSkill(content);

Assert.That(isInternal, Is.True);
}

// Tests that quoted false values remain non-internal after scalar normalization.
[TestCase("\"FALSE\"")]
[TestCase("'false'")]
public void IsInternalSkill_WhenFalseIsQuoted_ReturnsFalse(string scalar)
{
string content = $"---\ninternal: {scalar}\n---\n";

bool isInternal = SkillSourceFrontmatterReader.IsInternalSkill(content);

Assert.That(isInternal, Is.False);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/SkillSourceFrontmatterReaderTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace io.github.hatayama.UnityCliLoop.Infrastructure
/// </summary>
internal static class SkillSourceFrontmatterReader
{
private static string NormalizeFrontmatterScalar(string value)
{
return value.Trim().Trim('"', '\'');
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

internal static string ParseToolNameFromFrontmatter(string content)
{
Match frontmatterMatch = Regex.Match(content, @"^---\r?\n([\s\S]*?)\r?\n---");
Expand All @@ -26,7 +31,7 @@ internal static string ParseToolNameFromFrontmatter(string content)
return null;
}

return toolNameMatch.Groups[1].Value.Trim();
return NormalizeFrontmatterScalar(toolNameMatch.Groups[1].Value);
}

internal static string ParseNameFromFrontmatter(string content)
Expand All @@ -44,7 +49,7 @@ internal static string ParseNameFromFrontmatter(string content)
return null;
}

return nameMatch.Groups[1].Value.Trim().Trim('"');
return NormalizeFrontmatterScalar(nameMatch.Groups[1].Value);
}

internal static string ParseDescriptionFromFrontmatter(string content)
Expand All @@ -62,7 +67,7 @@ internal static string ParseDescriptionFromFrontmatter(string content)
return null;
}

return descriptionMatch.Groups[1].Value.Trim().Trim('"');
return NormalizeFrontmatterScalar(descriptionMatch.Groups[1].Value);
}

internal static string ResolveToolNameForSkillSource(string skillName, string toolName)
Expand Down Expand Up @@ -133,7 +138,7 @@ internal static bool IsInternalSkill(string content)
}

return string.Equals(
internalMatch.Groups[1].Value.Trim(),
NormalizeFrontmatterScalar(internalMatch.Groups[1].Value),
"true",
StringComparison.OrdinalIgnoreCase);
}
Expand Down
Loading