fix tests
This commit is contained in:
parent
11ea5e38e5
commit
547ad0e271
3 changed files with 125 additions and 156 deletions
|
|
@ -94,7 +94,7 @@ describe("createRuleMarkdown", () => {
|
|||
expect(parsed.frontmatter.description).toBe("Test description");
|
||||
expect(parsed.frontmatter.globs).toEqual(["*.ts", "*.js"]);
|
||||
expect(parsed.frontmatter.alwaysApply).toBe(true);
|
||||
expect(parsed.markdown).toBe("# Test Rule\n\nThis is the rule content");
|
||||
expect(parsed.markdown).toBe("This is the rule content");
|
||||
});
|
||||
|
||||
it("should create rule markdown with minimal options", () => {
|
||||
|
|
@ -105,7 +105,7 @@ describe("createRuleMarkdown", () => {
|
|||
expect(parsed.frontmatter.description).toBeUndefined();
|
||||
expect(parsed.frontmatter.globs).toBeUndefined();
|
||||
expect(parsed.frontmatter.alwaysApply).toBeUndefined();
|
||||
expect(parsed.markdown).toBe("# Simple Rule\n\nSimple content");
|
||||
expect(parsed.markdown).toBe("Simple content");
|
||||
});
|
||||
|
||||
it("should handle string globs", () => {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,5 @@ export function createRuleMarkdown(
|
|||
frontmatter.alwaysApply = options.alwaysApply;
|
||||
}
|
||||
|
||||
const markdownBody = `# ${name}\n\n${ruleContent}`;
|
||||
|
||||
return createMarkdownWithFrontmatter(frontmatter, markdownBody);
|
||||
return createMarkdownWithFrontmatter(frontmatter, ruleContent);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,192 +1,163 @@
|
|||
// import {
|
||||
// convertMarkdownRuleToContinueRule,
|
||||
// parseMarkdownRule,
|
||||
// } from "./parseMarkdownRule.js";
|
||||
import { markdownToRule, parseMarkdownRule } from "./parseMarkdownRule.js";
|
||||
|
||||
// describe("parseMarkdownRule", () => {
|
||||
// it("should correctly parse markdown with YAML frontmatter", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// ---
|
||||
describe("parseMarkdownRule", () => {
|
||||
it("should correctly parse markdown with YAML frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
// # Test Rule
|
||||
# Test Rule
|
||||
|
||||
// This is a test rule.`;
|
||||
This is a test rule.`;
|
||||
|
||||
// const result = parseMarkdownRule(content);
|
||||
// expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
// expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
// });
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
// it("should handle missing frontmatter", () => {
|
||||
// const content = `# Test Rule
|
||||
it("should handle missing frontmatter", () => {
|
||||
const content = `# Test Rule
|
||||
|
||||
// This is a test rule without frontmatter.`;
|
||||
This is a test rule without frontmatter.`;
|
||||
|
||||
// const result = parseMarkdownRule(content);
|
||||
// expect(result.frontmatter).toEqual({});
|
||||
// expect(result.markdown).toBe(content);
|
||||
// });
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(content);
|
||||
});
|
||||
|
||||
// it("should handle empty frontmatter", () => {
|
||||
// const content = `---
|
||||
// ---
|
||||
it("should handle empty frontmatter", () => {
|
||||
const content = `---
|
||||
---
|
||||
|
||||
// # Test Rule
|
||||
# Test Rule
|
||||
|
||||
// This is a test rule with empty frontmatter.`;
|
||||
This is a test rule with empty frontmatter.`;
|
||||
|
||||
// const result = parseMarkdownRule(content);
|
||||
const result = parseMarkdownRule(content);
|
||||
|
||||
// // Log exact strings for debugging
|
||||
// console.log("Actual:", JSON.stringify(result.markdown));
|
||||
// console.log(
|
||||
// "Expected:",
|
||||
// JSON.stringify(
|
||||
// "# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
// ),
|
||||
// );
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(
|
||||
"# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
);
|
||||
});
|
||||
|
||||
// expect(result.frontmatter).toEqual({});
|
||||
// expect(result.markdown).toBe(
|
||||
// "# Test Rule\n\nThis is a test rule with empty frontmatter.",
|
||||
// );
|
||||
// });
|
||||
it("should handle frontmatter with whitespace", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
// it("should handle frontmatter with whitespace", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// ---
|
||||
# Test Rule
|
||||
|
||||
// # Test Rule
|
||||
This is a test rule.`;
|
||||
|
||||
// This is a test rule.`;
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
// const result = parseMarkdownRule(content);
|
||||
// expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
// expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
// });
|
||||
it("should handle Windows line endings (CRLF)", () => {
|
||||
// Using \r\n for CRLF line endings
|
||||
const content = `---\r
|
||||
globs: "**/test/**/*.kt"\r
|
||||
---\r
|
||||
\r
|
||||
# Test Rule\r
|
||||
\r
|
||||
This is a test rule.`;
|
||||
|
||||
// it("should handle Windows line endings (CRLF)", () => {
|
||||
// // Using \r\n for CRLF line endings
|
||||
// const content = `---\r
|
||||
// globs: "**/test/**/*.kt"\r
|
||||
// ---\r
|
||||
// \r
|
||||
// # Test Rule\r
|
||||
// \r
|
||||
// This is a test rule.`;
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
// The result should be normalized to \n
|
||||
expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
});
|
||||
|
||||
// const result = parseMarkdownRule(content);
|
||||
// expect(result.frontmatter).toEqual({ globs: "**/test/**/*.kt" });
|
||||
// // The result should be normalized to \n
|
||||
// expect(result.markdown).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
// });
|
||||
it("should handle malformed frontmatter", () => {
|
||||
const content = `---
|
||||
globs: - "**/test/**/*.kt"
|
||||
invalid: yaml: content
|
||||
---
|
||||
|
||||
// it("should handle malformed frontmatter", () => {
|
||||
// const content = `---
|
||||
// globs: - "**/test/**/*.kt"
|
||||
// invalid: yaml: content
|
||||
// ---
|
||||
# Test Rule
|
||||
|
||||
// # Test Rule
|
||||
This is a test rule.`;
|
||||
|
||||
// This is a test rule.`;
|
||||
// Should treat as only markdown when frontmatter is malformed
|
||||
const result = parseMarkdownRule(content);
|
||||
expect(result.frontmatter).toEqual({});
|
||||
expect(result.markdown).toBe(content);
|
||||
});
|
||||
});
|
||||
|
||||
// // Should treat as only markdown when frontmatter is malformed
|
||||
// const result = parseMarkdownRule(content);
|
||||
// expect(result.frontmatter).toEqual({});
|
||||
// expect(result.markdown).toBe(content);
|
||||
// });
|
||||
// });
|
||||
describe("markdownToRule", () => {
|
||||
it("should convert markdown with frontmatter to a rule", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Custom Name
|
||||
---
|
||||
|
||||
// describe("convertMarkdownRuleToContinueRule", () => {
|
||||
// it("should convert markdown with frontmatter to a rule", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// name: Custom Name
|
||||
// ---
|
||||
# Test Rule
|
||||
|
||||
// # Test Rule
|
||||
This is a test rule.`;
|
||||
|
||||
// This is a test rule.`;
|
||||
const result = markdownToRule(content);
|
||||
expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
expect(result.globs).toBe("**/test/**/*.kt");
|
||||
expect(result.name).toBe("Custom Name");
|
||||
});
|
||||
|
||||
// const result = convertMarkdownRuleToContinueRule(
|
||||
// "/path/to/rule.md",
|
||||
// content,
|
||||
// );
|
||||
// expect(result.rule).toBe("# Test Rule\n\nThis is a test rule.");
|
||||
// expect(result.globs).toBe("**/test/**/*.kt");
|
||||
// expect(result.name).toBe("Custom Name");
|
||||
// expect(result.source).toBe("rules-block");
|
||||
// expect(result.ruleFile).toBe("/path/to/rule.md");
|
||||
// });
|
||||
it("should use default name if no heading or frontmatter name", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
// it("should use the first heading as name if not in frontmatter", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// ---
|
||||
# Test Rule Title
|
||||
|
||||
// # Test Rule Title
|
||||
This is a test rule.`;
|
||||
|
||||
// This is a test rule.`;
|
||||
const result = markdownToRule(content);
|
||||
expect(result.name).toBe("Rule"); // markdownToRule defaults to "Rule" when no name in frontmatter
|
||||
});
|
||||
|
||||
// const result = convertMarkdownRuleToContinueRule(
|
||||
// "/path/to/rule.md",
|
||||
// content,
|
||||
// );
|
||||
// expect(result.name).toBe("Test Rule Title");
|
||||
// });
|
||||
it("should use default name if no heading or frontmatter name", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
---
|
||||
|
||||
// it("should use filename as name if no heading or frontmatter name", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// ---
|
||||
This is a test rule without a heading.`;
|
||||
|
||||
// This is a test rule without a heading.`;
|
||||
const result = markdownToRule(content);
|
||||
expect(result.name).toBe("Rule"); // markdownToRule defaults to "Rule" when no name in frontmatter
|
||||
});
|
||||
|
||||
// const result = convertMarkdownRuleToContinueRule(
|
||||
// "/path/to/custom-rule.md",
|
||||
// content,
|
||||
// );
|
||||
// expect(result.name).toBe("custom-rule");
|
||||
// });
|
||||
it("should include description from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
description: This is a rule description from frontmatter
|
||||
---
|
||||
|
||||
// it("should include description from frontmatter", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// name: Test Rule
|
||||
// description: This is a rule description from frontmatter
|
||||
// ---
|
||||
# Test Rule
|
||||
|
||||
// # Test Rule
|
||||
This is the content of the rule.`;
|
||||
|
||||
// This is the content of the rule.`;
|
||||
const result = markdownToRule(content);
|
||||
expect(result.description).toBe(
|
||||
"This is a rule description from frontmatter",
|
||||
);
|
||||
});
|
||||
|
||||
// const result = convertMarkdownRuleToContinueRule(
|
||||
// "/path/to/rule.md",
|
||||
// content,
|
||||
// );
|
||||
// expect(result.description).toBe(
|
||||
// "This is a rule description from frontmatter",
|
||||
// );
|
||||
// });
|
||||
it("should include `alwaysApply` from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
// it("should include `alwaysApply` from frontmatter", () => {
|
||||
// const content = `---
|
||||
// globs: "**/test/**/*.kt"
|
||||
// name: Test Rule
|
||||
// alwaysApply: false
|
||||
// ---
|
||||
# Test Rule
|
||||
|
||||
// # Test Rule
|
||||
This is a rule with alwaysApply explicitly set to false.`;
|
||||
|
||||
// This is a rule with alwaysApply explicitly set to false.`;
|
||||
|
||||
// const result = convertMarkdownRuleToContinueRule(
|
||||
// "/path/to/rule.md",
|
||||
// content,
|
||||
// );
|
||||
// expect(result.alwaysApply).toBe(false);
|
||||
// });
|
||||
// });
|
||||
const result = markdownToRule(content);
|
||||
expect(result.alwaysApply).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue