11import { describe , expect , it } from "vitest" ;
2- import { compileTemplate , tokenize } from "../src/compiler.ts" ;
2+ import { compileTemplate } from "../src/compiler.ts" ;
33import { format } from "prettier" ;
44
55describe ( "compileTemplater" , ( ) => {
@@ -25,67 +25,4 @@ describe("compileTemplater", () => {
2525 ) . toMatchFileSnapshot ( "snapshots/compileTemplated-stream.js" ) ;
2626 } ) ;
2727 } ) ;
28-
29- describe ( "tokenize" , ( ) => {
30- it ( "plain text" , ( ) => {
31- const tokens = tokenize ( "Hello, World!" ) ;
32- expect ( tokens ) . toMatchObject ( [
33- { type : "text" , contents : "Hello, World!" } ,
34- ] ) ;
35- } ) ;
36-
37- it ( "expression" , ( ) => {
38- const tokens = tokenize ( "<?js= name ?>" ) ;
39- expect ( tokens ) . toMatchObject ( [ { type : "expr" , contents : " name " } ] ) ;
40- } ) ;
41-
42- it ( "expression (short)" , ( ) => {
43- const tokens = tokenize ( "<?= name ?>" ) ;
44- expect ( tokens ) . toMatchObject ( [ { type : "expr" , contents : " name " } ] ) ;
45- } ) ;
46-
47- it ( "code" , ( ) => {
48- const tokens = tokenize ( "<?js if (true) { ?>123<?js } ?>" ) ;
49- expect ( tokens ) . toMatchObject ( [
50- { type : "code" , contents : " if (true) { " } ,
51- { type : "text" , contents : "123" } ,
52- { type : "code" , contents : " } " } ,
53- ] ) ;
54- } ) ;
55-
56- it ( "code (short)" , ( ) => {
57- const tokens = tokenize ( "<? if (true) { ?>123<? } ?>" ) ;
58- expect ( tokens ) . toMatchObject ( [
59- { type : "code" , contents : " if (true) { " } ,
60- { type : "text" , contents : "123" } ,
61- { type : "code" , contents : " } " } ,
62- ] ) ;
63- } ) ;
64-
65- it ( "mixed" , ( ) => {
66- const template = [
67- "" ,
68- "Hello, <?= name ?>!" ,
69- "<?js if (age >= 18) { ?>" ,
70- " You are an adult." ,
71- "<?js } else { ?>" ,
72- " You are a minor." ,
73- "<?js } ?>" ,
74- "" ,
75- ] . join ( "\n" ) ;
76- const tokens = tokenize ( template ) ;
77- // console.log(tokens);
78- expect ( tokens ) . toMatchObject ( [
79- { type : "text" , contents : "\nHello, " } ,
80- { type : "expr" , contents : " name " } ,
81- { type : "text" , contents : "!\n" } ,
82- { type : "code" , contents : " if (age >= 18) { " } ,
83- { type : "text" , contents : "\n You are an adult.\n" } ,
84- { type : "code" , contents : " } else { " } ,
85- { type : "text" , contents : "\n You are a minor.\n" } ,
86- { type : "code" , contents : " } " } ,
87- { type : "text" , contents : "\n" } ,
88- ] ) ;
89- } ) ;
90- } ) ;
9128} ) ;
0 commit comments