|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const expect = require("chai").expect; |
| 4 | +const syntax = require("../"); |
| 5 | + |
| 6 | +describe("template interpolation", () => { |
| 7 | + it("PHP", () => { |
| 8 | + const document = syntax.parse( |
| 9 | + [ |
| 10 | + "<a style=\"color: #<?php echo '000' ?>;font-size:<?php echo '12' ?>px\">", |
| 11 | + "</a>", |
| 12 | + ].join("\n"), { |
| 13 | + from: "quickapp.ux", |
| 14 | + } |
| 15 | + ); |
| 16 | + |
| 17 | + expect(document.nodes).to.have.lengthOf(1); |
| 18 | + |
| 19 | + const root = document.first; |
| 20 | + expect(root.source).to.have.property("lang", "css"); |
| 21 | + expect(root.nodes).to.have.lengthOf(2); |
| 22 | + expect(root.first).to.have.property("type", "decl"); |
| 23 | + expect(root.first).to.have.property("prop", "color"); |
| 24 | + expect(root.first).to.have.property("value", "#<?php echo '000' ?>"); |
| 25 | + expect(root.last).to.have.property("type", "decl"); |
| 26 | + expect(root.last).to.have.property("prop", "font-size"); |
| 27 | + expect(root.last).to.have.property("value", "<?php echo '12' ?>px"); |
| 28 | + }); |
| 29 | + |
| 30 | + it("EJS", () => { |
| 31 | + const document = syntax.parse( |
| 32 | + [ |
| 33 | + "<a style=\"color: #<%= user.color %>;font-size:<%= user.size %>px\">", |
| 34 | + "</a>", |
| 35 | + ].join("\n"), { |
| 36 | + from: "quickapp.ux", |
| 37 | + } |
| 38 | + ); |
| 39 | + |
| 40 | + expect(document.nodes).to.have.lengthOf(1); |
| 41 | + |
| 42 | + const root = document.first; |
| 43 | + expect(root.source).to.have.property("lang", "css"); |
| 44 | + expect(root.nodes).to.have.lengthOf(2); |
| 45 | + expect(root.first).to.have.property("type", "decl"); |
| 46 | + expect(root.first).to.have.property("prop", "color"); |
| 47 | + expect(root.first).to.have.property("value", "#<%= user.color %>"); |
| 48 | + expect(root.last).to.have.property("type", "decl"); |
| 49 | + expect(root.last).to.have.property("prop", "font-size"); |
| 50 | + expect(root.last).to.have.property("value", "<%= user.size %>px"); |
| 51 | + }); |
| 52 | + |
| 53 | + it("Quick App", () => { |
| 54 | + const document = syntax.parse( |
| 55 | + [ |
| 56 | + "<template>", |
| 57 | + "\t<span style=\"color:#{{notice.color}};font-size:{{notice.font_size}}px\" for=\"{{(index,notice) in showModalData.notice}}\">{{notice.txt}}</span>", |
| 58 | + "<style module=\"style\"></style>", |
| 59 | + "</template>", |
| 60 | + ].join("\n"), { |
| 61 | + from: "quickapp.ux", |
| 62 | + } |
| 63 | + ); |
| 64 | + |
| 65 | + expect(document.nodes).to.have.lengthOf(2); |
| 66 | + expect(document.first.source).to.have.property("lang", "custom-template"); |
| 67 | + expect(document.last.source).to.have.property("lang", "css"); |
| 68 | + |
| 69 | + const root = document.first; |
| 70 | + expect(root.nodes).to.have.lengthOf(2); |
| 71 | + root.nodes.forEach(node => { |
| 72 | + expect(node).to.have.property("type", "decl"); |
| 73 | + }); |
| 74 | + |
| 75 | + expect(root.first).to.have.property("prop", "color"); |
| 76 | + expect(root.first).to.have.property("value", "#{{notice.color}}"); |
| 77 | + |
| 78 | + expect(root.last).to.have.property("prop", "font-size"); |
| 79 | + expect(root.last).to.have.property("value", "{{notice.font_size}}px"); |
| 80 | + }); |
| 81 | + |
| 82 | + it("VUE", () => { |
| 83 | + const document = syntax.parse( |
| 84 | + [ |
| 85 | + "<template>", |
| 86 | + "\t<span style=\"color:#{{notice.color}};font-size:{{notice.font_size}}px\" for=\"{{(index,notice) in showModalData.notice}}\">{{notice.txt}}</span>", |
| 87 | + "<style module=\"style\"></style>", |
| 88 | + "</template>", |
| 89 | + ].join("\n"), { |
| 90 | + from: "vue-sfc.vue", |
| 91 | + } |
| 92 | + ); |
| 93 | + |
| 94 | + expect(document.nodes).to.have.lengthOf(2); |
| 95 | + expect(document.first.source).to.have.property("lang", "custom-template"); |
| 96 | + expect(document.last.source).to.have.property("lang", "css"); |
| 97 | + |
| 98 | + const root = document.first; |
| 99 | + expect(root.nodes).to.have.lengthOf(2); |
| 100 | + root.nodes.forEach(node => { |
| 101 | + expect(node).to.have.property("type", "decl"); |
| 102 | + }); |
| 103 | + |
| 104 | + expect(root.first).to.have.property("prop", "color"); |
| 105 | + expect(root.first).to.have.property("value", "#{{notice.color}}"); |
| 106 | + |
| 107 | + expect(root.last).to.have.property("prop", "font-size"); |
| 108 | + expect(root.last).to.have.property("value", "{{notice.font_size}}px"); |
| 109 | + }); |
| 110 | + |
| 111 | + it("Svelte", () => { |
| 112 | + const document = syntax.parse( |
| 113 | + [ |
| 114 | + "<a style=\"display: {dynamicProperties}\">", |
| 115 | + "</a>", |
| 116 | + ].join("\n"), { |
| 117 | + from: "quickapp.ux", |
| 118 | + } |
| 119 | + ); |
| 120 | + expect(document.nodes).to.have.lengthOf(1); |
| 121 | + expect(document.first.source).to.have.property("lang", "custom-template"); |
| 122 | + const root = document.first; |
| 123 | + expect(root.nodes).to.have.lengthOf(1); |
| 124 | + root.nodes.forEach(node => { |
| 125 | + expect(node).to.have.property("type", "decl"); |
| 126 | + }); |
| 127 | + expect(root.first).to.have.property("prop", "display"); |
| 128 | + expect(root.first).to.have.property("value", "{dynamicProperties}"); |
| 129 | + }); |
| 130 | +}); |
0 commit comments