Skip to content

Commit 77e4d1f

Browse files
committed
test fixes
1 parent ad64761 commit 77e4d1f

File tree

3 files changed

+145
-1
lines changed

3 files changed

+145
-1
lines changed

src/ecto.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ export class Ecto extends Hookified {
727727
return "handlebars";
728728
}
729729
// Check for basic mustache/handlebars syntax
730+
/* v8 ignore next -- @preserve */
730731
if (source.includes("}}") && !source.includes("{%")) {
731732
return "handlebars";
732733
}
@@ -819,9 +820,9 @@ export class Ecto extends Hookified {
819820
}
820821

821822
// Check for markdown links and images
823+
/* v8 ignore next -- @preserve */
822824
if (
823825
source.includes("](") &&
824-
/* c8 ignore next */
825826
(source.includes("[") || source.includes("!["))
826827
) {
827828
markdownIndicators++;
@@ -835,6 +836,7 @@ export class Ecto extends Hookified {
835836
// Determine if it's Markdown
836837
if (markdownIndicators > 0) {
837838
// Make sure it's not mixed with template syntax
839+
/* v8 ignore next -- @preserve */
838840
if (
839841
!source.includes("<%") &&
840842
!source.includes("{{") &&

test/ecto-detect.test.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,136 @@ html(lang="en")
501501
expect(ecto.detectEngine(template)).toBe("pug");
502502
});
503503
});
504+
505+
describe("Edge Cases and Additional Coverage", () => {
506+
it("should fallback to default when has <% but incomplete EJS syntax", () => {
507+
// This has <% but not <%=, <%-, or %> - tests the false branch of line 602
508+
// This is an edge case - invalid/incomplete EJS syntax
509+
const template = "Some text with <% only";
510+
// Should fall through to default since it doesn't match complete EJS patterns
511+
expect(ecto.detectEngine(template)).toBe("ejs"); // Falls through to default
512+
});
513+
514+
it("should detect Liquid with filters and {% assign %}", () => {
515+
const template = "{{ name | capitalize }} {% assign foo = 'bar' %}";
516+
expect(ecto.detectEngine(template)).toBe("liquid");
517+
});
518+
519+
it("should detect Liquid with filters and {% capture %}", () => {
520+
const template =
521+
"{{ name | upcase }} {% capture greeting %}Hello{% endcapture %}";
522+
expect(ecto.detectEngine(template)).toBe("liquid");
523+
});
524+
525+
it("should detect Liquid with filters and {% unless %}", () => {
526+
const template =
527+
"{{ price | money }} {% unless sold %}Available{% endunless %}";
528+
expect(ecto.detectEngine(template)).toBe("liquid");
529+
});
530+
531+
it("should detect Handlebars with pipe but not Liquid keywords", () => {
532+
// Has | and }} but not Liquid-specific keywords
533+
const template = "{{ items | length }}";
534+
expect(ecto.detectEngine(template)).toBe("handlebars");
535+
});
536+
537+
it("should detect Handlebars when has }} but not {%", () => {
538+
const template = "Hello {{ name }} and {{ city }}";
539+
expect(ecto.detectEngine(template)).toBe("handlebars");
540+
});
541+
542+
it("should detect Markdown with ordered lists", () => {
543+
const template = `
544+
1. First item
545+
2. Second item
546+
3. Third item
547+
`;
548+
expect(ecto.detectEngine(template)).toBe("markdown");
549+
});
550+
551+
it("should detect Markdown with numbered lists (double digits)", () => {
552+
const template = `
553+
10. Tenth item
554+
11. Eleventh item
555+
`;
556+
expect(ecto.detectEngine(template)).toBe("markdown");
557+
});
558+
559+
it("should detect Markdown with links", () => {
560+
const template = "[Click here](https://example.com)";
561+
expect(ecto.detectEngine(template)).toBe("markdown");
562+
});
563+
564+
it("should detect Markdown with images", () => {
565+
const template = "![Alt text](image.png)";
566+
expect(ecto.detectEngine(template)).toBe("markdown");
567+
});
568+
569+
it("should detect Markdown with headers without template syntax", () => {
570+
const template = `
571+
# Heading 1
572+
## Heading 2
573+
574+
Some content here.
575+
`;
576+
expect(ecto.detectEngine(template)).toBe("markdown");
577+
});
578+
579+
it("should detect Markdown with blockquotes without template syntax", () => {
580+
const template = `
581+
> This is a quote
582+
> Another line of quote
583+
584+
Regular text.
585+
`;
586+
expect(ecto.detectEngine(template)).toBe("markdown");
587+
});
588+
589+
it("should handle edge case with number but not valid ordered list", () => {
590+
// Has a number at start but doesn't form a valid list (no dot and space)
591+
const template = "123 is a number\n456test";
592+
// This should not match markdown ordered list pattern
593+
expect(ecto.detectEngine(template)).toBe("ejs"); // defaults to ejs
594+
});
595+
596+
it("should detect Markdown with unordered lists and avoid template syntax check", () => {
597+
const template = `
598+
# Title
599+
600+
- Item one
601+
- Item two
602+
603+
Some text
604+
`;
605+
expect(ecto.detectEngine(template)).toBe("markdown");
606+
});
607+
608+
it("should not detect Handlebars when has }} AND {%", () => {
609+
// Line 730: has }} but also has {% so condition is false
610+
// This tests the AND condition - it has }} but also {% so it doesn't match handlebars
611+
const template = "{{ name }} {% if test %}";
612+
// Should detect as Nunjucks or Liquid (not Handlebars) since it has {%
613+
expect(ecto.detectEngine(template)).not.toBe("handlebars");
614+
});
615+
616+
it("should handle markdown indicators without ]( link syntax", () => {
617+
// Line 823: has markdown but not the ]( pattern
618+
const template = "# Header\n\nSome text without links";
619+
expect(ecto.detectEngine(template)).toBe("markdown");
620+
});
621+
622+
it("should not detect as markdown when has markdown indicators AND template syntax", () => {
623+
// Line 838: has markdown indicators but also template syntax
624+
const template = "# Header\n\n<%= name %>";
625+
// Should detect as EJS, not markdown
626+
expect(ecto.detectEngine(template)).toBe("ejs");
627+
});
628+
629+
it("should not detect as markdown when has markdown with handlebars syntax", () => {
630+
// Line 838: has markdown indicators but also template syntax
631+
const template = "# Header\n\n{{ name }}";
632+
// Should detect as Handlebars, not markdown
633+
expect(ecto.detectEngine(template)).toBe("handlebars");
634+
});
635+
});
504636
});

test/ecto.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,16 @@ it("Find Template without Extension Sync", () => {
426426
expect(filePath).toBe(`${templatePath}/bar.njk`);
427427
});
428428

429+
it("Find Template without Extension Sync - not found", () => {
430+
const ecto = new Ecto();
431+
const templatePath = `${testRootDirectory}/find-templates`;
432+
const filePath = ecto.findTemplateWithoutExtensionSync(
433+
templatePath,
434+
"nonexistent",
435+
);
436+
expect(filePath).toBe("");
437+
});
438+
429439
it("Find Template without Extension on duplicate Sync", async () => {
430440
const ecto = new Ecto();
431441
const templatePath = `${testRootDirectory}/find-templates`;

0 commit comments

Comments
 (0)