11import { describe , it , expect } from "vitest" ;
2- import { ParseResultStringUtils } from "content-tag-utils" ;
2+ import { Transformer , ParseResultStringUtils } from "content-tag-utils" ;
33import { Preprocessor } from "content-tag" ;
44
55const p = new Preprocessor ( ) ;
66
7- function create ( content : string ) {
8- let buffer = Buffer . from ( content , "utf8" ) ;
9-
10- return {
11- stringUtils : new ParseResultStringUtils ( buffer ) ,
12- parseResults : p . parse ( content ) ,
13- } ;
14- }
15-
167let simpleTemplate = [
178 "export const Name = <template>" ,
189 " {{@name}}" ,
@@ -24,7 +15,82 @@ let simpleTemplate = [
2415 "" ,
2516] . join ( "\n" ) ;
2617
27- describe ( "StringUtils" , ( ) => {
18+ describe ( "ParseResultStringUtils" , ( ) => {
19+ function create ( content : string ) {
20+ let buffer = Buffer . from ( content , "utf8" ) ;
21+
22+ return {
23+ stringUtils : new ParseResultStringUtils ( buffer ) ,
24+ parseResults : p . parse ( content ) ,
25+ } ;
26+ }
27+
28+ describe ( "contentBefore" , ( ) => {
29+ it ( "works" , ( ) => {
30+ let x = create ( simpleTemplate ) ;
31+
32+ let result = x . stringUtils . contentBefore ( x . parseResults [ 0 ] ! ) ;
33+ let result2 = x . stringUtils . contentBefore ( x . parseResults [ 1 ] ! ) ;
34+
35+ expect ( result ) . toMatchInlineSnapshot ( `"export const Name = "` ) ;
36+ expect ( result2 ) . toMatchInlineSnapshot ( `
37+ "export const Name = <template>
38+ {{@name}}
39+ </template>;
40+
41+ export const Greeting = "
42+ ` ) ;
43+ } ) ;
44+ } ) ;
45+
46+ describe ( "originalContentOf" , ( ) => {
47+ it ( "works" , ( ) => {
48+ let x = create ( simpleTemplate ) ;
49+
50+ let result = x . stringUtils . originalContentOf ( x . parseResults [ 0 ] ! ) ;
51+ let result2 = x . stringUtils . originalContentOf ( x . parseResults [ 1 ] ! ) ;
52+
53+ expect ( result ) . toMatchInlineSnapshot ( `
54+ "
55+ {{@name}}
56+ "
57+ ` ) ;
58+ expect ( result2 ) . toMatchInlineSnapshot ( `
59+ "
60+ Hello, <Name @name={{@name}} />!
61+ "
62+ ` ) ;
63+ } ) ;
64+ } ) ;
65+ describe ( "openingTag" , ( ) => {
66+ it ( "works" , ( ) => {
67+ let x = create ( simpleTemplate ) ;
68+
69+ let result = x . stringUtils . openingTag ( x . parseResults [ 0 ] ! ) ;
70+ let result2 = x . stringUtils . openingTag ( x . parseResults [ 1 ] ! ) ;
71+
72+ expect ( result ) . toMatchInlineSnapshot ( `"<template>"` ) ;
73+ expect ( result2 ) . toMatchInlineSnapshot ( `"<template>"` ) ;
74+ } ) ;
75+ } ) ;
76+ describe ( "closingTag" , ( ) => {
77+ it ( "works" , ( ) => {
78+ let x = create ( simpleTemplate ) ;
79+
80+ let result = x . stringUtils . closingTag ( x . parseResults [ 0 ] ! ) ;
81+ let result2 = x . stringUtils . closingTag ( x . parseResults [ 1 ] ! ) ;
82+
83+ expect ( result ) . toMatchInlineSnapshot ( `"</template>"` ) ;
84+ expect ( result2 ) . toMatchInlineSnapshot ( `"</template>"` ) ;
85+ } ) ;
86+ } ) ;
87+ } ) ;
88+
89+ describe ( "stringUtils" , ( ) => {
90+ function create ( content : string ) {
91+ return new Transformer ( content ) ;
92+ }
93+
2894 describe ( "contentBefore" , ( ) => {
2995 it ( "works" , ( ) => {
3096 let x = create ( simpleTemplate ) ;
0 commit comments