@@ -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 = "" ;
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} ) ;
0 commit comments